MCPcopy Index your code
hub / github.com/petertodd/python-bitcoinlib / decode

Function decode

bitcoin/segwit_addr.py:102–114  ·  view source on GitHub ↗

Decode a segwit address.

(hrp, addr)

Source from the content-addressed store, hash-verified

100
101
102def decode(hrp, addr):
103 """Decode a segwit address."""
104 hrpgot, data = bech32_decode(addr)
105 if hrpgot != hrp:
106 return (None, None)
107 decoded = convertbits(data[1:], 5, 8, False)
108 if decoded is None or len(decoded) < 2 or len(decoded) > 40:
109 return (None, None)
110 if data[0] > 16:
111 return (None, None)
112 if data[0] == 0 and len(decoded) != 20 and len(decoded) != 32:
113 return (None, None)
114 return (data[0], decoded)
115
116
117def encode(hrp, witver, witprog):

Callers 3

__new__Method · 0.90
test_encode_decodeMethod · 0.90
encodeFunction · 0.70

Calls 2

bech32_decodeFunction · 0.85
convertbitsFunction · 0.85

Tested by 1

test_encode_decodeMethod · 0.72