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

Class GetDataMessage

code-ch13/network.py:303–321  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

301
302
303class GetDataMessage:
304 command = b'getdata'
305
306 def __init__(self):
307 self.data = []
308
309 def add_data(self, data_type, identifier):
310 self.data.append((data_type, identifier))
311
312 def serialize(self):
313 # start with the number of items as a varint
314 result = encode_varint(len(self.data))
315 # loop through each tuple (data_type, identifier) in self.data
316 for data_type, identifier in self.data:
317 # data type is 4 bytes Little-Endian
318 result += int_to_little_endian(data_type, 4)
319 # identifier needs to be in Little-Endian
320 result += identifier[::-1]
321 return result
322
323
324class GetDataMessageTest(TestCase):

Callers 1

test_serializeMethod · 0.70

Calls

no outgoing calls

Tested by 1

test_serializeMethod · 0.56