Skip to content

Commit 8e47689

Browse files
committed
Add P2SHBitcoinAddress.from_redeemScript()
1 parent e3b9035 commit 8e47689

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

bitcoin/tests/test_wallet.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ def T(str_addr, expected_scriptPubKey_hexbytes):
114114
T('1111111111111111111114oLvT2',
115115
'76a914000000000000000000000000000000000000000088ac')
116116

117+
class Test_P2SHBitcoinAddress(unittest.TestCase):
118+
def test_from_redeemScript(self):
119+
addr = P2SHBitcoinAddress.from_redeemScript(CScript())
120+
self.assertEqual(str(addr), '3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy')
121+
117122
class Test_P2PKHBitcoinAddress(unittest.TestCase):
118123
def test_from_non_canonical_scriptPubKey(self):
119124
def T(hex_scriptpubkey, expected_str_address):

bitcoin/wallet.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ def from_bytes(cls, data, nVersion=None):
8787

8888
return super(P2SHBitcoinAddress, cls).from_bytes(data, nVersion)
8989

90+
@classmethod
91+
def from_redeemScript(cls, redeemScript):
92+
"""Convert a redeemScript to a P2SH address
93+
94+
Convenience function: equivalent to P2SHBitcoinAddress.from_scriptPubKey(redeemScript.to_p2sh_scriptPubKey())
95+
"""
96+
return cls.from_scriptPubKey(redeemScript.to_p2sh_scriptPubKey())
97+
9098
@classmethod
9199
def from_scriptPubKey(cls, scriptPubKey):
92100
"""Convert a scriptPubKey to a P2SH address

0 commit comments

Comments
 (0)