Skip to content

Commit bb5879b

Browse files
mflaxmanMichael Flaxman
andauthored
parse_wshsortedmulti hotfix (#55)
* fix network parsing on mainnet * add test and bump version number Co-authored-by: Michael Flaxman <[email protected]>
1 parent fe09f87 commit bb5879b

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

buidl/hd.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -775,17 +775,17 @@ def parse_wshsortedmulti(output_record):
775775
f"Malformed threshold {quorum_m_int}-of-{quorum_n_int} (m must be less than n) in {output_record}"
776776
)
777777

778-
# Remove testnet from key records (can just return it once at the parent output record level)
778+
# Remove testnet from each key record (can just return it once at the parent output record level)
779779
# Confirm all key records are on the same network
780-
output_is_testnet = key_records[0]["is_testnet"]
781-
if not all(x.pop("is_testnet") for x in key_records):
780+
networks_list = [x.pop("is_testnet") for x in key_records]
781+
if len(set(networks_list)) != 1:
782782
raise ValueError(f"Multiple (conflicting) networks in pubkeys: {key_records}")
783783

784784
return {
785785
"quorum_m": quorum_m_int,
786786
"quorum_n": quorum_n_int,
787787
"key_records": key_records,
788-
"is_testnet": output_is_testnet,
788+
"is_testnet": networks_list[0],
789789
}
790790

791791

buidl/test/test_hd.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,3 +661,14 @@ def test_valid_p2wsh_sortedmulti(self):
661661

662662
receive_addrs = list(generate_wshsortedmulti_address(**kwargs, is_change=False))
663663
self.assertEqual(receive_addrs, expected_receive_addrs)
664+
665+
def test_invalid_p2wsh_sortedmulti(self):
666+
# Notice the mix of xpub and tpub
667+
output_record = """wsh(sortedmulti(1,[c7d0648a/48h/1h/0h/2h]tpubDEpefcgzY6ZyEV2uF4xcW2z8bZ3DNeWx9h2BcwcX973BHrmkQxJhpAXoSWZeHkmkiTtnUjfERsTDTVCcifW6po3PFR1JRjUUTJHvPpDqJhr/0/*,[12980eed/48h/1h/0h/2h]xpub6ENtkZb1q4JLHBocpPeoQj8xGsQ1Y7Jnkc3Vm43LyPaQ7BfzkDeF3fzxt78SBELXc2PUNHPuVEdTaukwNRqqc8xFKjVXfQ4FpN6eKqe6y9E/0/*))#tatkmj5q"""
668+
669+
with self.assertRaises(ValueError) as fail:
670+
parse_wshsortedmulti(output_record)
671+
672+
self.assertIn(
673+
"Multiple (conflicting) networks in pubkeys: ", str(fail.exception)
674+
)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="buidl",
8-
version="0.2.11",
8+
version="0.2.12",
99
author="Example Author",
1010
author_email="[email protected]",
1111
description="An easy-to-use and fully featured bitcoin library written in pure python (no dependencies).",

0 commit comments

Comments
 (0)