Browse Source

qml: move tx verified event handling to transactionlistmodel,

refresh history after broadcast
patch-4
Sander van Grieken 2 years ago
parent
commit
b7c31ad80e
  1. 1
      electrum/gui/qml/components/TxDetails.qml
  2. 22
      electrum/gui/qml/qetransactionlistmodel.py
  3. 12
      electrum/gui/qml/qewallet.py

1
electrum/gui/qml/components/TxDetails.qml

@ -415,6 +415,7 @@ Pane {
qsTr('Note: this is an offline transaction, if you want the network to see it, you need to broadcast it.') qsTr('Note: this is an offline transaction, if you want the network to see it, you need to broadcast it.')
}) })
dialog.open() dialog.open()
root.close()
} }
onSaveTxError: { onSaveTxError: {
var dialog = app.messageDialog.createObject(app, { var dialog = app.messageDialog.createObject(app, {

22
electrum/gui/qml/qetransactionlistmodel.py

@ -7,13 +7,19 @@ from electrum.logging import get_logger
from electrum.util import Satoshis, TxMinedInfo from electrum.util import Satoshis, TxMinedInfo
from .qetypes import QEAmount from .qetypes import QEAmount
from .util import QtEventListener, qt_event_listener
class QETransactionListModel(QAbstractListModel): class QETransactionListModel(QAbstractListModel, QtEventListener):
def __init__(self, wallet, parent=None, *, onchain_domain=None, include_lightning=True): def __init__(self, wallet, parent=None, *, onchain_domain=None, include_lightning=True):
super().__init__(parent) super().__init__(parent)
self.wallet = wallet self.wallet = wallet
self.onchain_domain = onchain_domain self.onchain_domain = onchain_domain
self.include_lightning = include_lightning self.include_lightning = include_lightning
self.register_callbacks()
self.destroyed.connect(lambda: self.on_destroy())
self.requestRefresh.connect(lambda: self.init_model())
self.init_model() self.init_model()
_logger = get_logger(__name__) _logger = get_logger(__name__)
@ -26,6 +32,17 @@ class QETransactionListModel(QAbstractListModel):
_ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES])) _ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES]))
_ROLE_RMAP = dict(zip(_ROLE_NAMES, _ROLE_KEYS)) _ROLE_RMAP = dict(zip(_ROLE_NAMES, _ROLE_KEYS))
requestRefresh = pyqtSignal()
def on_destroy(self):
self.unregister_callbacks()
@qt_event_listener
def on_event_verified(self, wallet, txid, info):
if wallet == self.wallet:
self._logger.debug('verified event for txid %s' % txid)
self.on_tx_verified(txid, info)
def rowCount(self, index): def rowCount(self, index):
return len(self.tx_history) return len(self.tx_history)
@ -117,6 +134,7 @@ class QETransactionListModel(QAbstractListModel):
# initial model data # initial model data
@pyqtSlot() @pyqtSlot()
def init_model(self): def init_model(self):
self._logger.debug('retrieving history')
history = self.wallet.get_full_history(onchain_domain=self.onchain_domain, history = self.wallet.get_full_history(onchain_domain=self.onchain_domain,
include_lightning=self.include_lightning) include_lightning=self.include_lightning)
txs = [] txs = []
@ -129,7 +147,7 @@ class QETransactionListModel(QAbstractListModel):
self.tx_history.reverse() self.tx_history.reverse()
self.endInsertRows() self.endInsertRows()
def update_tx(self, txid, info): def on_tx_verified(self, txid, info):
i = 0 i = 0
for tx in self.tx_history: for tx in self.tx_history:
if 'txid' in tx and tx['txid'] == txid: if 'txid' in tx and tx['txid'] == txid:

12
electrum/gui/qml/qewallet.py

@ -176,11 +176,6 @@ class QEWallet(AuthMixin, QObject, QtEventListener):
self.addressModel.setDirty() self.addressModel.setDirty()
self.historyModel.init_model() # TODO: be less dramatic self.historyModel.init_model() # TODO: be less dramatic
@qt_event_listener
def on_event_verified(self, wallet, txid, info):
if wallet == self.wallet:
self.historyModel.update_tx(txid, info)
@event_listener @event_listener
def on_event_wallet_updated(self, wallet): def on_event_wallet_updated(self, wallet):
if wallet == self.wallet: if wallet == self.wallet:
@ -489,13 +484,12 @@ class QEWallet(AuthMixin, QObject, QtEventListener):
def broadcast(self, tx): def broadcast(self, tx):
assert tx.is_complete() assert tx.is_complete()
network = self.wallet.network # TODO not always defined? # network = self.wallet.network # TODO not always defined?
def broadcast_thread(): def broadcast_thread():
try: try:
self._logger.info('running broadcast in thread') self._logger.info('running broadcast in thread')
result = network.run_from_another_thread(network.broadcast_transaction(tx)) self.wallet.network.run_from_another_thread(self.wallet.network.broadcast_transaction(tx))
self._logger.info(repr(result))
except TxBroadcastError as e: except TxBroadcastError as e:
self._logger.error(repr(e)) self._logger.error(repr(e))
self.broadcastFailed.emit(tx.txid(),'',repr(e)) self.broadcastFailed.emit(tx.txid(),'',repr(e))
@ -503,7 +497,9 @@ class QEWallet(AuthMixin, QObject, QtEventListener):
self._logger.error(repr(e)) self._logger.error(repr(e))
self.broadcastFailed.emit(tx.txid(),'',repr(e)) self.broadcastFailed.emit(tx.txid(),'',repr(e))
else: else:
self._logger.info('broadcast success')
self.broadcastSucceeded.emit(tx.txid()) self.broadcastSucceeded.emit(tx.txid())
self.historyModel.requestRefresh.emit() # via qt thread
threading.Thread(target=broadcast_thread).start() threading.Thread(target=broadcast_thread).start()

Loading…
Cancel
Save