Bitcoin/address validation: Difference between revisions

→‎{{header|Python}}: Provided error capturing for addresses that cannot be decoded using the decode_base58
(→‎{{header|Python}}: Provided error capturing for addresses that cannot be decoded using the decode_base58)
Line 1,551:
return n.to_bytes(length, 'big')
def check_bc(bc):
try:
bcbytes = decode_base58(bc, 25)
return bcbytes[-4:] == sha256(sha256(bcbytes[:-4]).digest()).digestdecode_base58(bc, 25)[:4]
return bcbytes[-4:] == sha256(sha256(bcbytes[:-4]).digest()).digest()[:4]
except Exception:
return False
 
print(check_bc('1AGNa15ZQXAZUgFiqJ3i7Z2DPU2J6hW62i'))
Anonymous user