bitcoinlib icon indicating copy to clipboard operation
bitcoinlib copied to clipboard

serialization issue

Open vpereira opened this issue 4 years ago • 1 comments
trafficstars

from bitcoinlib.services.services import Service
srv = Service()
b = srv.getblock(300953)
print(b.serialize())

gives me the following error:

vpereira@foo:/mnt/c/Users/vpere/codes/bitcoin> python3 1.py
Traceback (most recent call last):
  File "1.py", line 19, in <module>
    print(b.serialize())
  File "/usr/lib/python3.6/site-packages/bitcoinlib/blocks.py", line 298, in serialize
    raise ValueError("Block contains incorrect number of transactions, can not serialize")
ValueError: Block contains incorrect number of transactions, can not serialize

vpereira avatar Apr 08 '21 19:04 vpereira

Yes, that's not the behavior you would expect. For efficiency reasons the getblock method by default only parses the first 10 transactions. So transactions are missing and the block cannot be serialized.

I'm not sure what your goal is, but you can also retrieve the serialized block with the getrawblock method. Or you could add a limit parameter to the getblock method and set it to 9999 for instance.

But I think this needs improvement and the getblock method should store the rawblock as well.

mccwdev avatar Jun 14 '21 20:06 mccwdev