Skip to content

Commit

Permalink
Merge pull request #1155 from pataegrillo/master
Browse files Browse the repository at this point in the history
Looks good in testing dispenses on p2sh, legacy, and bech32 addresses
  • Loading branch information
jdogresorg authored Feb 22, 2022
2 parents 478fb28 + de8a875 commit 127d5c6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
28 changes: 21 additions & 7 deletions counterpartylib/lib/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,23 +479,37 @@ 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():
pubkey = scriptpubkey[2:]
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
Expand Down
2 changes: 1 addition & 1 deletion counterpartylib/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
8 changes: 8 additions & 0 deletions counterpartylib/protocol_changes.json
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
}

0 comments on commit 127d5c6

Please sign in to comment.