tpsbt: always include full prev tx (#6198) - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit e058ee29575ddd69afeefe4a0319360163750c53 DIR parent 1978bba91500022d12db4ad885794a7595cac25f HTML Author: matejcik <ja@matejcik.cz> Date: Wed, 3 Jun 2020 20:03:12 +0200 psbt: always include full prev tx (#6198) * enable streaming full UTXOs for all types of inputs Co-authored-by: SomberNight <somber.night@protonmail.com> Diffstat: M electrum/plugins/trezor/trezor.py | 4 ++-- M electrum/transaction.py | 7 +++---- M electrum/wallet.py | 19 +++---------------- 3 files changed, 8 insertions(+), 22 deletions(-) --- DIR diff --git a/electrum/plugins/trezor/trezor.py b/electrum/plugins/trezor/trezor.py t@@ -88,8 +88,8 @@ class TrezorKeyStore(Hardware_KeyStore): 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) DIR diff --git a/electrum/transaction.py b/electrum/transaction.py t@@ -1381,11 +1381,10 @@ class PartialTxInput(TxInput, PSBTSection): 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: DIR diff --git a/electrum/wallet.py b/electrum/wallet.py t@@ -1400,22 +1400,9 @@ class Abstract_Wallet(AddressSynchronizer, ABC): 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],