Skip to content

Commit

Permalink
Use wally.address_to_scriptpubkey
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoComandini committed Jan 9, 2020
1 parent 09709b3 commit 354c90e
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions pywally/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,11 @@ def scriptpubkey_to_address(scriptpubkey: bytes) -> str:

def address_to_scriptpubkey(address: str) -> bytes:
try:
# flags = {
# 'mainnet': wally.WALLY_NETWORK_BITCOIN_MAINNET,
# 'testnet': wally.WALLY_NETWORK_BITCOIN_TESTNET,
# }[pywally.params.NAME]
# return wally.address_to_scriptpubkey(address, flags)
decoded = wally.base58check_to_bytes(address)
if len(decoded) != 21:
raise InvalidAddress('Unexpected length')
if decoded[0] == pywally.params.P2PKH_PREFIX:
return wally.scriptpubkey_p2pkh_from_bytes(decoded[1:21], 0)
elif decoded[0] == pywally.params.P2SH_PREFIX:
return wally.scriptpubkey_p2sh_from_bytes(decoded[1:21], 0)
else:
raise InvalidAddress('Unexpected prefix')
network = {
'mainnet': wally.WALLY_NETWORK_BITCOIN_MAINNET,
'testnet': wally.WALLY_NETWORK_BITCOIN_TESTNET,
}[pywally.params.NAME]
return wally.address_to_scriptpubkey(address, network)
except ValueError:
pass

Expand Down

0 comments on commit 354c90e

Please sign in to comment.