CityOfZion / neo-python

Python Node and SDK for the NEO 2.x blockchain. For NEO 3.x go to our successor project neo-mamba
https://neo-python.readthedocs.io/en/latest/
MIT License
313 stars 189 forks source link

"import token {contract hash}" not work #736

Closed kentarohorie closed 5 years ago

kentarohorie commented 5 years ago

Current behavior

This is log. Default error message is "Could not import token" Error place is neo/Wallets/NEP5Token.py 99 line and I print this log.

Could not execute command: 'NoneType' object has no attribute 'ToString'
  File "/usr/lib64/python3.6/threading.py", line 884, in _bootstrap
    self._bootstrap_inner()
  File "/usr/lib64/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib64/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/twisted/_threads/_threadworker.py", line 46, in work
    task()
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/twisted/_threads/_team.py", line 190, in doWork
    task()
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/twisted/python/threadpool.py", line 250, in inContext
    result = inContext.theWork()
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/twisted/python/threadpool.py", line 266, in <lambda>
    inContext.theWork = lambda: context.call(ctx, func, *args, **kw)
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/twisted/python/context.py", line 122, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/twisted/python/context.py", line 85, in callWithContext
    return func(*args,**kw)
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/neo/bin/prompt.py", line 1031, in run
    traceback.print_stack()
Traceback (most recent call last):
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/neo/bin/prompt.py", line 977, in run
    self.do_import(arguments)
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/neo/bin/prompt.py", line 391, in do_import
    return ImportToken(self.Wallet, get_arg(arguments, 1))
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/neo/Prompt/Commands/Wallet.py", line 112, in ImportToken
    result = token.Query()
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/neo/Wallets/NEP5Token.py", line 101, in Query
    engine = ApplicationEngine.Run(sb.ToArray(), exit_on_error=True, gas=Fixed8.FromDecimal(10.0), test_mode=False)
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/neo/SmartContract/ApplicationEngine.py", line 607, in Run
    events.emit(event.event_type, event)
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/pymitter/__init__.py", line 282, in emit
    remove = [l for l in listeners if not l(*args, **kwargs)]
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/pymitter/__init__.py", line 282, in <listcomp>
    remove = [l for l in listeners if not l(*args, **kwargs)]
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/pymitter/__init__.py", line 310, in __call__
    self.func(*args, **kwargs)
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/neo/EventHub.py", line 62, in on_sc_event
    logger.info("[%s][%s] [%s] [tx %s] %s" % (sc_event.event_type, sc_event.block_number, sc_event.contract_hash, sc_event.tx_hash.ToString(), payload.ToJson(auto_hex=False)))
AttributeError: 'NoneType' object has no attribute 'ToString'

I confirmed all nep5 methods and other my writing methods work expectedly.

Your environment

jseagrave21 commented 5 years ago

After reviewing similar issues in Discord, it seems import token {contract hash} sometimes requires the user to exit the cli then restart np-prompt and try again. Have you tried this?

ixje commented 5 years ago

Are you using a self-made NEP5 token contract or is it based on a template contract like NEX, Moonlight, MCT?

I'm assuming you're using a private network. Can you please share the console log starting from the build command, to import contract, to import token. The information of using those commands + their return values should give a good idea of a possible root cause. Thanks

kentarohorie commented 5 years ago

@jseagrave21

Yes, I retry at least 5 times or more. I repeated build, import contract, deploy, import token.

I suspect my token's have problem because I can import token nex ico template. So, I want to know reason why I can't import my token.

I confirmed deference between nex ico template and mine, and "import token"'s mechanism, but I can't resolve

ixje commented 5 years ago

It is impossible to tell without any reproducible code. Can you share your contract code so we can try to debug/help you?

kentarohorie commented 5 years ago

@ixje

This is commands and log. https://gist.github.com/kentarohorie/140efd1b9a6d6614f04dea2501702e1c

I want to share all code but I can't because of client...sorry so, what part of the contract code do we need for debug?

thanks for your help

ixje commented 5 years ago

so, what part of the contract code do we need for debug?

I don't know because it depends on where the bug is.

Try the following:

Let us know the output. I'm guessing one of these commands will fail and that's where the import failure comes from.

kentarohorie commented 5 years ago

this is the output.


neo> testinvoke 0x1482f699725e02ee7bd9026695c0c6c779d9b02f name []                                                                      
[I 181207 06:10:45 EventHub:58] [test_mode][SmartContract.Storage.Get] [1482f699725e02ee7bd9026695c0c6c779d9b02f] {'type': 'String', 'value': "b'contract_admin' -> bytearray(b'')"}
[I 181207 06:10:45 EventHub:58] [test_mode][SmartContract.Execution.Success] [1482f699725e02ee7bd9026695c0c6c779d9b02f] {'type': 'Array', 'value': [{'type': 'ByteArray', 'value': b'my token name'}]}
Used 0.249 Gas 

-------------------------------------------------------------------------------------------------------------------------------------
Test invoke successful
Total operations: 235
Results [{'type': 'ByteArray', 'value': 'strings of number and character'}]
Invoke TX GAS cost: 0.0
Invoke TX fee: 0.0001
-------------------------------------------------------------------------------------------------------------------------------------

Enter your password to continue and invoke on the network

[password]>                                                                                                                             
Incorrect password
neo> testinvoke 0x1482f699725e02ee7bd9026695c0c6c779d9b02f symbol []                                                                    
[I 181207 06:10:54 EventHub:58] [test_mode][SmartContract.Storage.Get] [1482f699725e02ee7bd9026695c0c6c779d9b02f] {'type': 'String', 'value': "b'contract_admin' -> bytearray(b'')"}
[I 181207 06:10:54 EventHub:58] [test_mode][SmartContract.Execution.Success] [1482f699725e02ee7bd9026695c0c6c779d9b02f] {'type': 'Array', 'value': [{'type': 'ByteArray', 'value': b'my token symbol(3 length string)'}]}
Used 0.283 Gas 

-------------------------------------------------------------------------------------------------------------------------------------
Test invoke successful
Total operations: 288
Results [{'type': 'ByteArray', 'value': 'strings of number'}]
Invoke TX GAS cost: 0.0
Invoke TX fee: 0.0001
-------------------------------------------------------------------------------------------------------------------------------------

Enter your password to continue and invoke on the network

[password]>                                                                                                                             
Incorrect password
neo> testinvoke 0x1482f699725e02ee7bd9026695c0c6c779d9b02f decimals []                                                                  
[I 181207 06:11:00 EventHub:58] [test_mode][SmartContract.Storage.Get] [1482f699725e02ee7bd9026695c0c6c779d9b02f] {'type': 'String', 'value': "b'contract_admin' -> bytearray(b'')"}
[I 181207 06:11:00 EventHub:58] [test_mode][SmartContract.Execution.Success] [1482f699725e02ee7bd9026695c0c6c779d9b02f] {'type': 'Array', 'value': [{'type': 'Integer', 'value': '8'}]}
Used 0.305 Gas 

-------------------------------------------------------------------------------------------------------------------------------------
Test invoke successful
Total operations: 320
Results [{'type': 'Integer', 'value': '8'}]
Invoke TX GAS cost: 0.0
Invoke TX fee: 0.0001
-------------------------------------------------------------------------------------------------------------------------------------

Enter your password to continue and invoke on the network

[password]>                                                                                                                             
Incorrect password
neo>  

I suspect other reason. I confirm this bug occur in neo/Wallets/NEP5Token.py 99 line.

File "/home/ec2-user/venv/lib64/python3.6/site-packages/neo/Wallets/NEP5Token.py", line 101, in Query
    engine = ApplicationEngine.Run(sb.ToArray(), exit_on_error=True, gas=Fixed8.FromDecimal(10.0), test_mode=False)
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/neo/SmartContract/ApplicationEngine.py", line 607, in Run
    events.emit(event.event_type, event)
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/pymitter/__init__.py", line 282, in emit
    remove = [l for l in listeners if not l(*args, **kwargs)]
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/pymitter/__init__.py", line 282, in <listcomp>
    remove = [l for l in listeners if not l(*args, **kwargs)]
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/pymitter/__init__.py", line 310, in __call__
    self.func(*args, **kwargs)
  File "/home/ec2-user/venv/lib64/python3.6/site-packages/neo/EventHub.py", line 62, in on_sc_event
    logger.info("[%s][%s] [%s] [tx %s] %s" % (sc_event.event_type, sc_event.block_number, sc_event.contract_hash, sc_event.tx_hash.ToString(), payload.ToJson(auto_hex=False)))
AttributeError: 'NoneType' object has no attribute 'ToString'
ixje commented 5 years ago

The error message doesn't give enough information to reproduce the error or solve the issue. All it says is that sc_event.tx_hash.ToString() fails because tx_hash is None. Why that is, no clue.

I'd have to see the contract code in order to help you debug. We have many NEP5 tokens working just fine so that tells me there's something wrong with your code. Now to be fair, we should have better error handling and give a more useful message to the user. I'm willing to help on that but I need more information.

If it helps you can share the code privately (just DM me on discord, same name as here). You have to realise that all code on the blockchain is public. So keeping a contract secret isn't really helping you here, because the moment you publish it I can read the code (although only I assembly format). If it helps, you can just share the .avm file (which are only the assembly instructions). That way I can't easily read your code, but I need something to reproduce the bug if you want my help.

ixje commented 5 years ago

Issue appears inactive. If you wish to continue the discussion please comment here and I'll re-open.