From 1035655151c3ac9f55112bc50f0c0d254583ca51 Mon Sep 17 00:00:00 2001 From: Lennart Jongeneel Date: Wed, 18 Oct 2023 22:27:38 +0200 Subject: [PATCH] [REF] Add witness_type to new_key_change --- bitcoinlib/wallets.py | 4 ++-- tests/test_wallets.py | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bitcoinlib/wallets.py b/bitcoinlib/wallets.py index 6e6ebfdf..53129058 100644 --- a/bitcoinlib/wallets.py +++ b/bitcoinlib/wallets.py @@ -1767,7 +1767,7 @@ def new_key(self, name='', account_id=None, change=0, cosigner_id=None, witness_ return self.key_for_path(req_path, name=name, account_id=account_id, witness_type=witness_type, network=network, cosigner_id=cosigner_id, address_index=address_index) - def new_key_change(self, name='', account_id=None, network=None): + def new_key_change(self, name='', account_id=None, witness_type=None, network=None): """ Create new key to receive change for a transaction. Calls :func:`new_key` method with change=1. @@ -1781,7 +1781,7 @@ def new_key_change(self, name='', account_id=None, network=None): :return WalletKey: """ - return self.new_key(name=name, account_id=account_id, network=network, change=1) + return self.new_key(name=name, account_id=account_id, witness_type=witness_type, network=network, change=1) def scan_key(self, key): """ diff --git a/tests/test_wallets.py b/tests/test_wallets.py index 54b1c2b8..c9b43a61 100644 --- a/tests/test_wallets.py +++ b/tests/test_wallets.py @@ -2706,4 +2706,12 @@ def test_wallet_mixed_witness_types_address(self): self.assertEqual(wmix.get_key(witness_type='legacy').address, wleg.get_key().address) self.assertEqual(wmix.get_key(witness_type='p2sh-segwit').address, wp2sh.get_key().address) self.assertEqual(wleg.get_key(witness_type='segwit').address, wmix.get_key().address) - self.assertEqual(wmix.new_account(witness_type='legacy').address, wleg.new_account().address) + wmix_legkey = wmix.new_account(witness_type='legacy').address + self.assertEqual(wmix_legkey, '18nM5LxmzaEcf4rv9pK7FLiAtfmH1VgVWD') + self.assertEqual(wmix_legkey, wleg.new_account().address) + self.assertEqual(wmix.new_key(witness_type='p2sh-segwit').address, wp2sh.new_key().address) + self.assertEqual(wmix.new_key_change(witness_type='p2sh-segwit').address, wp2sh.new_key_change().address) + self.assertEqual(wleg.get_key_change(witness_type='segwit').address, + wp2sh.get_key_change(witness_type='segwit').address) + self.assertEqual(wleg.new_key_change(witness_type='p2sh-segwit', account_id=111).address, + wp2sh.new_key_change(account_id=111).address)