wallet: simplify bump_fee: rm txid arg
closes https://github.com/spesmilo/electrum/issues/8797
This commit is contained in:
@@ -817,7 +817,6 @@ class Commands:
|
|||||||
await tx.add_info_from_network(self.network)
|
await tx.add_info_from_network(self.network)
|
||||||
new_tx = wallet.bump_fee(
|
new_tx = wallet.bump_fee(
|
||||||
tx=tx,
|
tx=tx,
|
||||||
txid=tx.txid(),
|
|
||||||
coins=coins,
|
coins=coins,
|
||||||
strategy=BumpFeeStrategy.DECREASE_PAYMENT if decrease_payment else BumpFeeStrategy.PRESERVE_PAYMENT,
|
strategy=BumpFeeStrategy.DECREASE_PAYMENT if decrease_payment else BumpFeeStrategy.PRESERVE_PAYMENT,
|
||||||
new_fee_rate=new_fee_rate)
|
new_fee_rate=new_fee_rate)
|
||||||
|
|||||||
@@ -543,7 +543,7 @@ class QETxRbfFeeBumper(TxFeeSlider, TxMonMixin):
|
|||||||
self._orig_tx = self._wallet.wallet.db.get_transaction(self._txid)
|
self._orig_tx = self._wallet.wallet.db.get_transaction(self._txid)
|
||||||
assert self._orig_tx
|
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._bump_methods_available = [{'value': strat.name, 'text': strat.text()} for strat in strategies]
|
||||||
self.bumpMethodsAvailableChanged.emit()
|
self.bumpMethodsAvailableChanged.emit()
|
||||||
self.bumpMethod = strategies[def_strat_idx].name
|
self.bumpMethod = strategies[def_strat_idx].name
|
||||||
@@ -581,7 +581,6 @@ class QETxRbfFeeBumper(TxFeeSlider, TxMonMixin):
|
|||||||
try:
|
try:
|
||||||
self._tx = self._wallet.wallet.bump_fee(
|
self._tx = self._wallet.wallet.bump_fee(
|
||||||
tx=self._orig_tx,
|
tx=self._orig_tx,
|
||||||
txid=self._txid,
|
|
||||||
new_fee_rate=new_fee_rate,
|
new_fee_rate=new_fee_rate,
|
||||||
strategy=BumpFeeStrategy[self._bump_method],
|
strategy=BumpFeeStrategy[self._bump_method],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2633,21 +2633,19 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
|||||||
self.show_transaction(new_tx)
|
self.show_transaction(new_tx)
|
||||||
|
|
||||||
def bump_fee_dialog(self, tx: Transaction):
|
def bump_fee_dialog(self, tx: Transaction):
|
||||||
txid = tx.txid()
|
|
||||||
if not isinstance(tx, PartialTransaction):
|
if not isinstance(tx, PartialTransaction):
|
||||||
tx = PartialTransaction.from_tx(tx)
|
tx = PartialTransaction.from_tx(tx)
|
||||||
if not tx.add_info_from_wallet_and_network(wallet=self.wallet, show_error=self.show_error):
|
if not tx.add_info_from_wallet_and_network(wallet=self.wallet, show_error=self.show_error):
|
||||||
return
|
return
|
||||||
d = BumpFeeDialog(main_window=self, tx=tx, txid=txid)
|
d = BumpFeeDialog(main_window=self, tx=tx)
|
||||||
d.run()
|
d.run()
|
||||||
|
|
||||||
def dscancel_dialog(self, tx: Transaction):
|
def dscancel_dialog(self, tx: Transaction):
|
||||||
txid = tx.txid()
|
|
||||||
if not isinstance(tx, PartialTransaction):
|
if not isinstance(tx, PartialTransaction):
|
||||||
tx = PartialTransaction.from_tx(tx)
|
tx = PartialTransaction.from_tx(tx)
|
||||||
if not tx.add_info_from_wallet_and_network(wallet=self.wallet, show_error=self.show_error):
|
if not tx.add_info_from_wallet_and_network(wallet=self.wallet, show_error=self.show_error):
|
||||||
return
|
return
|
||||||
d = DSCancelDialog(main_window=self, tx=tx, txid=txid)
|
d = DSCancelDialog(main_window=self, tx=tx)
|
||||||
d.run()
|
d.run()
|
||||||
|
|
||||||
def save_transaction_into_wallet(self, tx: Transaction):
|
def save_transaction_into_wallet(self, tx: Transaction):
|
||||||
|
|||||||
@@ -30,13 +30,10 @@ class _BaseRBFDialog(TxEditor):
|
|||||||
*,
|
*,
|
||||||
main_window: 'ElectrumWindow',
|
main_window: 'ElectrumWindow',
|
||||||
tx: PartialTransaction,
|
tx: PartialTransaction,
|
||||||
txid: str,
|
|
||||||
title: str):
|
title: str):
|
||||||
|
|
||||||
self.wallet = main_window.wallet
|
self.wallet = main_window.wallet
|
||||||
self.old_tx = tx
|
self.old_tx = tx
|
||||||
assert txid
|
|
||||||
self.old_txid = txid
|
|
||||||
self.message = ''
|
self.message = ''
|
||||||
|
|
||||||
self.old_fee = self.old_tx.get_fee()
|
self.old_fee = self.old_tx.get_fee()
|
||||||
@@ -58,7 +55,7 @@ class _BaseRBFDialog(TxEditor):
|
|||||||
def create_grid(self):
|
def create_grid(self):
|
||||||
self.method_label = QLabel(_('Method') + ':')
|
self.method_label = QLabel(_('Method') + ':')
|
||||||
self.method_combo = QComboBox()
|
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.addItems([strat.text() for strat in self._strategies])
|
||||||
self.method_combo.setCurrentIndex(def_strat_idx)
|
self.method_combo.setCurrentIndex(def_strat_idx)
|
||||||
self.method_combo.currentIndexChanged.connect(self.trigger_update)
|
self.method_combo.currentIndexChanged.connect(self.trigger_update)
|
||||||
@@ -140,18 +137,16 @@ class BumpFeeDialog(_BaseRBFDialog):
|
|||||||
*,
|
*,
|
||||||
main_window: 'ElectrumWindow',
|
main_window: 'ElectrumWindow',
|
||||||
tx: PartialTransaction,
|
tx: PartialTransaction,
|
||||||
txid: str):
|
):
|
||||||
_BaseRBFDialog.__init__(
|
_BaseRBFDialog.__init__(
|
||||||
self,
|
self,
|
||||||
main_window=main_window,
|
main_window=main_window,
|
||||||
tx=tx,
|
tx=tx,
|
||||||
txid=txid,
|
|
||||||
title=_('Bump Fee'))
|
title=_('Bump Fee'))
|
||||||
|
|
||||||
def rbf_func(self, fee_rate, *, confirmed_only=False):
|
def rbf_func(self, fee_rate, *, confirmed_only=False):
|
||||||
return self.wallet.bump_fee(
|
return self.wallet.bump_fee(
|
||||||
tx=self.old_tx,
|
tx=self.old_tx,
|
||||||
txid=self.old_txid,
|
|
||||||
new_fee_rate=fee_rate,
|
new_fee_rate=fee_rate,
|
||||||
coins=self.main_window.get_coins(nonlocal_only=True, confirmed_only=confirmed_only),
|
coins=self.main_window.get_coins(nonlocal_only=True, confirmed_only=confirmed_only),
|
||||||
strategy=self._strategies[self.method_combo.currentIndex()],
|
strategy=self._strategies[self.method_combo.currentIndex()],
|
||||||
@@ -169,12 +164,11 @@ class DSCancelDialog(_BaseRBFDialog):
|
|||||||
*,
|
*,
|
||||||
main_window: 'ElectrumWindow',
|
main_window: 'ElectrumWindow',
|
||||||
tx: PartialTransaction,
|
tx: PartialTransaction,
|
||||||
txid: str):
|
):
|
||||||
_BaseRBFDialog.__init__(
|
_BaseRBFDialog.__init__(
|
||||||
self,
|
self,
|
||||||
main_window=main_window,
|
main_window=main_window,
|
||||||
tx=tx,
|
tx=tx,
|
||||||
txid=txid,
|
|
||||||
title=_('Cancel transaction'))
|
title=_('Cancel transaction'))
|
||||||
self.method_label.setVisible(False)
|
self.method_label.setVisible(False)
|
||||||
self.method_combo.setVisible(False)
|
self.method_combo.setVisible(False)
|
||||||
|
|||||||
@@ -1243,7 +1243,9 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
def export_invoices(self, path):
|
def export_invoices(self, path):
|
||||||
write_json_file(path, list(self._invoices.values()))
|
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())
|
invoice_keys = self._invoices_from_txid_map.get(tx_hash, set())
|
||||||
invoices = [self.get_invoice(key) for key in invoice_keys]
|
invoices = [self.get_invoice(key) for key in invoice_keys]
|
||||||
invoices = [inv for inv in invoices if inv] # filter out None
|
invoices = [inv for inv in invoices if inv] # filter out None
|
||||||
@@ -2042,15 +2044,11 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
tx: Transaction,
|
tx: Transaction,
|
||||||
txid: str = None,
|
|
||||||
) -> Tuple[Sequence[BumpFeeStrategy], int]:
|
) -> Tuple[Sequence[BumpFeeStrategy], int]:
|
||||||
"""Returns tuple(list of available strategies, idx of recommended option among those)."""
|
"""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()
|
all_strats = BumpFeeStrategy.all()
|
||||||
# are we paying max?
|
# 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 len(invoices) == 1 and len(invoices[0].outputs) == 1:
|
||||||
if invoices[0].outputs[0].value == '!':
|
if invoices[0].outputs[0].value == '!':
|
||||||
return all_strats, all_strats.index(BumpFeeStrategy.DECREASE_PAYMENT)
|
return all_strats, all_strats.index(BumpFeeStrategy.DECREASE_PAYMENT)
|
||||||
@@ -2064,7 +2062,6 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
tx: Transaction,
|
tx: Transaction,
|
||||||
txid: str = None,
|
|
||||||
new_fee_rate: Union[int, float, Decimal],
|
new_fee_rate: Union[int, float, Decimal],
|
||||||
coins: Sequence[PartialTxInput] = None,
|
coins: Sequence[PartialTxInput] = None,
|
||||||
strategy: BumpFeeStrategy = BumpFeeStrategy.PRESERVE_PAYMENT,
|
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().
|
note: it is the caller's responsibility to have already called tx.add_info_from_network().
|
||||||
Without that, all txins must be ismine.
|
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):
|
if not isinstance(tx, PartialTransaction):
|
||||||
tx = PartialTransaction.from_tx(tx)
|
tx = PartialTransaction.from_tx(tx)
|
||||||
assert isinstance(tx, PartialTransaction)
|
assert isinstance(tx, PartialTransaction)
|
||||||
@@ -2102,7 +2096,6 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
try:
|
try:
|
||||||
tx_new = self._bump_fee_through_coinchooser(
|
tx_new = self._bump_fee_through_coinchooser(
|
||||||
tx=tx,
|
tx=tx,
|
||||||
txid=txid,
|
|
||||||
new_fee_rate=new_fee_rate,
|
new_fee_rate=new_fee_rate,
|
||||||
coins=coins,
|
coins=coins,
|
||||||
)
|
)
|
||||||
@@ -2131,7 +2124,6 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
tx: PartialTransaction,
|
tx: PartialTransaction,
|
||||||
txid: str,
|
|
||||||
new_fee_rate: Union[int, Decimal],
|
new_fee_rate: Union[int, Decimal],
|
||||||
coins: Sequence[PartialTxInput] = None,
|
coins: Sequence[PartialTxInput] = None,
|
||||||
) -> PartialTransaction:
|
) -> PartialTransaction:
|
||||||
@@ -2141,7 +2133,6 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
- keeps all not is_mine outputs,
|
- keeps all not is_mine outputs,
|
||||||
- allows adding new inputs
|
- allows adding new inputs
|
||||||
"""
|
"""
|
||||||
assert txid
|
|
||||||
tx = copy.deepcopy(tx)
|
tx = copy.deepcopy(tx)
|
||||||
tx.add_info_from_wallet(self)
|
tx.add_info_from_wallet(self)
|
||||||
assert tx.get_fee() is not None
|
assert tx.get_fee() is not None
|
||||||
@@ -2170,7 +2161,8 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
if coins is None:
|
if coins is None:
|
||||||
coins = self.get_spendable_coins(None)
|
coins = self.get_spendable_coins(None)
|
||||||
# make sure we don't try to spend output from the tx-to-be-replaced:
|
# 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:
|
for item in coins:
|
||||||
self.add_input_info(item)
|
self.add_input_info(item)
|
||||||
def fee_estimator(size):
|
def fee_estimator(size):
|
||||||
|
|||||||
Reference in New Issue
Block a user