pybitcash/bitcash

Error when trying to get Tx Details from BchTestnet using NetworkAPI.get_transaction_testnet

Closed this issue ยท 9 comments

When trying to get details of an existing transaction on the Testnet the following error is raised:

Traceback (most recent call last):
File "4GetTxDetails.py", line 11, in
transaction=NetworkAPI.get_transaction_testnet("[redacted]")
File "/usr/local/lib/python3.6/dist-packages/bitcash/network/services.py", line 489, in get_transaction_testnet
return api_call(txid)
File "/usr/local/lib/python3.6/dist-packages/bitcash/network/services.py", line 298, in get_transaction_testnet
tx = Transaction(response['txid'], response['blockheight'],
KeyError: 'blockheight'

Steps taken with no success:
-Increased service timeout

Seems that the bug it's that there is no "/tx/" in blockchain.com rest api but instead it's https://rest.bitcoin.com/v2/transaction/details/$TxId
(trest in case of testnet)

Thanks for looking into that. Let me get back to you.

Yeah, this is definitely broken.

@merc1er, it looks like get_transaction is broken on bitcore and on rest.bitcoin.com. Do you know if this was changed recently or maybe broken to begin with?

I'm pretty sure it was broken to begin with. I am working on this.

This is somewhat fixed at https://github.com/merc1er/bitcash.

Tested with:

import bitcash

bitcash.network.NetworkAPI.get_transaction('0d840c0351f554fa2579e7d47c025ab5d22eb1d4ca34126b7eaa8f5195a2a849')

bitcash.network.NetworkAPI.get_transaction_testnet('37e22c74c09f61a03d4e9fd64602c716fa65377cf3561dc9bab7ac12a25483ee')

This should return:
0d840c0351f554fa2579e7d47c025ab5d22eb1d4ca34126b7eaa8f5195a2a849 in block 623076 for 18471968 satoshi (18471159 sent + 809 fee) with 3 inputs and 4 outputs

37e22c74c09f61a03d4e9fd64602c716fa65377cf3561dc9bab7ac12a25483ee in block 1173910 for 1095999600 satoshi (1094999600 sent + 1000000 fee) with 1 input and 101 outputs

Ok after testing this is working for all transactions except coinbase transaction because they do not have inputs.

Example:

>>> import bitcash
>>> bitcash.network.NetworkAPI.get_transaction('c28a74ac58de9852721eeecec5999f9a9b04d0102ef65fd52a1337a612f65d5d')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/corentinmercier/Documents/bitcash/bitcash/network/services.py", line 472, in get_transaction
    return api_call(txid)
  File "/Users/corentinmercier/Documents/bitcash/bitcash/network/services.py", line 132, in get_transaction
    (Decimal(response['valueIn']) *
KeyError: 'valueIn'

If anyone can look into it feel free to submit PRs to merc1er/bitcash.

Fixed in #60

Thank you, @merc1er! @selfdrivingmenee, can you test master and see if it works for you?

Working thanks!