Browse Source

psbt: always include full prev tx (#6198)

* enable streaming full UTXOs for all types of inputs

Co-authored-by: SomberNight <somber.night@protonmail.com>
master
matejcik 4 years ago
committed by GitHub
parent
commit
e058ee2957
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      electrum/plugins/trezor/trezor.py
  2. 7
      electrum/transaction.py
  3. 19
      electrum/wallet.py

4
electrum/plugins/trezor/trezor.py

@ -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)

7
electrum/transaction.py

@ -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:

19
electrum/wallet.py

@ -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],

Loading…
Cancel
Save