Skip to content

Commit

Permalink
[ADD] witness type to new_key method
Browse files Browse the repository at this point in the history
  • Loading branch information
mccwdev committed Oct 1, 2023
1 parent dca94d1 commit 9e6a1d9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions bitcoinlib/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ def _new_key_multisig(self, public_keys, name, account_id, change, cosigner_id,
self._commit()
return self.key(multisig_key.id)

def new_key(self, name='', account_id=None, change=0, cosigner_id=None, network=None):
def new_key(self, name='', account_id=None, change=0, cosigner_id=None, witness_type=None, network=None):
"""
Create a new HD Key derived from this wallet's masterkey. An account will be created for this wallet
with index 0 if there is no account defined yet.
Expand Down Expand Up @@ -2090,7 +2090,7 @@ def path_expand(self, path, level_offset=None, account_id=None, cosigner_id=0, a
witness_type=self.witness_type, network=network)

def key_for_path(self, path, level_offset=None, name=None, account_id=None, cosigner_id=None,
address_index=0, change=0, network=None, recreate=False):
address_index=0, change=0, witness_type=None, network=None, recreate=False):
"""
Return key for specified path. Derive all wallet keys in path if they not already exists
Expand Down Expand Up @@ -2135,6 +2135,7 @@ def key_for_path(self, path, level_offset=None, name=None, account_id=None, cosi
"""

network, account_id, _ = self._get_account_defaults(network, account_id)
witness_type = self.witness_type if not witness_type else witness_type
cosigner_id = cosigner_id if cosigner_id is not None else self.cosigner_id
level_offset_key = level_offset
if level_offset and self.main_key and level_offset > 0:
Expand All @@ -2145,7 +2146,7 @@ def key_for_path(self, path, level_offset=None, name=None, account_id=None, cosi
key_path = self.cosigner[cosigner_id].key_path
fullpath = path_expand(path, key_path, level_offset_key, account_id=account_id, cosigner_id=cosigner_id,
purpose=self.purpose, address_index=address_index, change=change,
witness_type=self.witness_type, network=network)
witness_type=witness_type, network=network)

if self.multisig and self.cosigner:
public_keys = []
Expand Down Expand Up @@ -2201,7 +2202,7 @@ def key_for_path(self, path, level_offset=None, name=None, account_id=None, cosi
key_name = key_name.replace("'", "").replace("_", " ")
nk = WalletKey.from_key(key=ck, name=key_name, wallet_id=self.wallet_id, account_id=account_id,
change=change, purpose=self.purpose, path=newpath, parent_id=parent_id,
encoding=self.encoding, witness_type=self.witness_type,
encoding=self.encoding, witness_type=witness_type,
cosigner_id=cosigner_id, network=network, session=self._session)
self._key_objects.update({nk.key_id: nk})
parent_id = nk.key_id
Expand Down

0 comments on commit 9e6a1d9

Please sign in to comment.