Skip to content

Commit cdfcf88

Browse files
committed
qml: make finalizer options a flag, allowing to enable/disable certain finalizer options
depending on the use-case
1 parent 2224250 commit cdfcf88

4 files changed

Lines changed: 51 additions & 9 deletions

File tree

electrum/gui/qml/components/ConfirmTxDialog.qml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ ElDialog {
1414
required property var satoshis // type: Amount
1515
property string address
1616
property string message
17-
property bool showOptions: true
1817
property alias amountLabelText: amountLabel.text
1918
property alias sendButtonText: sendButton.text
2019

@@ -152,7 +151,7 @@ ElDialog {
152151
Layout.columnSpan: 2
153152
labelText: qsTr('Options')
154153
color: Material.accentColor
155-
visible: showOptions
154+
visible: finalizer.txOptions
156155
}
157156

158157
DialogHighlightPane {
@@ -168,7 +167,9 @@ ElDialog {
168167
rowSpacing: 0
169168

170169
ElCheckBox {
170+
id: cb_multiple_change
171171
Layout.fillWidth: true
172+
visible: finalizer.txOptions & TxFinalizer.TxOptions.MULTIPLE_CHANGE
172173
text: qsTr('Use multiple change addresses')
173174
onCheckedChanged: {
174175
if (activeFocus) {
@@ -182,13 +183,16 @@ ElDialog {
182183
}
183184

184185
HelpButton {
186+
visible: cb_multiple_change.visible
185187
heading: qsTr('Use multiple change addresses')
186188
helptext: [qsTr('In some cases, use up to 3 change addresses in order to break up large coin amounts and obfuscate the recipient address.'),
187189
qsTr('This may result in higher transactions fees.')].join(' ')
188190
}
189191

190192
ElCheckBox {
193+
id: cb_output_rounding
191194
Layout.fillWidth: true
195+
visible: finalizer.txOptions & TxFinalizer.TxOptions.OUTPUT_ROUNDING
192196
text: Config.shortDescFor('WALLET_COIN_CHOOSER_OUTPUT_ROUNDING')
193197
onCheckedChanged: {
194198
if (activeFocus) {
@@ -202,14 +206,16 @@ ElDialog {
202206
}
203207

204208
HelpButton {
209+
visible: cb_output_rounding.visible
205210
heading: Config.shortDescFor('WALLET_COIN_CHOOSER_OUTPUT_ROUNDING')
206211
helptext: Config.longDescFor('WALLET_COIN_CHOOSER_OUTPUT_ROUNDING')
207212
}
208213

209214
ElCheckBox {
210215
id: cb_send_change_to_lightning
211216
Layout.fillWidth: true
212-
visible: Daemon.currentWallet.isLightning && Daemon.currentWallet.lightningCanReceive.satsInt > 0
217+
visible: finalizer.txOptions & TxFinalizer.TxOptions.SEND_CHANGE_TO_LIGHTNING
218+
&& Daemon.currentWallet.isLightning && Daemon.currentWallet.lightningCanReceive.satsInt > 0
213219
text: Config.shortDescFor('WALLET_SEND_CHANGE_TO_LIGHTNING')
214220
onCheckedChanged: {
215221
if (activeFocus) {
@@ -223,7 +229,7 @@ ElDialog {
223229
}
224230

225231
HelpButton {
226-
visible: Daemon.currentWallet.isLightning && Daemon.currentWallet.lightningCanReceive.satsInt > 0
232+
visible: cb_send_change_to_lightning.visible
227233
heading: Config.shortDescFor('WALLET_SEND_CHANGE_TO_LIGHTNING')
228234
helptext: Config.longDescFor('WALLET_SEND_CHANGE_TO_LIGHTNING')
229235
}

electrum/gui/qml/components/WalletMainView.qml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ Item {
144144
var finalizerDialog = confirmSweepDialog.createObject(mainView, {
145145
privateKeys: dialog.privateKeys,
146146
message: qsTr('Sweep transaction'),
147-
showOptions: false,
148147
amountLabelText: qsTr('Total sweep amount'),
149148
sendButtonText: Daemon.currentWallet.isWatchOnly
150149
? qsTr('Sweep...')
@@ -679,6 +678,9 @@ Item {
679678
property var _swapwaitdialog
680679
wallet: Daemon.currentWallet
681680
canRbf: true
681+
txOptions: TxFinalizer.TxOptions.MULTIPLE_CHANGE
682+
| TxFinalizer.TxOptions.OUTPUT_ROUNDING
683+
| TxFinalizer.TxOptions.SEND_CHANGE_TO_LIGHTNING
682684
onFinished: (signed, saved, complete) => {
683685
if (!complete) {
684686
var msg
@@ -760,6 +762,7 @@ Item {
760762
wallet: Daemon.currentWallet
761763
canRbf: true
762764
privateKeys: _confirmSweepDialog.privateKeys
765+
txOptions: TxFinalizer.TxOptions.NONE
763766
}
764767

765768
onClosed: destroy()

electrum/gui/qml/qechannelopener.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def openChannel(self, confirm_backup_conflict=False):
216216

217217
self._finalizer = QETxFinalizer(self, make_tx=mktx, accept=acpt)
218218
self._finalizer.canRbf = False
219+
self._finalizer.txOptions = QETxFinalizer.TxOptions.MULTIPLE_CHANGE | QETxFinalizer.TxOptions.OUTPUT_ROUNDING
219220
self._finalizer.amount = self._amount
220221
self._finalizer.wallet = self._wallet
221222
self.finalizerChanged.emit()

electrum/gui/qml/qetxfinalizer.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
22
import copy
33
from asyncio import Future
4-
from enum import IntEnum
4+
from enum import IntEnum, IntFlag
55
import threading
66
from decimal import Decimal, InvalidOperation
77
from typing import Optional, TYPE_CHECKING, Callable
@@ -163,9 +163,19 @@ def update(self):
163163

164164

165165
class TxFeeSlider(FeeSlider):
166+
167+
@pyqtEnum
168+
class TxOptions(IntFlag):
169+
NONE = 0
170+
MULTIPLE_CHANGE = 1
171+
OUTPUT_ROUNDING = 2
172+
SEND_CHANGE_TO_LIGHTNING = 4
173+
166174
def __init__(self, parent=None):
167175
FeeSlider.__init__(self, parent)
168176

177+
self._tx_options = TxFeeSlider.TxOptions.MULTIPLE_CHANGE | TxFeeSlider.TxOptions.OUTPUT_ROUNDING
178+
169179
self._fee = QEAmount()
170180
self._feeRate = ''
171181
self._userFee = ''
@@ -179,6 +189,20 @@ def __init__(self, parent=None):
179189
self._valid = False
180190
self._warning = ''
181191

192+
txOptionsChanged = pyqtSignal()
193+
@pyqtProperty(int, notify=txOptionsChanged)
194+
def txOptions(self) -> int:
195+
return int(self._tx_options)
196+
197+
@txOptions.setter
198+
def txOptions(self, options: int):
199+
options = TxFeeSlider.TxOptions(options)
200+
if self._tx_options != options:
201+
self._tx_options = options
202+
self.txOptionsChanged.emit()
203+
if self._wallet: # recompute (e.g. swap message) for the new option set
204+
self.update()
205+
182206
feeChanged = pyqtSignal()
183207
@pyqtProperty(QVariant, notify=feeChanged)
184208
def fee(self) -> QEAmount:
@@ -507,6 +531,13 @@ def swapStatusMsg(self, swap_status_msg: str):
507531
self._swapStatusMsg = swap_status_msg
508532
self.swapStatusMsgChanged.emit()
509533

534+
def _send_change_to_lightning(self) -> bool:
535+
# only honour the (persistent) config flag when this finalizer was set up to
536+
# offer the option, so non-payment flows (channel open, sweep) never swap change
537+
return (bool(self._tx_options & TxFeeSlider.TxOptions.SEND_CHANGE_TO_LIGHTNING)
538+
and self._wallet.wallet.has_lightning()
539+
and self._config.WALLET_SEND_CHANGE_TO_LIGHTNING)
540+
510541
@profiler
511542
def make_tx(self, amount):
512543
self._logger.debug(f'make_tx amount={amount}')
@@ -522,7 +553,7 @@ def make_tx(self, amount):
522553
outputs=outputs,
523554
fee_policy=self._fee_policy,
524555
rbf=self._rbf,
525-
send_change_to_lightning=self._config.WALLET_SEND_CHANGE_TO_LIGHTNING)
556+
send_change_to_lightning=self._send_change_to_lightning())
526557

527558
self._logger.debug('fee: %d, inputs: %d, outputs: %d' % (tx.get_fee(), len(tx.inputs()), len(tx.outputs())))
528559

@@ -533,7 +564,8 @@ def update(self):
533564
self._logger.debug('wallet not set, ignoring update()')
534565
return
535566

536-
if self._wallet.wallet.has_lightning() and self._config.WALLET_SEND_CHANGE_TO_LIGHTNING:
567+
send_change_to_lightning = self._send_change_to_lightning()
568+
if send_change_to_lightning:
537569
self._logger.debug('sending change to lightning')
538570
self.prepare_swap_transport()
539571

@@ -542,7 +574,7 @@ def update(self):
542574
amount = '!' if self._amount.isMax else self._amount.satsInt
543575
tx = self.make_tx(amount=amount)
544576
msg = ''
545-
if self.config.WALLET_SEND_CHANGE_TO_LIGHTNING:
577+
if send_change_to_lightning:
546578
msg = self.swap_manager.get_message_for_swap_change(self.swap_transport, tx)
547579
self.swapStatusMsg = msg
548580

0 commit comments

Comments
 (0)