From 563cd93d438709ed90017dc3608c031bacb9dd49 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Fri, 31 May 2019 11:34:38 -0400 Subject: [PATCH] Add python implementation of dynafed block serialization --- test/functional/test_framework/messages.py | 141 +++++++++++++++++++-- 1 file changed, 133 insertions(+), 8 deletions(-) diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index 02b0f35250..dd12e303e5 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -835,9 +835,101 @@ class CProof: return "CProof(challenge=%s solution=%s)" \ % (self.challenge, self.solution) +class ConsensusParamEntry: + __slots__ = ("m_serialize_type", "m_signblockscript", "m_sbs_wit_limit", "m_fedpegscript", "m_extension_space") + + # Constructor args will define serialization type: + # null = 0 + # signblock-related fields = 1, required for m_current on non-epoch-starts + # all fields = 2, required for epoch starts + def __init__(self, m_signblockscript=b"", m_sbs_wit_limit=0, m_fedpegscript=b"", m_extension_space=[]): + self.m_signblockscript = m_signblockscript + self.m_sbs_wit_limit = m_sbs_wit_limit + self.m_fedpegscript = m_fedpegscript + self.m_extension_space = m_extension_space + if self.is_null(): + self.m_serialize_type = 0 + elif m_fedpegscript==b"" and m_extension_space == []: + self.m_serialize_type = 1 + else: + self.m_serialize_type = 2 + + def set_null(self): + self.m_signblockscript = b"" + self.m_sbs_wit_limit = 0 + self.m_fedpegscript = b"" + self.m_extension_space = [] + self.m_serialize_type = 0 + + def is_null(self): + return self.m_signblockscript == b"" and self.m_sbs_wit_limit == 0 and \ + self.m_fedpegscript == b"" and self.m_extension_space == [] + + def serialize(self): + r = b"" + r += struct.pack("B", self.m_serialize_type) + if self.m_serialize_type == 1: + r += ser_string(self.m_signblockscript) + r += struct.pack(" 2: + raise Exception("Invalid serialization type for ConsensusParamEntry") + return r + + def deserialize(self, f): + self.m_serialize_type = struct.unpack("B", f.read(1))[0] + if self.m_serialize_type == 1: + self.m_signblockscript = deser_string(f) + self.m_sbs_wit_limit = struct.unpack("