From 28baa597ccdeb76e34f5ac2fa42b124568bde7d2 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Fri, 1 Dec 2023 00:19:54 +0200 Subject: [PATCH] coins: Read Firo ProgPow blocks --- .../contrib/firo_test_framework/mininode.py | 127 ++++++++++++++++-- tests/basicswap/extended/test_firo.py | 5 + 2 files changed, 121 insertions(+), 11 deletions(-) diff --git a/basicswap/interface/contrib/firo_test_framework/mininode.py b/basicswap/interface/contrib/firo_test_framework/mininode.py index 7e52886..4212a80 100644 --- a/basicswap/interface/contrib/firo_test_framework/mininode.py +++ b/basicswap/interface/contrib/firo_test_framework/mininode.py @@ -67,6 +67,18 @@ mininode_socket_map = dict() # access to any data shared with the NodeConnCB or NodeConn. mininode_lock = RLock() + +ZC_GENESIS_BLOCK_TIME = 1414776286 +MTP_SWITCH_TIME = 1544443200 +PP_SWITCH_TIME = 1635228000 + + +def set_regtest() -> None: + global MTP_SWITCH_TIME, PP_SWITCH_TIME + MTP_SWITCH_TIME = 4294967295 + PP_SWITCH_TIME = 4294967295 + + # Serialization/deserialization tools def sha256(s): return hashlib.new('sha256', s).digest() @@ -516,10 +528,12 @@ class CTransaction(object): ver32bit = struct.unpack("> 16) & 0xffff + self.vin = deser_vector(f, CTxIn) self.vout = deser_vector(f, CTxOut) self.nLockTime = struct.unpack("> nProofMTP[mtp::MTP_L*3]; + ''' + self.hashRootMTP = [0] * 16 # uint8_t 16 is 128 bit of blake2b + self.nBlockMTP = None + self.nProofMTP = None + + def IsMTPDataStripped(self): + for i in range(16): + if self.hashRootMTP[i] != 0: + return False + return True + + def deserialize(self, f): + for i in range(16): + self.hashRootMTP[i] = struct.unpack(" bool: + return self.nTime >= MTP_SWITCH_TIME + + def IsProgPow(self) -> bool: + return self.nTime >= PP_SWITCH_TIME + class CBlock(CBlockHeader): def __init__(self, header=None): @@ -1168,6 +1271,8 @@ class CFinalCommitment: r += self.quorumSig r += self.membersSig return r + + # Objects that correspond to messages on the wire class msg_version(object): command = b"version" diff --git a/tests/basicswap/extended/test_firo.py b/tests/basicswap/extended/test_firo.py index bd82653..296c1c7 100644 --- a/tests/basicswap/extended/test_firo.py +++ b/tests/basicswap/extended/test_firo.py @@ -47,6 +47,7 @@ from tests.basicswap.common import ( from basicswap.interface.contrib.firo_test_framework.mininode import ( FromHex, CTransaction, + set_regtest, ) from bin.basicswap_run import startDaemon from basicswap.contrib.rpcauth import generate_salt, password_to_hmac @@ -152,6 +153,10 @@ class Test(BaseTest): @classmethod def prepareExtraCoins(cls): + + # Raise MTP_SWITCH_TIME and PP_SWITCH_TIME in mininode.py + set_regtest() + if cls.restore_instance: void_block_rewards_pubkey = cls.getRandomPubkey() cls.firo_addr = cls.swap_clients[0].ci(Coins.FIRO).pubkey_to_address(void_block_rewards_pubkey)