Are there any Python modules that decode raw transaction data?



I'm currently doing RPC calls to bitcoin-cli within python to get raw block data:

bitcoin-cli getblock BLOCKHASH False

I've already written a function that cuts off the block header and splits the transaction block into individual transactions, resulting in the same result as:

bitcoin-cli getrawblock TXID

I'm now trying to convert this data into the same result as

bitcoin-cli getrawblock TXID 1

without doing another RPC call to bitcoind. Would prefer to use pre-existing modules if possible.

Python packages would be appreciated.


Posted 2015-07-09T02:21:19.100

Reputation: 113



Yes, Pybitcointools (or this fork which has BIP39, file embedding and mk_opreturn) can do this.

Install either version of pybitcointools using install, as usual.

Then, with a raw hex transaction, rawtx, simply use txo = deserialize(rawtx). rawtx can be either a signed or unsigned hex transaction. The returned txo is deserialized as a dict object. Use serialize(txo) to get back to rawtx.

You can fetch TxIDs using fetchtx(hex_txid, source="blockr") and send signed Txs with pushtx(signed_hex_tx, source="bci").

Wizard Of Ozzie

Posted 2015-07-09T02:21:19.100

Reputation: 4 920

Does Pybitcointools send an RPC call to bitcoind to deserialize raw transactions or does it do the conversion within the module? – SLee – 2015-07-13T00:48:56.133

1@SLee From the module: no RPC required – Wizard Of Ozzie – 2015-07-13T02:47:41.533