Skip to content

Commit

Permalink
psbt: always include full prev tx (#6198)
Browse files Browse the repository at this point in the history
* enable streaming full UTXOs for all types of inputs

Co-authored-by: SomberNight <[email protected]>
  • Loading branch information
matejcik and SomberNight authored Jun 3, 2020
1 parent 1978bba commit e058ee2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
4 changes: 2 additions & 2 deletions electrum/plugins/trezor/trezor.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def sign_transaction(self, tx, password):
prev_tx = {}
for txin in tx.inputs():
tx_hash = txin.prevout.txid.hex()
if txin.utxo is None and not Transaction.is_segwit_input(txin):
raise UserFacingException(_('Missing previous tx for legacy input.'))
if txin.utxo is None:
raise UserFacingException(_('Missing previous tx.'))
prev_tx[tx_hash] = txin.utxo

self.plugin.sign_transaction(self, tx, prev_tx)
Expand Down
7 changes: 3 additions & 4 deletions electrum/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,11 +1381,10 @@ def combine_with_other_txin(self, other_txin: 'TxInput') -> None:
self.finalize()

def ensure_there_is_only_one_utxo(self):
# we prefer having the full previous tx, even for segwit inputs. see #6198
# for witness v1, witness_utxo will be enough though
if self.utxo is not None and self.witness_utxo is not None:
if Transaction.is_segwit_input(self):
self.utxo = None
else:
self.witness_utxo = None
self.witness_utxo = None

def convert_utxo_to_witness_utxo(self) -> None:
if self.utxo:
Expand Down
19 changes: 3 additions & 16 deletions electrum/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,22 +1400,9 @@ def _add_txinout_derivation_info(self, txinout: Union[PartialTxInput, PartialTxO
pass # implemented by subclasses

def _add_input_utxo_info(self, txin: PartialTxInput, address: str) -> None:
if Transaction.is_segwit_input(txin):
if txin.witness_utxo is None:
received, spent = self.get_addr_io(address)
item = received.get(txin.prevout.to_str())
if item:
txin_value = item[1]
txin.witness_utxo = TxOutput.from_address_and_value(address, txin_value)
else: # legacy input
if txin.utxo is None:
# note: for hw wallets, for legacy inputs, ignore_network_issues used to be False
txin.utxo = self.get_input_tx(txin.prevout.txid.hex(), ignore_network_issues=True)
# If there is a NON-WITNESS UTXO, but we know input is segwit, add a WITNESS UTXO, based on it.
# This could have happened if previously another wallet had put a NON-WITNESS UTXO for txin,
# as they did not know if it was segwit. This switch is needed to interop with bitcoin core.
if txin.utxo and Transaction.is_segwit_input(txin):
txin.convert_utxo_to_witness_utxo()
if txin.utxo is None:
# note: for hw wallets, for legacy inputs, ignore_network_issues used to be False
txin.utxo = self.get_input_tx(txin.prevout.txid.hex(), ignore_network_issues=True)
txin.ensure_there_is_only_one_utxo()

def _learn_derivation_path_for_address_from_txinout(self, txinout: Union[PartialTxInput, PartialTxOutput],
Expand Down

0 comments on commit e058ee2

Please sign in to comment.