| 308 | |
| 309 | |
| 310 | class CInv: |
| 311 | __slots__ = ("hash", "type") |
| 312 | |
| 313 | typemap = { |
| 314 | 0: "Error", |
| 315 | MSG_TX: "TX", |
| 316 | MSG_BLOCK: "Block", |
| 317 | MSG_TX | MSG_WITNESS_FLAG: "WitnessTx", |
| 318 | MSG_BLOCK | MSG_WITNESS_FLAG: "WitnessBlock", |
| 319 | MSG_FILTERED_BLOCK: "filtered Block", |
| 320 | MSG_CMPCT_BLOCK: "CompactBlock", |
| 321 | MSG_WTX: "WTX", |
| 322 | } |
| 323 | |
| 324 | def __init__(self, t=0, h=0): |
| 325 | self.type = t |
| 326 | self.hash = h |
| 327 | |
| 328 | def deserialize(self, f): |
| 329 | self.type = struct.unpack("<I", f.read(4))[0] |
| 330 | self.hash = deser_uint256(f) |
| 331 | |
| 332 | def serialize(self): |
| 333 | r = b"" |
| 334 | r += struct.pack("<I", self.type) |
| 335 | r += ser_uint256(self.hash) |
| 336 | return r |
| 337 | |
| 338 | def __repr__(self): |
| 339 | return "CInv(type=%s hash=%064x)" \ |
| 340 | % (self.typemap[self.type], self.hash) |
| 341 | |
| 342 | def __eq__(self, other): |
| 343 | return isinstance(other, CInv) and self.hash == other.hash and self.type == other.type |
| 344 | |
| 345 | |
| 346 | class CBlockLocator: |
no outgoing calls