Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/messages.py
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
NODE_NETWORK = (1 << 0) | NODE_NETWORK = (1 << 0) | ||||
# NODE_GETUTXO = (1 << 1) | # NODE_GETUTXO = (1 << 1) | ||||
NODE_BLOOM = (1 << 2) | NODE_BLOOM = (1 << 2) | ||||
# 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) | |||||
MSG_TX = 1 | MSG_TX = 1 | ||||
MSG_BLOCK = 2 | MSG_BLOCK = 2 | ||||
MSG_CMPCTBLOCK = 4 | MSG_CMPCTBLOCK = 4 | ||||
MSG_TYPE_MASK = 0xffffffff >> 2 | MSG_TYPE_MASK = 0xffffffff >> 2 | ||||
# Serialization/deserialization tools | # Serialization/deserialization tools | ||||
▲ Show 20 Lines • Show All 696 Lines • ▼ Show 20 Lines | def serialize(self): | ||||
r += ser_vector(self.transactions) | r += ser_vector(self.transactions) | ||||
return r | return r | ||||
def __repr__(self): | def __repr__(self): | ||||
return "BlockTransactions(hash={:064x} transactions={})".format( | return "BlockTransactions(hash={:064x} transactions={})".format( | ||||
self.blockhash, repr(self.transactions)) | self.blockhash, repr(self.transactions)) | ||||
class AvalanchePoll(): | |||||
def __init__(self, round=0, invs=None): | |||||
self.round = round | |||||
self.invs = invs if invs is not None else [] | |||||
def deserialize(self, f): | |||||
self.round = struct.unpack("<q", f.read(8))[0] | |||||
self.invs = deser_vector(f, CInv) | |||||
def serialize(self): | |||||
r = b"" | |||||
r += struct.pack("<q", self.round) | |||||
r += ser_vector(self.invs) | |||||
return r | |||||
def __repr__(self): | |||||
return "AvalanchePoll(round={}, invs={})".format( | |||||
self.round, repr(self.invs)) | |||||
class AvalancheVote(): | |||||
def __init__(self, e=0, h=0): | |||||
self.error = e | |||||
self.hash = h | |||||
def deserialize(self, f): | |||||
self.error = struct.unpack("<i", f.read(4))[0] | |||||
self.hash = deser_uint256(f) | |||||
def serialize(self): | |||||
r = b"" | |||||
r += struct.pack("<i", self.error) | |||||
r += ser_uint256(self.hash) | |||||
return r | |||||
def __repr__(self): | |||||
return "AvalancheVote(error={}, hash={:064x})".format( | |||||
self.error, self.hash) | |||||
class AvalancheResponse(): | |||||
def __init__(self, round=0, cooldown=0, votes=None): | |||||
self.round = round | |||||
self.cooldown = cooldown | |||||
self.votes = votes if votes is not None else [] | |||||
def deserialize(self, f): | |||||
self.round = struct.unpack("<q", f.read(8))[0] | |||||
self.cooldown = struct.unpack("<i", f.read(4))[0] | |||||
self.votes = deser_vector(f, AvalancheVote) | |||||
def serialize(self): | |||||
r = b"" | |||||
r += struct.pack("<q", self.round) | |||||
r += struct.pack("<i", self.cooldown) | |||||
r += ser_vector(self.votes) | |||||
return r | |||||
def __repr__(self): | |||||
return "AvalancheResponse(round={}, cooldown={}, votes={})".format( | |||||
self.round, self.cooldown, repr(self.votes)) | |||||
class CPartialMerkleTree: | class CPartialMerkleTree: | ||||
__slots__ = ("fBad", "nTransactions", "vBits", "vHash") | __slots__ = ("fBad", "nTransactions", "vBits", "vHash") | ||||
def __init__(self): | def __init__(self): | ||||
self.nTransactions = 0 | self.nTransactions = 0 | ||||
self.vHash = [] | self.vHash = [] | ||||
self.vBits = [] | self.vBits = [] | ||||
self.fBad = False | self.fBad = False | ||||
▲ Show 20 Lines • Show All 542 Lines • ▼ Show 20 Lines | class msg_blocktxn: | ||||
def serialize(self): | def serialize(self): | ||||
r = b"" | r = b"" | ||||
r += self.block_transactions.serialize() | r += self.block_transactions.serialize() | ||||
return r | return r | ||||
def __repr__(self): | def __repr__(self): | ||||
return "msg_blocktxn(block_transactions={})".format( | return "msg_blocktxn(block_transactions={})".format( | ||||
repr(self.block_transactions)) | repr(self.block_transactions)) | ||||
class msg_avapoll(): | |||||
command = b"avapoll" | |||||
def __init__(self): | |||||
self.poll = AvalanchePoll() | |||||
def deserialize(self, f): | |||||
self.poll.deserialize(f) | |||||
def serialize(self): | |||||
r = b"" | |||||
r += self.poll.serialize() | |||||
return r | |||||
def __repr__(self): | |||||
return "msg_avapoll(poll={})".format(repr(self.poll)) | |||||
class msg_avaresponse(): | |||||
command = b"avaresponse" | |||||
def __init__(self): | |||||
self.response = AvalancheResponse() | |||||
def deserialize(self, f): | |||||
self.response.deserialize(f) | |||||
def serialize(self): | |||||
r = b"" | |||||
r += self.response.serialize() | |||||
return r | |||||
def __repr__(self): | |||||
return "msg_avaresponse(response={})".format(repr(self.response)) |