vbuterin / pybitcointools

SImple, common-sense Bitcoin-themed Python ECC library
1.28k stars 856 forks source link

script_to_address returns incorrectly for testnet addresses #150

Closed discoltk closed 7 years ago

discoltk commented 7 years ago

Maybe related to compressed vs uncompressed addresses, but this function returns mainnet looking addresses for my testnet transactions.

reiven commented 7 years ago

@discoltk if you take a look into the code, you need to pass the 'magic byte' for testnet to that function to return testnet address from script

def script_to_address(script, vbyte=0):
    if re.match('^[0-9a-fA-F]*$', script):
        script = binascii.unhexlify(script)
    if script[:3] == b'\x76\xa9\x14' and script[-2:] == b'\x88\xac' and len(script) == 25:
        return bin_to_b58check(script[3:-2], vbyte)  # pubkey hash addresses
    else:
        if vbyte in [111, 196]:
            # Testnet
            scripthash_byte = 196
   ...
discoltk commented 7 years ago

@reiven Ah, yea now it makes sense. Saw the magic byte stuff but it didn't click (despite being obvious) that it was an argument I had to pass myself. Thanks!

reiven commented 7 years ago

ok great, you can now close this issue.