|
|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
from datetime import datetime, timedelta |
|
|
|
|
from typing import TYPE_CHECKING |
|
|
|
|
from typing import TYPE_CHECKING, Dict, Any |
|
|
|
|
|
|
|
|
|
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject |
|
|
|
|
from PyQt5.QtCore import Qt, QAbstractListModel, QModelIndex |
|
|
|
|
@ -97,9 +97,9 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
|
|
|
|
|
self.tx_history = [] |
|
|
|
|
self.endResetModel() |
|
|
|
|
|
|
|
|
|
def tx_to_model(self, tx): |
|
|
|
|
#self._logger.debug(str(tx)) |
|
|
|
|
item = tx |
|
|
|
|
def tx_to_model(self, tx_item): |
|
|
|
|
#self._logger.debug(str(tx_item)) |
|
|
|
|
item = tx_item |
|
|
|
|
|
|
|
|
|
item['key'] = item['txid'] if 'txid' in item else item['payment_hash'] |
|
|
|
|
|
|
|
|
|
@ -118,15 +118,19 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
|
|
|
|
|
|
|
|
|
|
if 'txid' in item: |
|
|
|
|
tx = self.wallet.db.get_transaction(item['txid']) |
|
|
|
|
assert tx is not None |
|
|
|
|
if tx: |
|
|
|
|
item['complete'] = tx.is_complete() |
|
|
|
|
else: # due to races, tx might have already been removed from history |
|
|
|
|
item['complete'] = False |
|
|
|
|
|
|
|
|
|
# newly arriving txs, or (partially/fully signed) local txs have no (block) timestamp |
|
|
|
|
# FIXME just use wallet.get_tx_status, and change that as needed |
|
|
|
|
if not item['timestamp']: # onchain: local or mempool or unverified txs |
|
|
|
|
txinfo = self.wallet.get_tx_info(tx) |
|
|
|
|
item['section'] = 'mempool' if item['complete'] and not txinfo.can_broadcast else 'local' |
|
|
|
|
status, status_str = self.wallet.get_tx_status(item['txid'], txinfo.tx_mined_status) |
|
|
|
|
txid = item['txid'] |
|
|
|
|
assert txid |
|
|
|
|
tx_mined_info = self._tx_mined_info_from_tx_item(tx_item) |
|
|
|
|
item['section'] = 'local' if tx_mined_info.is_local_like() else 'mempool' |
|
|
|
|
status, status_str = self.wallet.get_tx_status(txid, tx_mined_info=tx_mined_info) |
|
|
|
|
item['date'] = status_str |
|
|
|
|
else: # lightning or already mined (and SPV-ed) onchain txs |
|
|
|
|
item['section'] = self.get_section_by_timestamp(item['timestamp']) |
|
|
|
|
@ -162,6 +166,17 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
|
|
|
|
|
section = 'older' |
|
|
|
|
return date.strftime(dfmt[section]) |
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
def _tx_mined_info_from_tx_item(tx_item: Dict[str, Any]) -> TxMinedInfo: |
|
|
|
|
# FIXME a bit hackish to have to reconstruct the TxMinedInfo... same thing in qt-gui |
|
|
|
|
tx_mined_info = TxMinedInfo( |
|
|
|
|
height=tx_item['height'], |
|
|
|
|
conf=tx_item['confirmations'], |
|
|
|
|
timestamp=tx_item['timestamp'], |
|
|
|
|
wanted_height=tx_item.get('wanted_height', None), |
|
|
|
|
) |
|
|
|
|
return tx_mined_info |
|
|
|
|
|
|
|
|
|
# initial model data |
|
|
|
|
@pyqtSlot() |
|
|
|
|
@pyqtSlot(bool) |
|
|
|
|
|