1
0

plugins: psbt_nostr: move can_send_psbt logic from GUI to backend, fix qml wallet switch bug

This commit is contained in:
Sander van Grieken
2025-04-16 09:47:41 +02:00
parent eb52090fee
commit 182accb9fb
4 changed files with 22 additions and 15 deletions

View File

@@ -218,6 +218,14 @@ class CosignerWallet(Logger):
# note that tx could also be unrelated from wallet?... (not ismine inputs)
return True
def can_send_psbt(self, tx: Union[Transaction, PartialTransaction]) -> bool:
if tx.is_complete() or self.wallet.can_sign(tx):
return False
for xpub, pubkey in self.cosigner_list:
if self.cosigner_can_sign(tx, xpub):
return True
return False
def mark_pending_event_rcvd(self, event_id):
self.logger.debug('marking event rcvd')
self.known_events[event_id] = now()

View File

@@ -58,23 +58,30 @@ class QReceiveSignalObject(QObject):
def loader(self):
return 'main.qml'
@pyqtSlot(QEWallet, str, result=bool)
def canSendPsbt(self, wallet: 'QEWallet', tx: str) -> bool:
cosigner_wallet = self._plugin.cosigner_wallets.get(wallet.wallet)
if not cosigner_wallet:
return False
return cosigner_wallet.can_send_psbt(tx_from_any(tx, deserialize=True))
@pyqtSlot(QEWallet, str)
def sendPsbt(self, wallet: 'QEWallet', tx: str):
cosigner_wallet = self._plugin.cosigner_wallets[wallet.wallet]
cosigner_wallet = self._plugin.cosigner_wallets.get(wallet.wallet)
if not cosigner_wallet:
return
cosigner_wallet.send_psbt(tx_from_any(tx, deserialize=True))
@pyqtSlot(QEWallet, str)
def acceptPsbt(self, wallet: 'QEWallet', event_id: str):
cosigner_wallet = self._plugin.cosigner_wallets[wallet.wallet]
cosigner_wallet = self._plugin.cosigner_wallets.get(wallet.wallet)
if not cosigner_wallet:
return
cosigner_wallet.accept_psbt(event_id)
@pyqtSlot(QEWallet, str)
def rejectPsbt(self, wallet: 'QEWallet', event_id: str):
cosigner_wallet = self._plugin.cosigner_wallets[wallet.wallet]
cosigner_wallet = self._plugin.cosigner_wallets.get(wallet.wallet)
if not cosigner_wallet:
return
cosigner_wallet.reject_psbt(event_id)
@@ -98,8 +105,8 @@ class Plugin(PsbtNostrPlugin):
@hook
def load_wallet(self, wallet: 'Abstract_Wallet'):
# remove existing, only foreground wallet active
if len(self.cosigner_wallets):
self.remove_cosigner_wallet(self.cosigner_wallets[0])
for wallet in self.cosigner_wallets.copy().keys():
self.remove_cosigner_wallet(wallet)
if not isinstance(wallet, Multisig_Wallet):
return
self.add_cosigner_wallet(wallet, QmlCosignerWallet(wallet, self))

View File

@@ -36,7 +36,7 @@ Item {
property variant dialog
text: qsTr('Nostr')
icon.source: Qt.resolvedUrl('../../../gui/icons/network.png')
visible: Daemon.currentWallet.isMultisig && Daemon.currentWallet.walletType != '2fa'
visible: AppController.plugin('psbt_nostr').canSendPsbt(Daemon.currentWallet, dialog.text)
onClicked: {
console.log('about to psbt nostr send')
psbt_nostr_send_button.enabled = false

View File

@@ -77,15 +77,7 @@ class Plugin(PsbtNostrPlugin):
def transaction_dialog_update(self, d: 'TxDialog'):
if cw := self.cosigner_wallets.get(d.wallet):
assert isinstance(cw, QtCosignerWallet)
if d.tx.is_complete() or d.wallet.can_sign(d.tx):
d.cosigner_send_button.setVisible(False)
return
for xpub, pubkey in cw.cosigner_list:
if cw.cosigner_can_sign(d.tx, xpub):
d.cosigner_send_button.setVisible(True)
break
else:
d.cosigner_send_button.setVisible(False)
d.cosigner_send_button.setVisible(cw.can_send_psbt(d.tx))
class QtCosignerWallet(EventListener, CosignerWallet):