Skip to content

Commit 01083b7

Browse files
Martino Salvettidgpv
authored andcommitted
Add BECH32_HRP in network parameters
1 parent dfaa0c2 commit 01083b7

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

bitcoin/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class MainParams(bitcoin.core.CoreMainParams):
3131
BASE58_PREFIXES = {'PUBKEY_ADDR':0,
3232
'SCRIPT_ADDR':5,
3333
'SECRET_KEY' :128}
34+
BECH32_HRP = 'bc'
3435

3536
class TestNetParams(bitcoin.core.CoreTestNetParams):
3637
MESSAGE_START = b'\x0b\x11\x09\x07'
@@ -43,6 +44,7 @@ class TestNetParams(bitcoin.core.CoreTestNetParams):
4344
BASE58_PREFIXES = {'PUBKEY_ADDR':111,
4445
'SCRIPT_ADDR':196,
4546
'SECRET_KEY' :239}
47+
BECH32_HRP = 'tb'
4648

4749
class RegTestParams(bitcoin.core.CoreRegTestParams):
4850
MESSAGE_START = b'\xfa\xbf\xb5\xda'
@@ -52,6 +54,7 @@ class RegTestParams(bitcoin.core.CoreRegTestParams):
5254
BASE58_PREFIXES = {'PUBKEY_ADDR':111,
5355
'SCRIPT_ADDR':196,
5456
'SECRET_KEY' :239}
57+
BECH32_HRP = 'tb'
5558

5659
"""Master global setting for what chain params we're using.
5760

bitcoin/bech32.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
_bord = lambda x: x
2121

2222
from bitcoin.segwit_addr import encode, decode
23+
import bitcoin
2324

2425
class Bech32Error(Exception):
2526
pass
@@ -34,7 +35,7 @@ class CBech32Data(bytes):
3435
"""
3536
def __new__(cls, s):
3637
"""from bech32 addr to """
37-
witver, data = decode('bc', s) # TODO: bc from bitcoin.params
38+
witver, data = decode(bitcoin.params.BECH32_HRP, s)
3839
if witver is None and data is None:
3940
raise Bech32Error('Bech32 decoding error')
4041

@@ -68,7 +69,7 @@ def to_bytes(self):
6869

6970
def __str__(self):
7071
"""Convert to string"""
71-
return encode('bc', self.witver, self) # TODO: bc from bitcoin.params
72+
return encode(bitcoin.params.BECH32_HRP, self.witver, self)
7273

7374
def __repr__(self):
7475
return '%s(%r)' % (self.__class__.__name__, str(self))

0 commit comments

Comments
 (0)