Browse Source
bech32: around 5% speedup for bech32_decode
useful for lnaddr.lndecode
patch-4
SomberNight
4 years ago
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
1 changed files with
2 additions and
1 deletions
-
electrum/segwit_addr.py
|
|
@ -23,6 +23,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l" |
|
|
|
_CHARSET_INVERSE = {x: CHARSET.find(x) for x in CHARSET} |
|
|
|
|
|
|
|
|
|
|
|
def bech32_polymod(values): |
|
|
@ -72,7 +73,7 @@ def bech32_decode(bech, ignore_long_length=False): |
|
|
|
if not all(x in CHARSET for x in bech[pos+1:]): |
|
|
|
return (None, None) |
|
|
|
hrp = bech[:pos] |
|
|
|
data = [CHARSET.find(x) for x in bech[pos+1:]] |
|
|
|
data = [_CHARSET_INVERSE[x] for x in bech[pos+1:]] |
|
|
|
if not bech32_verify_checksum(hrp, data): |
|
|
|
return (None, None) |
|
|
|
return (hrp, data[:-6]) |
|
|
|