diff --git a/bitcoinlib/main.py b/bitcoinlib/main.py index 322e0626..d1172929 100644 --- a/bitcoinlib/main.py +++ b/bitcoinlib/main.py @@ -106,8 +106,23 @@ def get_encoding_from_witness(witness_type=None): def get_key_structure_data(witness_type, multisig=False, purpose=None, encoding=None): + """ + Get data from wallet key structure. Provide witness_type and multisig to determine key path, purpose (BIP44 + reference) and encoding. + + :param witness_type: Witness type used for transaction validation + :type witness_type: str + :param multisig: Multisig or single keys wallet, default is False: single key / 1-of-1 wallet + :type multisig: bool + :param purpose: Overrule purpose found in wallet structure. Do not use unless you known what you are doing. + :type purpose: int + :param encoding: Overrule encoding found in wallet structure. Do not use unless you known what you are doing. + :type encoding: str + + :return: (key_path, purpose, encoding) + """ if not witness_type: - return None, None, None + return None, purpose, encoding ks = [k for k in WALLET_KEY_STRUCTURES if k['witness_type'] == witness_type and k['multisig'] == multisig and k['purpose'] is not None] if len(ks) > 1: diff --git a/bitcoinlib/wallets.py b/bitcoinlib/wallets.py index f8267969..d4c46381 100644 --- a/bitcoinlib/wallets.py +++ b/bitcoinlib/wallets.py @@ -1263,16 +1263,6 @@ def create(cls, name, keys=None, owner='', network=None, account_id=0, purpose=0 key_path = ['m'] purpose = 0 else: - # ks = [k for k in WALLET_KEY_STRUCTURES if k['witness_type'] == witness_type and - # k['multisig'] == multisig and k['purpose'] is not None] - # if len(ks) > 1: - # raise WalletError("Please check definitions in WALLET_KEY_STRUCTURES. Multiple options found for " - # "witness_type - multisig combination") - # if ks and not purpose: - # purpose = ks[0]['purpose'] - # if ks and not encoding: - # encoding = ks[0]['encoding'] - # key_path = ks[0]['key_path'] key_path, purpose, encoding = get_key_structure_data(witness_type, multisig, purpose, encoding) else: if purpose is None: @@ -2132,6 +2122,8 @@ def key_for_path(self, path, level_offset=None, name=None, account_id=None, cosi :type address_index: int :param change: Change key = 1 or normal = 0, normally provided to 'path' argument :type change: int + :param witness_type: Use to create key with different witness_type + :type witness_type: str :param network: Network name. Leave empty for default network :type network: str :param recreate: Recreate key, even if already found in wallet. Can be used to update public key with private key info