Skip to content

Commit

Permalink
Implement support for GETMNLISTD and MNLISTDIFF P2P message in minino…
Browse files Browse the repository at this point in the history
…de.py
  • Loading branch information
codablock committed Apr 4, 2019
1 parent 585b9c2 commit ef6b6a1
Showing 1 changed file with 83 additions and 1 deletion.
84 changes: 83 additions & 1 deletion qa/rpc-tests/test_framework/mininode.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,37 @@ def serialize(self):
return r


class CSimplifiedMNListEntry(object):
def __init__(self):
self.set_null()

def set_null(self):
self.proRegTxHash = 0
self.confirmedHash = 0
self.service = CService()
self.pubKeyOperator = b'\\x0' * 48
self.keyIDVoting = 0
self.isValid = False

def deserialize(self, f):
self.proRegTxHash = deser_uint256(f)
self.confirmedHash = deser_uint256(f)
self.service.deserialize(f)
self.pubKeyOperator = f.read(48)
self.keyIDVoting = f.read(20)
self.isValid = struct.unpack("<?", f.read(1))[0]

def serialize(self):
r = b""
r += ser_uint256(self.proRegTxHash)
r += ser_uint256(self.confirmedHash)
r += self.service.serialize()
r += self.pubKeyOperator
r += self.keyIDVoting
r += struct.pack("<?", self.isValid)
return r


# Objects that correspond to messages on the wire
class msg_version(object):
command = b"version"
Expand Down Expand Up @@ -1404,6 +1435,55 @@ def serialize(self):
def __repr__(self):
return "msg_blocktxn(block_transactions=%s)" % (repr(self.block_transactions))

class msg_getmnlistd(object):
command = b"getmnlistd"

def __init__(self, baseBlockHash=0, blockHash=0):
self.baseBlockHash = baseBlockHash
self.blockHash = blockHash

def deserialize(self, f):
self.baseBlockHash = deser_uint256(f)
self.blockHash = deser_uint256(f)

def serialize(self):
r = b""
r += ser_uint256(self.baseBlockHash)
r += ser_uint256(self.blockHash)
return r

def __repr__(self):
return "msg_getmnlistd(baseBlockHash=%064x, blockHash=%064x)" % (self.baseBlockHash, self.blockHash)

class msg_mnlistdiff(object):
command = b"mnlistdiff"

def __init__(self):
self.baseBlockHash = 0
self.blockHash = 0
self.merkleProof = CPartialMerkleTree()
self.cbTx = None
self.deletedMNs = []
self.mnList = []

def deserialize(self, f):
self.baseBlockHash = deser_uint256(f)
self.blockHash = deser_uint256(f)
self.merkleProof.deserialize(f)
self.cbTx = CTransaction()
self.cbTx.deserialize(f)
self.cbTx.rehash()
self.deletedMNs = deser_uint256_vector(f)
self.mnList = []
for i in range(deser_compact_size(f)):
e = CSimplifiedMNListEntry()
e.deserialize(f)
self.mnList.append(e)

def __repr__(self):
return "msg_mnlistdiff(baseBlockHash=%064x, blockHash=%064x)" % (self.baseBlockHash, self.blockHash)


# This is what a callback should look like for NodeConn
# Reimplement the on_* functions to provide handling for events
class NodeConnCB(object):
Expand Down Expand Up @@ -1487,6 +1567,7 @@ 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
def on_mnlistdiff(self, conn, message): pass

# More useful callbacks and functions for NodeConnCB's which have a single NodeConn
class SingleNodeConnCB(NodeConnCB):
Expand Down Expand Up @@ -1543,7 +1624,8 @@ class NodeConn(asyncore.dispatcher):
b"sendcmpct": msg_sendcmpct,
b"cmpctblock": msg_cmpctblock,
b"getblocktxn": msg_getblocktxn,
b"blocktxn": msg_blocktxn
b"blocktxn": msg_blocktxn,
b"mnlistdiff": msg_mnlistdiff
}
MAGIC_BYTES = {
"mainnet": b"\xbf\x0c\x6b\xbd", # mainnet
Expand Down

0 comments on commit ef6b6a1

Please sign in to comment.