What is the required input for python-bitcoinlib getrawtransaction command?

2

I am running a bitcoin node on my machine, fully synced with RPC commands enabled, rpc server live and txindex=1.

In the command-line I can run the following RPC call and obtain the information about the transaction I require. I am using the cli as I need to process 2.5 million transactions.

./bitcoin-cli decoderawtransaction $(./bitcoin-cli getrawtransaction b601fc820d66b6516f89557fba9b40943df962de96b914547dec72b0f047c2f3)

Which returns a JSON output of the transaction.

However, when run with the python-bitcoinlib library it seems to give the following error message

import bitcoin, bitcoin.rpc bitcoin.SelectParams("mainnet") rpc = bitcoin.rpc.Proxy() rpc.getrawtransaction("b601fc820d66b6516f89557fba9b40943df962de96b914547dec72b0f047c2f3")

InvalidParameterError: {u'message': u'parameter 1 must be of length 64 (not 128)', u'code': -8}

What am I doing wrong, isn't b601.. the transaction id?

Edit: As per comment I fixed it by replacing rpc=bitcoin.rpc.Proxy() with rpc=bitcoin.rpc.RawProxy(). But I would still like to know why the previous fails.

Oonah

Posted 2017-09-04T13:03:16.010

Reputation: 65

1I fixed it by replacing rpc=bitcoin.rpc.Proxy() with rpc=bitcoin.rpc.RawProxy(). But I would still like to know why the previous failsOonah 2017-09-04T13:07:00.287

I suppose there's a difference parsing the hexstring when you use Proxy vs. RawProxy.renlord 2017-10-17T11:30:42.097

Answers

-2

getrawtransaction requires little endian format of the trxid, like:

import bitcoin.rpc
from bitcoin.core import lx
p = bitcoin.rpc.Proxy(service_url='http://usr:pa@ip:port')
trxid = lx('7e195aa3de827814f172c362fcf838d92ba10e3f9fdd9c3ecaf79522b311b22d')
rawtrx = p.getrawtransaction(trxid)
print(rawtrx)

Comments from Mr Peter Todd on that:

https://github.com/petertodd/python-bitcoinlib/blob/master/examples/spend-p2pkh-txout.py#L41

flck

Posted 2017-09-04T13:03:16.010

Reputation: 1