MCPcopy
hub / github.com/jimmysong/programmingbitcoin / parse

Method parse

code-ch13/network.py:274–289  ·  view source on GitHub ↗
(cls, stream)

Source from the content-addressed store, hash-verified

272
273 @classmethod
274 def parse(cls, stream):
275 # number of headers is in a varint
276 num_headers = read_varint(stream)
277 # initialize the blocks array
278 blocks = []
279 # loop through number of headers times
280 for _ in range(num_headers):
281 # add a block to the blocks array by parsing the stream
282 blocks.append(Block.parse(stream))
283 # read the next varint (num_txs)
284 num_txs = read_varint(stream)
285 # num_txs should be 0 or raise a RuntimeError
286 if num_txs != 0:
287 raise RuntimeError('number of txs not 0')
288 # return a class instance
289 return cls(blocks)
290
291
292class HeadersMessageTest(TestCase):

Callers

nothing calls this directly

Calls 2

read_varintFunction · 0.90
parseMethod · 0.45

Tested by

no test coverage detected