2

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.

1 Answer 1

4

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

Install either version of pybitcointools using setup.py 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").

2
  • Does Pybitcointools send an RPC call to bitcoind to deserialize raw transactions or does it do the conversion within the module?
    – SLee
    Jul 13, 2015 at 0:48
  • 1
    @SLee From the module: no RPC required Jul 13, 2015 at 2:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.