Returns the byte serialization of the entire network message
(self)
| 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''' |
no test coverage detected