From 57ec81cad0f9a8869893b0d3f34487fc5fadbb57 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Tue, 15 Nov 2022 17:11:08 +0100 Subject: [PATCH] qml: multisig implement finalize tx not complete result --- .../gui/qml/components/ConfirmTxDialog.qml | 4 ++- electrum/gui/qml/components/OpenChannel.qml | 2 +- .../gui/qml/components/WalletMainView.qml | 8 ++--- electrum/gui/qml/qetxfinalizer.py | 31 ++++++++++++++++++- electrum/gui/qml/qewallet.py | 13 ++++++-- 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/electrum/gui/qml/components/ConfirmTxDialog.qml b/electrum/gui/qml/components/ConfirmTxDialog.qml index 67ae49499..5c5cdbbc5 100644 --- a/electrum/gui/qml/components/ConfirmTxDialog.qml +++ b/electrum/gui/qml/components/ConfirmTxDialog.qml @@ -224,7 +224,9 @@ ElDialog { FlatButton { id: sendButton Layout.fillWidth: true - text: Daemon.currentWallet.isWatchOnly ? qsTr('Finalize') : qsTr('Pay') + text: (Daemon.currentWallet.isWatchOnly || !Daemon.currentWallet.canSignWithoutCosigner) + ? qsTr('Finalize') + : qsTr('Pay') icon.source: '../../icons/confirmed.png' enabled: finalizer.valid onClicked: { diff --git a/electrum/gui/qml/components/OpenChannel.qml b/electrum/gui/qml/components/OpenChannel.qml index ab7dc6e1b..84f6d1a3f 100644 --- a/electrum/gui/qml/components/OpenChannel.qml +++ b/electrum/gui/qml/components/OpenChannel.qml @@ -186,7 +186,7 @@ Pane { 'satoshis': channelopener.amount }) dialog.txaccepted.connect(function() { - dialog.finalizer.send_onchain() + dialog.finalizer.signAndSend() }) dialog.open() } diff --git a/electrum/gui/qml/components/WalletMainView.qml b/electrum/gui/qml/components/WalletMainView.qml index c5dfc27dd..e66a0da49 100644 --- a/electrum/gui/qml/components/WalletMainView.qml +++ b/electrum/gui/qml/components/WalletMainView.qml @@ -235,12 +235,12 @@ Item { 'satoshis': invoice.amount, 'message': invoice.message }) - var wo = Daemon.currentWallet.isWatchOnly + var canComplete = !Daemon.currentWallet.isWatchOnly && Daemon.currentWallet.canSignWithoutCosigner dialog.txaccepted.connect(function() { - if (wo) { - showUnsignedTx(dialog.finalizer.serializedTx(false), dialog.finalizer.serializedTx(true)) + if (!canComplete) { + dialog.finalizer.signAndSave() } else { - dialog.finalizer.send_onchain() + dialog.finalizer.signAndSend() } }) dialog.open() diff --git a/electrum/gui/qml/qetxfinalizer.py b/electrum/gui/qml/qetxfinalizer.py index 67f360a1a..7e84707a6 100644 --- a/electrum/gui/qml/qetxfinalizer.py +++ b/electrum/gui/qml/qetxfinalizer.py @@ -320,7 +320,7 @@ class QETxFinalizer(TxFeeSlider): self.validChanged.emit() @pyqtSlot() - def send_onchain(self): + def signAndSend(self): if not self._valid or not self._tx: self._logger.debug('no valid tx') return @@ -331,6 +331,35 @@ class QETxFinalizer(TxFeeSlider): self._wallet.sign(self._tx, broadcast=True) + @pyqtSlot() + def signAndSave(self): + if not self._valid or not self._tx: + self._logger.error('no valid tx') + return + + # TODO: f_accept handler not used + # if self.f_accept: + # self.f_accept(self._tx) + # return + + try: + self._wallet.transactionSigned.disconnect(self.onSigned) + except: + pass + self._wallet.transactionSigned.connect(self.onSigned) + self._wallet.sign(self._tx) + + @pyqtSlot(str) + def onSigned(self, txid): + if txid != self._tx.txid(): + return + + self._logger.debug('onSigned') + self._wallet.transactionSigned.disconnect(self.onSigned) + + if not self._wallet.wallet.adb.add_transaction(self._tx): + self._logger.error('Could not save tx') + @pyqtSlot(result=str) @pyqtSlot(bool, result=str) def serializedTx(self, for_qr=False): diff --git a/electrum/gui/qml/qewallet.py b/electrum/gui/qml/qewallet.py index 6e45ac506..e60191a5d 100644 --- a/electrum/gui/qml/qewallet.py +++ b/electrum/gui/qml/qewallet.py @@ -15,6 +15,7 @@ from electrum.network import TxBroadcastError, BestEffortRequestFailed from electrum.transaction import PartialTxOutput from electrum.util import (parse_max_spend, InvalidPassword, event_listener) from electrum.plugin import run_hook +from electrum.wallet import Multisig_Wallet from .auth import AuthMixin, auth_protect from .qeaddresslistmodel import QEAddressListModel @@ -355,6 +356,14 @@ class QEWallet(AuthMixin, QObject, QtEventListener): def canSignWithoutServer(self): return self.wallet.can_sign_without_server() if self.wallet.wallet_type == '2fa' else True + @pyqtProperty(bool, notify=dataChanged) + def canSignWithoutCosigner(self): + if isinstance(self.wallet, Multisig_Wallet): + if self.wallet.wallet_type == '2fa': # 2fa is multisig, but it handles cosigning itself + return True + return self.wallet.m == 1 + return True + balanceChanged = pyqtSignal() @pyqtProperty(QEAmount, notify=balanceChanged) @@ -453,12 +462,12 @@ class QEWallet(AuthMixin, QObject, QtEventListener): return txid = tx.txid() - self._logger.debug(f'txid={txid}') + self._logger.debug(f'do_sign(), txid={txid}') self.transactionSigned.emit(txid) if not tx.is_complete(): - self._logger.info('tx not complete') + self._logger.debug('tx not complete') return if broadcast: