Browse Source

wallet: simplify bump_fee: rm txid arg

closes https://github.com/spesmilo/electrum/issues/8797
master
SomberNight 2 years ago
parent
commit
49c3567d7d
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 1
      electrum/commands.py
  2. 3
      electrum/gui/qml/qetxfinalizer.py
  3. 6
      electrum/gui/qt/main_window.py
  4. 12
      electrum/gui/qt/rbf_dialog.py
  5. 20
      electrum/wallet.py

1
electrum/commands.py

@ -817,7 +817,6 @@ class Commands:
await tx.add_info_from_network(self.network)
new_tx = wallet.bump_fee(
tx=tx,
txid=tx.txid(),
coins=coins,
strategy=BumpFeeStrategy.DECREASE_PAYMENT if decrease_payment else BumpFeeStrategy.PRESERVE_PAYMENT,
new_fee_rate=new_fee_rate)

3
electrum/gui/qml/qetxfinalizer.py

@ -543,7 +543,7 @@ class QETxRbfFeeBumper(TxFeeSlider, TxMonMixin):
self._orig_tx = self._wallet.wallet.db.get_transaction(self._txid)
assert self._orig_tx
strategies, def_strat_idx = self._wallet.wallet.get_bumpfee_strategies_for_tx(tx=self._orig_tx, txid=self._txid)
strategies, def_strat_idx = self._wallet.wallet.get_bumpfee_strategies_for_tx(tx=self._orig_tx)
self._bump_methods_available = [{'value': strat.name, 'text': strat.text()} for strat in strategies]
self.bumpMethodsAvailableChanged.emit()
self.bumpMethod = strategies[def_strat_idx].name
@ -581,7 +581,6 @@ class QETxRbfFeeBumper(TxFeeSlider, TxMonMixin):
try:
self._tx = self._wallet.wallet.bump_fee(
tx=self._orig_tx,
txid=self._txid,
new_fee_rate=new_fee_rate,
strategy=BumpFeeStrategy[self._bump_method],
)

6
electrum/gui/qt/main_window.py

@ -2633,21 +2633,19 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
self.show_transaction(new_tx)
def bump_fee_dialog(self, tx: Transaction):
txid = tx.txid()
if not isinstance(tx, PartialTransaction):
tx = PartialTransaction.from_tx(tx)
if not tx.add_info_from_wallet_and_network(wallet=self.wallet, show_error=self.show_error):
return
d = BumpFeeDialog(main_window=self, tx=tx, txid=txid)
d = BumpFeeDialog(main_window=self, tx=tx)
d.run()
def dscancel_dialog(self, tx: Transaction):
txid = tx.txid()
if not isinstance(tx, PartialTransaction):
tx = PartialTransaction.from_tx(tx)
if not tx.add_info_from_wallet_and_network(wallet=self.wallet, show_error=self.show_error):
return
d = DSCancelDialog(main_window=self, tx=tx, txid=txid)
d = DSCancelDialog(main_window=self, tx=tx)
d.run()
def save_transaction_into_wallet(self, tx: Transaction):

12
electrum/gui/qt/rbf_dialog.py

@ -30,13 +30,10 @@ class _BaseRBFDialog(TxEditor):
*,
main_window: 'ElectrumWindow',
tx: PartialTransaction,
txid: str,
title: str):
self.wallet = main_window.wallet
self.old_tx = tx
assert txid
self.old_txid = txid
self.message = ''
self.old_fee = self.old_tx.get_fee()
@ -58,7 +55,7 @@ class _BaseRBFDialog(TxEditor):
def create_grid(self):
self.method_label = QLabel(_('Method') + ':')
self.method_combo = QComboBox()
self._strategies, def_strat_idx = self.wallet.get_bumpfee_strategies_for_tx(tx=self.old_tx, txid=self.old_txid)
self._strategies, def_strat_idx = self.wallet.get_bumpfee_strategies_for_tx(tx=self.old_tx)
self.method_combo.addItems([strat.text() for strat in self._strategies])
self.method_combo.setCurrentIndex(def_strat_idx)
self.method_combo.currentIndexChanged.connect(self.trigger_update)
@ -140,18 +137,16 @@ class BumpFeeDialog(_BaseRBFDialog):
*,
main_window: 'ElectrumWindow',
tx: PartialTransaction,
txid: str):
):
_BaseRBFDialog.__init__(
self,
main_window=main_window,
tx=tx,
txid=txid,
title=_('Bump Fee'))
def rbf_func(self, fee_rate, *, confirmed_only=False):
return self.wallet.bump_fee(
tx=self.old_tx,
txid=self.old_txid,
new_fee_rate=fee_rate,
coins=self.main_window.get_coins(nonlocal_only=True, confirmed_only=confirmed_only),
strategy=self._strategies[self.method_combo.currentIndex()],
@ -169,12 +164,11 @@ class DSCancelDialog(_BaseRBFDialog):
*,
main_window: 'ElectrumWindow',
tx: PartialTransaction,
txid: str):
):
_BaseRBFDialog.__init__(
self,
main_window=main_window,
tx=tx,
txid=txid,
title=_('Cancel transaction'))
self.method_label.setVisible(False)
self.method_combo.setVisible(False)

20
electrum/wallet.py

@ -1243,7 +1243,9 @@ class Abstract_Wallet(ABC, Logger, EventListener):
def export_invoices(self, path):
write_json_file(path, list(self._invoices.values()))
def get_relevant_invoices_for_tx(self, tx_hash) -> Sequence[Invoice]:
def get_relevant_invoices_for_tx(self, tx_hash: Optional[str]) -> Sequence[Invoice]:
if not tx_hash:
return []
invoice_keys = self._invoices_from_txid_map.get(tx_hash, set())
invoices = [self.get_invoice(key) for key in invoice_keys]
invoices = [inv for inv in invoices if inv] # filter out None
@ -2042,15 +2044,11 @@ class Abstract_Wallet(ABC, Logger, EventListener):
self,
*,
tx: Transaction,
txid: str = None,
) -> Tuple[Sequence[BumpFeeStrategy], int]:
"""Returns tuple(list of available strategies, idx of recommended option among those)."""
txid = txid or tx.txid()
assert txid
assert tx.txid() in (None, txid)
all_strats = BumpFeeStrategy.all()
# are we paying max?
invoices = self.get_relevant_invoices_for_tx(txid)
invoices = self.get_relevant_invoices_for_tx(tx.txid())
if len(invoices) == 1 and len(invoices[0].outputs) == 1:
if invoices[0].outputs[0].value == '!':
return all_strats, all_strats.index(BumpFeeStrategy.DECREASE_PAYMENT)
@ -2064,7 +2062,6 @@ class Abstract_Wallet(ABC, Logger, EventListener):
self,
*,
tx: Transaction,
txid: str = None,
new_fee_rate: Union[int, float, Decimal],
coins: Sequence[PartialTxInput] = None,
strategy: BumpFeeStrategy = BumpFeeStrategy.PRESERVE_PAYMENT,
@ -2076,9 +2073,6 @@ class Abstract_Wallet(ABC, Logger, EventListener):
note: it is the caller's responsibility to have already called tx.add_info_from_network().
Without that, all txins must be ismine.
"""
txid = txid or tx.txid()
assert txid
assert tx.txid() in (None, txid)
if not isinstance(tx, PartialTransaction):
tx = PartialTransaction.from_tx(tx)
assert isinstance(tx, PartialTransaction)
@ -2102,7 +2096,6 @@ class Abstract_Wallet(ABC, Logger, EventListener):
try:
tx_new = self._bump_fee_through_coinchooser(
tx=tx,
txid=txid,
new_fee_rate=new_fee_rate,
coins=coins,
)
@ -2131,7 +2124,6 @@ class Abstract_Wallet(ABC, Logger, EventListener):
self,
*,
tx: PartialTransaction,
txid: str,
new_fee_rate: Union[int, Decimal],
coins: Sequence[PartialTxInput] = None,
) -> PartialTransaction:
@ -2141,7 +2133,6 @@ class Abstract_Wallet(ABC, Logger, EventListener):
- keeps all not is_mine outputs,
- allows adding new inputs
"""
assert txid
tx = copy.deepcopy(tx)
tx.add_info_from_wallet(self)
assert tx.get_fee() is not None
@ -2170,7 +2161,8 @@ class Abstract_Wallet(ABC, Logger, EventListener):
if coins is None:
coins = self.get_spendable_coins(None)
# make sure we don't try to spend output from the tx-to-be-replaced:
coins = [c for c in coins if c.prevout.txid.hex() != txid]
coins = [c for c in coins
if c.prevout.txid.hex() not in self.adb.get_conflicting_transactions(tx, include_self=True)]
for item in coins:
self.add_input_info(item)
def fee_estimator(size):

Loading…
Cancel
Save