diff --git a/counterpartylib/lib/blocks.py b/counterpartylib/lib/blocks.py index 2b28e4d3ac..cf5bc0a092 100644 --- a/counterpartylib/lib/blocks.py +++ b/counterpartylib/lib/blocks.py @@ -479,9 +479,20 @@ def get_tx_info(tx_hex, block_parser=None, block_index=None, db=None): def _get_swap_tx(decoded_tx, block_parser=None, block_index=None, db=None): def get_pubkeyhash(scriptpubkey): asm = script.get_asm(scriptpubkey) - if len(asm) != 5 or asm[0] != 'OP_DUP' or asm[1] != 'OP_HASH160' or asm[3] != 'OP_EQUALVERIFY' or asm[4] != 'OP_CHECKSIG': - return False - return asm[2] + + if len(asm) > 0: + if asm[0] == "OP_DUP": + if len(asm) != 5 or asm[1] != 'OP_HASH160' or asm[3] != 'OP_EQUALVERIFY' or asm[4] != 'OP_CHECKSIG': + return False + else: + return {"pubkeyhash":asm[2],"address_version":config.ADDRESSVERSION} + elif (asm[0] == "OP_HASH160") and util.enabled('p2sh_dispensers_support'): + if len(asm) != 3 or asm[-1] != 'OP_EQUAL': + return False + else: + return {"pubkeyhash":asm[1],"address_version":config.P2SH_ADDRESSVERSION} + + return False def get_address(scriptpubkey): if util.enabled('correct_segwit_txids') and scriptpubkey.is_witness_v0_keyhash(): @@ -489,13 +500,16 @@ def get_address(scriptpubkey): address = str(bitcoinlib.bech32.CBech32Data.from_bytes(0, pubkey)) return address else: - pubkeyhash = get_pubkeyhash(scriptpubkey) - if not pubkeyhash: + pubkeyhashdict = get_pubkeyhash(scriptpubkey) + if not pubkeyhashdict: return False + pubkeyhash = pubkeyhashdict["pubkeyhash"] + address_version = pubkeyhashdict["address_version"] + pubkeyhash = binascii.hexlify(pubkeyhash).decode('utf-8') - address = script.base58_check_encode(pubkeyhash, config.ADDRESSVERSION) + address = script.base58_check_encode(pubkeyhash, address_version) # Test decoding of address. - if address != config.UNSPENDABLE and binascii.unhexlify(bytes(pubkeyhash, 'utf-8')) != script.base58_check_decode(address, config.ADDRESSVERSION): + if address != config.UNSPENDABLE and binascii.unhexlify(bytes(pubkeyhash, 'utf-8')) != script.base58_check_decode(address, address_version): return False return address diff --git a/counterpartylib/lib/config.py b/counterpartylib/lib/config.py index 3b7caeec39..456c0a8429 100644 --- a/counterpartylib/lib/config.py +++ b/counterpartylib/lib/config.py @@ -9,7 +9,7 @@ # Versions VERSION_MAJOR = 9 VERSION_MINOR = 59 -VERSION_REVISION = 5 +VERSION_REVISION = 6 VERSION_STRING = str(VERSION_MAJOR) + '.' + str(VERSION_MINOR) + '.' + str(VERSION_REVISION) diff --git a/counterpartylib/protocol_changes.json b/counterpartylib/protocol_changes.json index 47db93a16a..85f93a9132 100644 --- a/counterpartylib/protocol_changes.json +++ b/counterpartylib/protocol_changes.json @@ -271,5 +271,13 @@ "minimum_version_revision": 3, "block_index": 670000, "testnet_block_index": 1666625 + }, + "p2sh_dispensers_support": { + "minimum_version_major": 9, + "minimum_version_minor": 59, + "minimum_version_revision": 6, + "block_index": 724000, + "testnet_block_index": 2163328 + } }