MCPcopy Index your code
hub / github.com/jimmysong/programmingbitcoin / serialize

Method serialize

code-ch13/network.py:72–85  ·  view source on GitHub ↗

Returns the byte serialization of the entire network message

(self)

Source from the content-addressed store, hash-verified

70 return cls(command, payload, testnet=testnet)
71
72 def serialize(self):
73 '''Returns the byte serialization of the entire network message'''
74 # add the network magic
75 result = self.magic
76 # command 12 bytes
77 # fill with 0's
78 result += self.command + b'\x00' * (12 - len(self.command))
79 # payload length 4 bytes, little endian
80 result += int_to_little_endian(len(self.payload), 4)
81 # checksum 4 bytes, first four of hash256 of payload
82 result += hash256(self.payload)[:4]
83 # payload
84 result += self.payload
85 return result
86
87 def stream(self):
88 '''Returns a stream for parsing the payload'''

Callers 1

sendMethod · 0.95

Calls 2

int_to_little_endianFunction · 0.90
hash256Function · 0.90

Tested by

no test coverage detected