Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/messages.py
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
# NODE_WITNESS = (1 << 3) | # NODE_WITNESS = (1 << 3) | ||||
NODE_XTHIN = (1 << 4) | NODE_XTHIN = (1 << 4) | ||||
NODE_BITCOIN_CASH = (1 << 5) | NODE_BITCOIN_CASH = (1 << 5) | ||||
NODE_NETWORK_LIMITED = (1 << 10) | NODE_NETWORK_LIMITED = (1 << 10) | ||||
NODE_AVALANCHE = (1 << 24) | NODE_AVALANCHE = (1 << 24) | ||||
MSG_TX = 1 | MSG_TX = 1 | ||||
MSG_BLOCK = 2 | MSG_BLOCK = 2 | ||||
MSG_FILTERED_BLOCK = 3 | |||||
MSG_CMPCTBLOCK = 4 | MSG_CMPCTBLOCK = 4 | ||||
MSG_TYPE_MASK = 0xffffffff >> 2 | MSG_TYPE_MASK = 0xffffffff >> 2 | ||||
# Serialization/deserialization tools | # Serialization/deserialization tools | ||||
def sha256(s): | def sha256(s): | ||||
return hashlib.new('sha256', s).digest() | return hashlib.new('sha256', s).digest() | ||||
▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | def __repr__(self): | ||||
self.nServices, self.ip, self.port) | self.nServices, self.ip, self.port) | ||||
class CInv: | class CInv: | ||||
__slots__ = ("hash", "type") | __slots__ = ("hash", "type") | ||||
typemap = { | typemap = { | ||||
0: "Error", | 0: "Error", | ||||
1: "TX", | MSG_TX: "TX", | ||||
2: "Block", | MSG_BLOCK: "Block", | ||||
4: "CompactBlock" | MSG_FILTERED_BLOCK: "filtered Block", | ||||
MSG_CMPCTBLOCK: "CompactBlock" | |||||
} | } | ||||
def __init__(self, t=0, h=0): | def __init__(self, t=0, h=0): | ||||
self.type = t | self.type = t | ||||
self.hash = h | self.hash = h | ||||
def deserialize(self, f): | def deserialize(self, f): | ||||
self.type = struct.unpack("<i", f.read(4))[0] | self.type = struct.unpack("<i", f.read(4))[0] | ||||
▲ Show 20 Lines • Show All 1,051 Lines • ▼ Show 20 Lines | def serialize(self): | ||||
r += ser_uint256(self.data) | r += ser_uint256(self.data) | ||||
return r | return r | ||||
def __repr__(self): | def __repr__(self): | ||||
return "msg_reject: {} {} {} [{:064x}]".format( | return "msg_reject: {} {} {} [{:064x}]".format( | ||||
self.message, self.code, self.reason, self.data) | self.message, self.code, self.reason, self.data) | ||||
class msg_merkleblock: | |||||
command = b"merkleblock" | |||||
def deserialize(self, f): | |||||
pass # Placeholder for now | |||||
class msg_filterload: | |||||
__slots__ = ("data", "nHashFuncs", "nTweak", "nFlags") | |||||
command = b"filterload" | |||||
def __init__(self, data=b'00', nHashFuncs=0, nTweak=0, nFlags=0): | |||||
self.data = data | |||||
self.nHashFuncs = nHashFuncs | |||||
self.nTweak = nTweak | |||||
self.nFlags = nFlags | |||||
def deserialize(self, f): | |||||
self.data = deser_string(f) | |||||
self.nHashFuncs = struct.unpack("<I", f.read(4))[0] | |||||
self.nTweak = struct.unpack("<I", f.read(4))[0] | |||||
self.nFlags = struct.unpack("<B", f.read(1))[0] | |||||
def serialize(self): | |||||
r = b"" | |||||
r += ser_string(self.data) | |||||
r += struct.pack("<I", self.nHashFuncs) | |||||
r += struct.pack("<I", self.nTweak) | |||||
r += struct.pack("<B", self.nFlags) | |||||
return r | |||||
def __repr__(self): | |||||
return "msg_filterload(data={}, nHashFuncs={}, nTweak={}, nFlags={})".format( | |||||
self.data, self.nHashFuncs, self.nTweak, self.nFlags) | |||||
class msg_feefilter: | class msg_feefilter: | ||||
__slots__ = ("feerate",) | __slots__ = ("feerate",) | ||||
command = b"feefilter" | command = b"feefilter" | ||||
def __init__(self, feerate=0): | def __init__(self, feerate=0): | ||||
self.feerate = feerate | self.feerate = feerate | ||||
def deserialize(self, f): | def deserialize(self, f): | ||||
▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines |