def script_to_address(script, vbyte=0):
if re.match('^[0-9a-fA-F]*$', script):
script = binascii.unhexlify(script)
if script[:3] == '\x76\xa9\x14' and script[-2:] == '\x88\xac' and len(script) == 25:
return bin_to_b58check(script[3:-2], vbyte) # pubkey hash addresses
else:
if vbyte == 111:
# Testnet
scripthash_byte = 196
else:
scripthash_byte = 5
# BIP0016 scripthash addresses
return bin_to_b58check(script[2:-1], scripthash_byte)
The testnet vbyte for P2SH addresses is 196. If you call script_to_address(script, 196), this code sets scripthash_byte to 5 instead. It's avoidable by setting vbyte to 111 instead, but it seems odd to use the P2PKH vbyte for a function that creates a P2SH address. I can make a pull request for this if you'd like, but it's a one-line fix.
The testnet vbyte for P2SH addresses is 196. If you call script_to_address(script, 196), this code sets scripthash_byte to 5 instead. It's avoidable by setting vbyte to 111 instead, but it seems odd to use the P2PKH vbyte for a function that creates a P2SH address. I can make a pull request for this if you'd like, but it's a one-line fix.