Author

Topic: python-bitcoinlib, creating CBlock with getblocktemplate data (Read 1044 times)

legendary
Activity: 1456
Merit: 1083
I may write code in exchange for bitcoins.
I don't have experience with this lib.  But I took a look at the documentation you linked to as well as your example code.  I see that you create a list of CTransaction objects and pass that as the last argument to CBlock.  The docs show the last argument as a tuple of vtx. So, here are a couple of ideas.


EDIT: removed wrong ideas after looking a bit deeper.

Can you follow the call stack from that CBlock construction all the way to line 328 in stream_deserialize?  I can't see enough of your code to tell how you got there.

Sorry!
newbie
Activity: 8
Merit: 1
Well, there is some documentation, but it doesn't answer my question.. https://media.readthedocs.org/pdf/python-bitcoinlib/latest/python-bitcoinlib.pdf . I was rather hoping that one of the developers would read this forum. Im reading the source code, but its kind of difficult to follow with the high level of abstraction (at least with my experiencie in mostly simple python code).
newbie
Activity: 88
Merit: 0
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:
Code:
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:
Code:
foo[0].stream_deserialize(block['transactions'][0]['data'])
gives
Code:
Traceback (most recent call last):

  File "mining.py", line 165, in
    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"  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?



It looks like you are passing stream data or stream name instead of the stream itself.

This library has zero documentation, but you can take look at file bitcoin/core/serialize.py

newbie
Activity: 8
Merit: 1
BTW is this the correct subforum for this post? I can't really find one that seems to fit the question, but i read that this subforum is not for support inquiries.
newbie
Activity: 8
Merit: 1
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:
Code:
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:
Code:
foo[0].stream_deserialize(block['transactions'][0]['data'])
gives
Code:
Traceback (most recent call last):

  File "mining.py", line 165, in
    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"  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?

Jump to: