Skip to content

Commit

Permalink
[FIX] Sending from wallets with multiple witness types
Browse files Browse the repository at this point in the history
  • Loading branch information
mccwdev committed Nov 8, 2023
1 parent 28a5e5c commit 1566bd2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions bitcoinlib/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3613,12 +3613,13 @@ def transaction_create(self, output_arr, input_arr=None, input_key_id=None, acco
amount_total_input += utxo.value
inp_keys, key = self._objects_by_key_id(utxo.key_id)
multisig = False if isinstance(inp_keys, list) and len(inp_keys) < 2 else True
unlock_script_type = get_unlocking_script_type(utxo.script_type, self.witness_type, multisig=multisig)
unlock_script_type = get_unlocking_script_type(utxo.script_type, utxo.key.witness_type,
multisig=multisig)
transaction.add_input(utxo.transaction.txid, utxo.output_n, keys=inp_keys,
script_type=unlock_script_type, sigs_required=self.multisig_n_required,
sort=self.sort_keys, compressed=key.compressed, value=utxo.value,
address=utxo.key.address, sequence=sequence,
key_path=utxo.key.path, witness_type=self.witness_type)
key_path=utxo.key.path, witness_type=utxo.key.witness_type)
# FIXME: Missing locktime_cltv=locktime_cltv, locktime_csv=locktime_csv (?)
else:
for inp in input_arr:
Expand All @@ -3639,6 +3640,7 @@ def transaction_create(self, output_arr, input_arr=None, input_key_id=None, acco
sequence = inp.sequence
locktime_cltv = inp.locktime_cltv
locktime_csv = inp.locktime_csv
witness_type = inp.witness_type
# elif isinstance(inp, DbTransactionOutput):
# prev_txid = inp.transaction.txid
# output_n = inp.output_n
Expand All @@ -3657,6 +3659,7 @@ def transaction_create(self, output_arr, input_arr=None, input_key_id=None, acco
signatures = None if len(inp) <= 4 else inp[4]
unlocking_script = b'' if len(inp) <= 5 else inp[5]
address = '' if len(inp) <= 6 else inp[6]
witness_type = self.witness_type
# Get key_ids, value from Db if not specified
if not (key_id and value and unlocking_script_type):
if not isinstance(output_n, TYPE_INT):
Expand All @@ -3670,7 +3673,7 @@ def transaction_create(self, output_arr, input_arr=None, input_key_id=None, acco
value = inp_utxo.value
address = inp_utxo.key.address
unlocking_script_type = get_unlocking_script_type(inp_utxo.script_type, multisig=self.multisig)
# witness_type = inp_utxo.witness_type
witness_type = inp_utxo.key.witness_type
else:
_logger.info("UTXO %s not found in this wallet. Please update UTXO's if this is not an "
"offline wallet" % to_hexstring(prev_txid))
Expand All @@ -3691,7 +3694,7 @@ def transaction_create(self, output_arr, input_arr=None, input_key_id=None, acco
unlocking_script=unlocking_script, address=address,
unlocking_script_unsigned=unlocking_script_unsigned,
sequence=sequence, locktime_cltv=locktime_cltv, locktime_csv=locktime_csv,
witness_type=self.witness_type, key_path=key.path)
witness_type=witness_type, key_path=key.path)
# Calculate fees
transaction.fee = fee
fee_per_output = None
Expand Down

0 comments on commit 1566bd2

Please sign in to comment.