I'm trying to learn about bitcoin by writing a python bitcoin miner using python-bitcoinlib (
https://github.com/petertodd/python-bitcoinlib).
I'm having problems creating a complete CBlock with data from a getblocktemplate request. I get all parameters right except from the transactions, the
vtx() in the function argument.
CBlock() accepts an array of
CTransaction()-objects. Is this the correct parameter? If so, how do I populate add data to the
CTransaction()-objects from the getblocktemplate data? I've tried using the template transaction-data, but I only get errors of the type: AttributeError: 'unicode' object has no attribute 'read'. I tried formatting the data as string or int aswell. What kind of object should be passed to
CTransaction()? I'm reading the source code, but I can't figure it out.
No error:
foo = [bitcoin.core.CTransaction() for i in range(5)]
mineBlock = bitcoin.core.CBlock(2, bitcoin.core.x(block['previousblockhash']),bitcoin.core.x(mHash),block['curtime'],int(block['bits'],16),0x00,foo)
Error:
foo[0].stream_deserialize(block['transactions'][0]['data'])
gives
Traceback (most recent call last):
File "mining.py", line 165, in <module>
foo[0].stream_deserialize(block['transactions'][0]['data'])
File "/home/hadoque/.local/lib/python2.7/site-packages/bitcoin/core/__init__.py", line 328, in stream_deserialize
nVersion = struct.unpack(b"<i", ser_read(f,4))[0]
File "/home/hadoque/.local/lib/python2.7/site-packages/bitcoin/core/serialize.py", line 79, in ser_read
r = f.read(n)
AttributeError: 'unicode' object has no attribute 'read'
So, am I submitting the right data but in wrong format (how do I make data a serializable object?) or is the data wrong all together?