Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/messages.py
Show All 33 Lines | |||||
MIN_VERSION_SUPPORTED = 60001 | MIN_VERSION_SUPPORTED = 60001 | ||||
# past bip-31 for ping/pong | # past bip-31 for ping/pong | ||||
MY_VERSION = 70014 | MY_VERSION = 70014 | ||||
MY_SUBVERSION = b"/python-mininode-tester:0.0.3/" | MY_SUBVERSION = b"/python-mininode-tester:0.0.3/" | ||||
# from version 70001 onwards, fRelay should be appended to version | # from version 70001 onwards, fRelay should be appended to version | ||||
# messages (BIP37) | # messages (BIP37) | ||||
MY_RELAY = 1 | MY_RELAY = 1 | ||||
MAX_INV_SZ = 50000 | |||||
MAX_LOCATOR_SZ = 101 | MAX_LOCATOR_SZ = 101 | ||||
MAX_BLOCK_BASE_SIZE = 1000000 | MAX_BLOCK_BASE_SIZE = 1000000 | ||||
# 1 BCH in satoshis | # 1 BCH in satoshis | ||||
COIN = 100000000 | COIN = 100000000 | ||||
NODE_NETWORK = (1 << 0) | NODE_NETWORK = (1 << 0) | ||||
NODE_GETUTXO = (1 << 1) | NODE_GETUTXO = (1 << 1) | ||||
Show All 12 Lines | |||||
# Serialization/deserialization tools | # Serialization/deserialization tools | ||||
def sha256(s): | def sha256(s): | ||||
return hashlib.new('sha256', s).digest() | return hashlib.new('sha256', s).digest() | ||||
def ripemd160(s): | |||||
return hashlib.new('ripemd160', s).digest() | |||||
def hash256(s): | def hash256(s): | ||||
return sha256(sha256(s)) | return sha256(sha256(s)) | ||||
def ser_compact_size(size): | def ser_compact_size(size): | ||||
r = b"" | r = b"" | ||||
if size < 253: | if size < 253: | ||||
r = struct.pack("B", size) | r = struct.pack("B", size) | ||||
▲ Show 20 Lines • Show All 781 Lines • ▼ Show 20 Lines | def serialize(self): | ||||
return r | return r | ||||
def __repr__(self): | def __repr__(self): | ||||
return "TCPAvalancheResponse(response={}, sig={})".format( | return "TCPAvalancheResponse(response={}, sig={})".format( | ||||
repr(self.response), self.sig) | repr(self.response), self.sig) | ||||
class CPartialMerkleTree: | class CPartialMerkleTree: | ||||
__slots__ = ("fBad", "nTransactions", "vBits", "vHash") | __slots__ = ("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 | |||||
def deserialize(self, f): | def deserialize(self, f): | ||||
self.nTransactions = struct.unpack("<i", f.read(4))[0] | self.nTransactions = struct.unpack("<i", f.read(4))[0] | ||||
self.vHash = deser_uint256_vector(f) | self.vHash = deser_uint256_vector(f) | ||||
vBytes = deser_string(f) | vBytes = deser_string(f) | ||||
self.vBits = [] | self.vBits = [] | ||||
for i in range(len(vBytes) * 8): | for i in range(len(vBytes) * 8): | ||||
self.vBits.append(vBytes[i // 8] & (1 << (i % 8)) != 0) | self.vBits.append(vBytes[i // 8] & (1 << (i % 8)) != 0) | ||||
▲ Show 20 Lines • Show All 651 Lines • Show Last 20 Lines |