Browse Source

wallet: only select mature coins by default

this is a regression from #5721

Removed the `TxInput.is_coinbase` method as I think it is a confusing API,
instead we now have `TxInput.is_coinbase_input` and `TxInput.is_coinbase_output`.

related #5872
hard-fail-on-bad-server-string
SomberNight 5 years ago
parent
commit
d2f132738a
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 13
      electrum/address_synchronizer.py
  2. 2
      electrum/gui/qt/transaction_dialog.py
  3. 2
      electrum/json_db.py
  4. 2
      electrum/plugins/digitalbitbox/digitalbitbox.py
  5. 2
      electrum/plugins/keepkey/keepkey.py
  6. 2
      electrum/plugins/ledger/ledger.py
  7. 2
      electrum/plugins/safe_t/safe_t.py
  8. 2
      electrum/plugins/trezor/trezor.py
  9. 4
      electrum/plugins/trustedcoin/legacy_tx_format.py
  10. 29
      electrum/transaction.py

13
electrum/address_synchronizer.py

@ -194,7 +194,7 @@ class AddressSynchronizer(Logger):
conflicting_txns = set()
with self.transaction_lock:
for txin in tx.inputs():
if txin.is_coinbase():
if txin.is_coinbase_input():
continue
prevout_hash = txin.prevout.txid.hex()
prevout_n = txin.prevout.out_idx
@ -228,7 +228,7 @@ class AddressSynchronizer(Logger):
# BUT we track is_mine inputs in a txn, and during subsequent calls
# of add_transaction tx, we might learn of more-and-more inputs of
# being is_mine, as we roll the gap_limit forward
is_coinbase = tx.inputs()[0].is_coinbase()
is_coinbase = tx.inputs()[0].is_coinbase_input()
tx_height = self.get_tx_height(tx_hash).height
if not allow_unrelated:
# note that during sync, if the transactions are not properly sorted,
@ -279,7 +279,7 @@ class AddressSynchronizer(Logger):
self._get_addr_balance_cache.pop(addr, None) # invalidate cache
return
for txi in tx.inputs():
if txi.is_coinbase():
if txi.is_coinbase_input():
continue
prevout_hash = txi.prevout.txid.hex()
prevout_n = txi.prevout.out_idx
@ -314,7 +314,7 @@ class AddressSynchronizer(Logger):
if tx is not None:
# if we have the tx, this branch is faster
for txin in tx.inputs():
if txin.is_coinbase():
if txin.is_coinbase_input():
continue
prevout_hash = txin.prevout.txid.hex()
prevout_n = txin.prevout.out_idx
@ -758,7 +758,8 @@ class AddressSynchronizer(Logger):
for prevout_str, v in coins.items():
tx_height, value, is_cb = v
prevout = TxOutpoint.from_str(prevout_str)
utxo = PartialTxInput(prevout=prevout)
utxo = PartialTxInput(prevout=prevout,
is_coinbase_output=is_cb)
utxo._trusted_address = address
utxo._trusted_value_sats = value
utxo.block_height = tx_height
@ -825,7 +826,7 @@ class AddressSynchronizer(Logger):
continue
if nonlocal_only and utxo.block_height == TX_HEIGHT_LOCAL:
continue
if (mature_only and utxo.prevout.is_coinbase()
if (mature_only and utxo.is_coinbase_output()
and utxo.block_height + COINBASE_MATURITY > mempool_height):
continue
coins.append(utxo)

2
electrum/gui/qt/transaction_dialog.py

@ -480,7 +480,7 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
i_text.setReadOnly(True)
cursor = i_text.textCursor()
for txin in self.tx.inputs():
if txin.is_coinbase():
if txin.is_coinbase_input():
cursor.insertText('coinbase')
else:
prevout_hash = txin.prevout.txid.hex()

2
electrum/json_db.py

@ -424,7 +424,7 @@ class JsonDB(Logger):
for txid, raw_tx in transactions.items():
tx = Transaction(raw_tx)
for txin in tx.inputs():
if txin.is_coinbase():
if txin.is_coinbase_input():
continue
prevout_hash = txin.prevout.txid.hex()
prevout_n = txin.prevout.out_idx

2
electrum/plugins/digitalbitbox/digitalbitbox.py

@ -539,7 +539,7 @@ class DigitalBitbox_KeyStore(Hardware_KeyStore):
# Build hasharray from inputs
for i, txin in enumerate(tx.inputs()):
if txin.is_coinbase():
if txin.is_coinbase_input():
self.give_error("Coinbase not supported") # should never happen
if txin.script_type != 'p2pkh':

2
electrum/plugins/keepkey/keepkey.py

@ -364,7 +364,7 @@ class KeepKeyPlugin(HW_PluginBase):
inputs = []
for txin in tx.inputs():
txinputtype = self.types.TxInputType()
if txin.is_coinbase():
if txin.is_coinbase_input():
prev_hash = b"\x00"*32
prev_index = 0xffffffff # signed int -1
else:

2
electrum/plugins/ledger/ledger.py

@ -330,7 +330,7 @@ class Ledger_KeyStore(Hardware_KeyStore):
# Fetch inputs of the transaction to sign
for txin in tx.inputs():
if txin.is_coinbase():
if txin.is_coinbase_input():
self.give_error("Coinbase not supported") # should never happen
if txin.script_type in ['p2sh']:

2
electrum/plugins/safe_t/safe_t.py

@ -338,7 +338,7 @@ class SafeTPlugin(HW_PluginBase):
inputs = []
for txin in tx.inputs():
txinputtype = self.types.TxInputType()
if txin.is_coinbase():
if txin.is_coinbase_input():
prev_hash = b"\x00"*32
prev_index = 0xffffffff # signed int -1
else:

2
electrum/plugins/trezor/trezor.py

@ -361,7 +361,7 @@ class TrezorPlugin(HW_PluginBase):
inputs = []
for txin in tx.inputs():
txinputtype = TxInputType()
if txin.is_coinbase():
if txin.is_coinbase_input():
prev_hash = b"\x00"*32
prev_index = 0xffffffff # signed int -1
else:

4
electrum/plugins/trustedcoin/legacy_tx_format.py

@ -38,7 +38,7 @@ def serialize_tx_in_legacy_format(tx: PartialTransaction, *, wallet: Multisig_Wa
tx = copy.deepcopy(tx)
def get_siglist(txin: 'PartialTxInput', *, estimate_size=False):
if txin.prevout.is_coinbase():
if txin.is_coinbase_input():
return [], []
if estimate_size:
try:
@ -80,7 +80,7 @@ def serialize_tx_in_legacy_format(tx: PartialTransaction, *, wallet: Multisig_Wa
assert estimate_size is False
if txin.witness is not None:
return txin.witness.hex()
if txin.prevout.is_coinbase():
if txin.is_coinbase_input():
return ''
assert isinstance(txin, PartialTxInput)
if not self.is_segwit_input(txin):

29
electrum/transaction.py

@ -192,20 +192,30 @@ class TxInput:
script_sig: Optional[bytes]
nsequence: int
witness: Optional[bytes]
_is_coinbase_output: bool
def __init__(self, *,
prevout: TxOutpoint,
script_sig: bytes = None,
nsequence: int = 0xffffffff - 1,
witness: bytes = None):
witness: bytes = None,
is_coinbase_output: bool = False):
self.prevout = prevout
self.script_sig = script_sig
self.nsequence = nsequence
self.witness = witness
self._is_coinbase_output = is_coinbase_output
def is_coinbase(self) -> bool:
def is_coinbase_input(self) -> bool:
"""Whether this is the input of a coinbase tx."""
return self.prevout.is_coinbase()
def is_coinbase_output(self) -> bool:
"""Whether the coin being spent is an output of a coinbase tx.
This matters for coin maturity.
"""
return self._is_coinbase_output
def value_sats(self) -> Optional[int]:
return None
@ -213,7 +223,7 @@ class TxInput:
d = {
'prevout_hash': self.prevout.txid.hex(),
'prevout_n': self.prevout.out_idx,
'coinbase': self.is_coinbase(),
'coinbase': self.is_coinbase_output(),
'nsequence': self.nsequence,
}
if self.script_sig is not None:
@ -550,7 +560,7 @@ class Transaction:
@classmethod
def get_siglist(self, txin: 'PartialTxInput', *, estimate_size=False):
if txin.prevout.is_coinbase():
if txin.is_coinbase_input():
return [], []
if estimate_size:
@ -579,7 +589,7 @@ class Transaction:
def serialize_witness(cls, txin: TxInput, *, estimate_size=False) -> str:
if txin.witness is not None:
return txin.witness.hex()
if txin.prevout.is_coinbase():
if txin.is_coinbase_input():
return ''
assert isinstance(txin, PartialTxInput)
@ -643,7 +653,7 @@ class Transaction:
def input_script(self, txin: TxInput, *, estimate_size=False) -> str:
if txin.script_sig is not None:
return txin.script_sig.hex()
if txin.prevout.is_coinbase():
if txin.is_coinbase_input():
return ''
assert isinstance(txin, PartialTxInput)
@ -1090,7 +1100,8 @@ class PartialTxInput(TxInput, PSBTSection):
res = PartialTxInput(prevout=txin.prevout,
script_sig=None if strip_witness else txin.script_sig,
nsequence=txin.nsequence,
witness=None if strip_witness else txin.witness)
witness=None if strip_witness else txin.witness,
is_coinbase_output=txin.is_coinbase_output())
return res
def validate_data(self, *, for_signing=False) -> None:
@ -1243,7 +1254,7 @@ class PartialTxInput(TxInput, PSBTSection):
def is_complete(self) -> bool:
if self.script_sig is not None and self.witness is not None:
return True
if self.prevout.is_coinbase():
if self.is_coinbase_input():
return True
if self.script_sig is not None and not Transaction.is_segwit_input(self):
return True
@ -1750,7 +1761,7 @@ class PartialTransaction(Transaction):
s = 0 # "num Sigs we have"
r = 0 # "Required"
for txin in self.inputs():
if txin.prevout.is_coinbase():
if txin.is_coinbase_input():
continue
signatures = list(txin.part_sigs.values())
s += len(signatures)

Loading…
Cancel
Save