Skip to content

Commit

Permalink
[REF] Add witness_type to new_key_change
Browse files Browse the repository at this point in the history
  • Loading branch information
mccwdev committed Oct 18, 2023
1 parent bfa9c5d commit 1035655
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions bitcoinlib/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
"""
Expand Down
10 changes: 9 additions & 1 deletion tests/test_wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 1035655

Please sign in to comment.