Skip to content

Commit 542ac35

Browse files
committed
Add python2 support to CBech32BitcoinAddress
1 parent e872989 commit 542ac35

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

bitcoin/wallet.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717

1818
from __future__ import absolute_import, division, print_function, unicode_literals
1919

20+
import array
2021
import sys
2122

2223
_bord = ord
24+
_tobytes = lambda x: array.array('B', x).tostring()
2325
if sys.version > '3':
2426
_bord = lambda x: x
27+
_tobytes = bytes
2528

2629
import bitcoin
2730
import bitcoin.base58
@@ -72,9 +75,11 @@ class CBech32BitcoinAddress(bitcoin.bech32.CBech32Data, CBitcoinAddress):
7275
@classmethod
7376
def from_bytes(cls, witver, witprog):
7477

75-
assert(witver == 0)
76-
77-
self = super(CBech32BitcoinAddress, cls).from_bytes(witver, witprog)
78+
assert witver == 0
79+
self = super(CBech32BitcoinAddress, cls).from_bytes(
80+
witver,
81+
_tobytes(witprog)
82+
)
7883

7984
if len(self) == 32:
8085
self.__class__ = P2WSHBitcoinAddress

0 commit comments

Comments
 (0)