Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get address or balance on testnet #9

Closed
l4zygreed opened this issue Jul 10, 2018 · 7 comments
Closed

Can't get address or balance on testnet #9

l4zygreed opened this issue Jul 10, 2018 · 7 comments

Comments

@l4zygreed
Copy link

l4zygreed commented Jul 10, 2018

When I call key.address parameter, it returns PrivateKey, not address (found cashaddress solution)

also key.balance everytime returns 0
when trying to call key.get_unspents() after transaction, it crashes

File "/home/l4zygreed/Templates/btc_py/venv/lib/python3.6/site-packages/bitcash/wallet.py", line 489, in get_unspents
    self.unspents[:] = NetworkAPI.get_unspent_testnet(self.address)
  File "/home/l4zygreed/Templates/btc_py/venv/lib/python3.6/site-packages/bitcash/network/services.py", line 315, in get_unspent_testnet
    return api_call(address)
  File "/home/l4zygreed/Templates/btc_py/venv/lib/python3.6/site-packages/bitcash/network/services.py", line 157, in get_unspent_testnet
    for tx in r.json()
  File "/home/l4zygreed/Templates/btc_py/venv/lib/python3.6/site-packages/bitcash/network/services.py", line 157, in <listcomp>
    for tx in r.json()
KeyError: 'scriptPubKey'
@l4zygreed l4zygreed changed the title Can't get address Can't get address or balance on testnet Jul 10, 2018
@ghost
Copy link

ghost commented Jul 10, 2018

Can you give some more code examples? key.address should return an address properly.

>>> key = bitcash.PrivateKeyTestnet.from_hex('da2876b3eb31edb4436fa4650673fc6f01f90de2f1793c4ec332b2387b09726f')
>>> key.address
'bchtest:qq9gh20y2vur63tpe0xa5dh90zwzsuxagynn6xtttd'
>>> key.balance
0

The test cases should cover testnet as well. You can run nosetests -vx to run those.

I have been doing this on Python 3.5, possible there's something that breaks in Python 3.6.

@l4zygreed
Copy link
Author

l4zygreed commented Jul 10, 2018

sorry, expected legacy (shorter) type of address, like in original git repo

key.get_unspets still cryshing until first confirmation on network
and key.balance still 0

>>> key.get_unspents()
[Unspent(amount=200000000, confirmations=8, script='76a9141944c73fec145bd87f3e427921568d21a95694ea88ac', txid='eabf0b3e4d4d806c1a0f4dd111cbc5c1dbfe6a7a6fdbcbfe760c709c23e9b079', txindex=1)]
>>> key.balance
0

founded another problem, I can't transfer funds

>>> key.create_transaction([], leftover='mqFJqi8SMevMdALqDdUsgiW3FEjVXYqWsv')
'010000000179b0e9239c700c76fecbdb6f7a6afedbc1c5cb11d14d0f1a6c804d4d3e0bbfea010000006a47304402201f3d47f09710d9b556d3175694637dfef838a1fb3cddcdcee1ec37870f3e352e022031eb23a8cdbeb249e1355badef19aff5a68f967f9987385dc2f8e660601015984121039990a14e6b7ad0237e1dd5801e277938d9642794b900a8e8fcec220417496b81ffffffff0100bfeb0b000000001976a9146abbc0d28291128f3b70460a3c0e02e2393bd3cd88ac00000000'
>>> key.transactions
[]

key.send returns error

>>> key.send([('mqFJqi8SMevMdALqDdUsgiW3FEjVXYqWsv', 100000000, 'satoshi')])
ERROR:root:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/l4zygreed/Templates/btc_py/venv/lib/python3.6/site-packages/bitcash/wallet.py", line 587, in send
    NetworkAPI.broadcast_tx_testnet(tx_hex)
  File "/home/l4zygreed/Templates/btc_py/venv/lib/python3.6/site-packages/bitcash/network/services.py", line 366, in broadcast_tx_testnet
    raise ConnectionError('Transaction broadcast failed, or '
ConnectionError: Transaction broadcast failed, or Unspents were already used.

@ghost
Copy link

ghost commented Jul 10, 2018

key.get_unspets still cryshing until first confirmation on network

This is going to depend on the behavior of the one (or two?) upstream testnet APIs in use.

founded another problem, I can't transfer funds

key.transactions will only show a list of transactions that have been on the network. I could be wrong on that, but creating a transaction (which only returns the hex and nothing else) definitely won't update that. You'll have to send to expect any change there. Even then, that feature could be broken, not really sure.

ConnectionError: Transaction broadcast failed, or Unspents were already used.

This error usually comes upstream. I want to improve logging here so that there's at least some warning with what happened.

I'm going to dig into this some more. I would try to stick with the cashaddr format if you can, it's what the API is designed around.

I use bitcash heavily on mainnet but some features are untested by me. If you see insufficient testing you can push up a PR with more test cases.

@ghost
Copy link

ghost commented Jul 10, 2018

KeyError: 'scriptPubKey'

This is coming from tbch.blockdozer.com. I am making a change to ignore keys without 'scriptPubKey'.

Example:

> GET /insight-api/addr/bchtest:qzvsaasdvw6mt9j2rs3gyps673gj86flev3z0s40ln/utxo HTTP/1.1
> Host: tbch.blockdozer.com
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Tue, 10 Jul 2018 16:42:39 GMT
< Content-Type: application/json; charset=utf-8
< Server: Kestrel
< Cache-Control: public,max-age=30
< Transfer-Encoding: chunked
< Set-Cookie: blockdoza=8d24278ea9a95d8500d820ffcaa835d226acd425; path=/; domain=blockdozer.com
< 
[{"address":"muUFbvTKDEokGTVUjScMhw1QF2rtv5hxCz","txid":"102f4862300fc2388bdf69d42f572e6d083a0246de6bd28b71cfe11aff750b8a","vout":1,"scriptPubKey":"76a914990ef60d63b5b5964a1c2282061af45123e93fcb88ac","amount":0.79069138,"satoshis":79069138,"height":1245981,"confirmations":1},{"address":"muUFbvTKDEokGTVUjScMhw1QF2rtv5hxCz","txid":"0dabf31a8806c230b8cd92f0699228315900e6560e311ec7230d95b4383b2327","vout":1,"amount":0.79058234,"satoshis":79058234,"height":-1,"confirmations":0},{"address":"muUFbvTKDEokGTVUjScMhw1QF2rtv5hxCz","txid":"0dabf31a8806c230b8cd92f0699228315900e6560e311ec7230d95b4383b2327","vout":0,"amount":-0.79069138,"satoshis":-79069138,"height":-1,"confirmations":0}]

@ghost
Copy link

ghost commented Jul 10, 2018

Alright, I just pushed a commit (but no release) with some improvements. The Blockdozer API made some changes, breaking TX sends for testnet, and changing the unspent format. They don't have pubscripthash on unconfirmed transactions now. We could allow that to be set to None, but may cause other problems.

You may want to contact Blockdozer and get them in the loop on this thread. Not sure how much of this affects mainnet and not just testnet.

@ghost
Copy link

ghost commented Jul 10, 2018

Also, key.balance is only accurate after getting unspents. Or maybe doing a send. It starts at 0, maybe not the best behavior.

@ghost
Copy link

ghost commented Jul 10, 2018

Pushed one more commit. Tests can pass now if the timing is right.

merc1er pushed a commit that referenced this issue Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant