GithubHelp home page GithubHelp logo

Comments (4)

slipo avatar slipo commented on July 18, 2024

BTW, if anybody wants to confirm this is a bug and point me in the right direction to fixing it, I'm happy to take a look. I'm still pretty new to the codebase so just want to make sure I'm not missing something.

from neo-boa.

trendsetter37 avatar trendsetter37 commented on July 18, 2024

@slipo can you post the entire contract file for more context?

from neo-boa.

slipo avatar slipo commented on July 18, 2024

Sure.

Here's example 1 which works:

from boa.blockchain.vm.Neo.Runtime import GetTrigger
from boa.blockchain.vm.Neo.TriggerType import Application, Verification
from boa.blockchain.vm.System.ExecutionEngine import GetScriptContainer
from boa.blockchain.vm.Neo.Storage import GetContext
from boa.blockchain.vm.Neo.Transaction import GetUnspentCoins, GetHash

def Main(operation, args):
    trigger = GetTrigger()

    if trigger == Application():
        if operation == 'deposit':
            tx = GetScriptContainer()
            tx_hash = tx.Hash
            print(tx_hash)

    return False

Here's example 2 which adds a call to Input.GetHash thereby breaking tx.Hash:

from boa.blockchain.vm.Neo.Runtime import GetTrigger
from boa.blockchain.vm.Neo.TriggerType import Application, Verification
from boa.blockchain.vm.System.ExecutionEngine import GetScriptContainer
from boa.blockchain.vm.Neo.Storage import GetContext
from boa.blockchain.vm.Neo.Transaction import GetInputs, GetUnspentCoins
from boa.blockchain.vm.Neo.Input import GetIndex, GetHash

def Main(operation, args):
    trigger = GetTrigger()

    if trigger == Verification():
        tx = GetScriptContainer()

        valid = True

        for input in tx.Inputs:
            hash = GetHash(input)
            print(hash)

        return valid

    elif trigger == Application():
        if operation == 'deposit':
            tx = GetScriptContainer()
            tx_hash = tx.Hash
            print(tx_hash)

    return False

Note: I don't even need to import Transaction.GetHash in this. And I haven't found a way to import it so it doesn't conflict with Input.GetHash.

When I run testinvoke EXAMPLE_2_SCRIPT_HASH deposit [] --attach-gas=1 I get errors like:

[E 180208 03:24:18 ExecutionEngine:852] COULD NOT EXECUTE OP: Invalid list operation b'\x9c' NUMEQUAL
[E 180208 03:24:18 ExecutionEngine:853] Invalid list operation

Originally somehow I think I saw an error related to Input's PrevHash not existing in tx which was my original clue of this issue.

from neo-boa.

localhuman avatar localhuman commented on July 18, 2024

This is a little tricky since there's three things named GetHash in the interop module. Without type checking in python it's difficult to tell which one to use. Regardless, there is a workaround in the new version of the compiler. If you want to use tx.Hash and input.Hash in the same contract, you should use the long form version of the input.Hash attr accessor, which is GetInputHash(input)

You can see an example here, which uses both in the same contract: https://github.com/CityOfZion/neo-boa/blob/master/boa_test/example/blockchain/TransactionTest.py#L88

from neo-boa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.