diff --git a/qa/rpc-tests/test_framework/mininode.py b/qa/rpc-tests/test_framework/mininode.py --- a/qa/rpc-tests/test_framework/mininode.py +++ b/qa/rpc-tests/test_framework/mininode.py @@ -42,11 +42,11 @@ BIP0031_VERSION = 60000 MY_VERSION = 70014 # past bip-31 for ping/pong MY_SUBVERSION = b"/python-mininode-tester:0.0.3/" -MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37) +MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37) MAX_INV_SZ = 50000 -COIN = 100000000 # 1 btc in satoshis +COIN = 100000000 # 1 btc in satoshis NODE_NETWORK = (1 << 0) NODE_GETUTXO = (1 << 1) @@ -72,15 +72,20 @@ mininode_lock = RLock() # Serialization/deserialization tools + + def sha256(s): return hashlib.new('sha256', s).digest() + def ripemd160(s): return hashlib.new('ripemd160', s).digest() + def hash256(s): return sha256(sha256(s)) + def ser_compact_size(l): r = b"" if l < 253: @@ -93,6 +98,7 @@ r = struct.pack(" 1: newhashes = [] for i in range(0, len(hashes), 2): - i2 = min(i+1, len(hashes)-1) + i2 = min(i + 1, len(hashes) - 1) newhashes.append(hash256(hashes[i] + hashes[i2])) hashes = newhashes return uint256_from_str(hashes[0]) @@ -668,6 +696,7 @@ class CUnsignedAlert(object): + def __init__(self): self.nVersion = 1 self.nRelayUntil = 0 @@ -723,6 +752,7 @@ class CAlert(object): + def __init__(self): self.vchMsg = b"" self.vchSig = b"" @@ -743,7 +773,8 @@ class PrefilledTransaction(object): - def __init__(self, index=0, tx = None): + + def __init__(self, index=0, tx=None): self.index = index self.tx = tx @@ -768,7 +799,10 @@ return "PrefilledTransaction(index=%d, tx=%s)" % (self.index, repr(self.tx)) # This is what we send on the wire, in a cmpctblock message. + + class P2PHeaderAndShortIDs(object): + def __init__(self): self.header = CBlockHeader() self.nonce = 0 @@ -784,7 +818,8 @@ for i in range(self.shortids_length): # shortids are defined to be 6 bytes in the spec, so append # two zero bytes and read it in as an 8-byte number - self.shortids.append(struct.unpack(" BIP0031_VERSION: conn.send_message(msg_pong(message.nonce)) + def on_reject(self, conn, message): pass + def on_open(self, conn): pass + def on_close(self, conn): pass + def on_mempool(self, conn): pass + def on_pong(self, conn, message): pass + def on_feefilter(self, conn, message): pass + def on_sendheaders(self, conn, message): pass + def on_sendcmpct(self, conn, message): pass + def on_cmpctblock(self, conn, message): pass + def on_getblocktxn(self, conn, message): pass + def on_blocktxn(self, conn, message): pass -# More useful callbacks and functions for NodeConnCB's which have a single NodeConn +# More useful callbacks and functions for NodeConnCB's which have a single +# NodeConn + + class SingleNodeConnCB(NodeConnCB): + def __init__(self): NodeConnCB.__init__(self) self.connection = None @@ -1589,6 +1679,8 @@ # The actual NodeConn class # This class provides an interface for a p2p connection to a specified node + + class NodeConn(asyncore.dispatcher): messagemap = { b"version": msg_version, @@ -1648,8 +1740,8 @@ vt.addrFrom.port = 0 self.send_message(vt, True) - print('MiniNode: Connecting to Bitcoin Node IP # ' + dstaddr + ':' \ - + str(dstport)) + print('MiniNode: Connecting to Bitcoin Node IP # ' + dstaddr + ':' + + str(dstport)) try: self.connect((dstaddr, dstport)) @@ -1729,26 +1821,29 @@ if self.ver_recv < 209: if len(self.recvbuf) < 4 + 12 + 4: return None - command = self.recvbuf[4:4+12].split(b"\x00", 1)[0] - msglen = struct.unpack("