commit 205c437d9ae66152126c64fc835145f6aa7a45a9
parent 271d1a3f1d0548000f2aef1593cebd278367fb77
Author: SomberNight <somber.night@protonmail.com>
Date: Mon, 29 Apr 2019 02:32:15 +0200
wallet: get_tx_info now returns NamedTuple instead of abomination
Diffstat:
3 files changed, 50 insertions(+), 21 deletions(-)
diff --git a/electrum/gui/kivy/uix/dialogs/tx_dialog.py b/electrum/gui/kivy/uix/dialogs/tx_dialog.py
@@ -121,11 +121,18 @@ class TxDialog(Factory.Popup):
def update(self):
format_amount = self.app.format_amount_and_units
- tx_hash, self.status_str, self.description, self.can_broadcast, self.can_rbf, amount, fee, height, conf, timestamp, exp_n = self.wallet.get_tx_info(self.tx)
- self.tx_hash = tx_hash or ''
- if timestamp:
+ tx_details = self.wallet.get_tx_info(self.tx)
+ tx_mined_status = tx_details.tx_mined_status
+ exp_n = tx_details.mempool_depth_bytes
+ amount, fee = tx_details.amount, tx_details.fee
+ self.status_str = tx_details.status
+ self.description = tx_details.label
+ self.can_broadcast = tx_details.can_broadcast
+ self.can_rbf = tx_details.can_bump
+ self.tx_hash = tx_details.txid or ''
+ if tx_mined_status.timestamp:
self.date_label = _('Date')
- self.date_str = datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
+ self.date_str = datetime.fromtimestamp(tx_mined_status.timestamp).isoformat(' ')[:-3]
elif exp_n:
self.date_label = _('Mempool depth')
self.date_str = _('{} from tip').format('%.2f MB'%(exp_n/1000000))
@@ -144,7 +151,7 @@ class TxDialog(Factory.Popup):
self.fee_str = format_amount(fee) if fee is not None else _('unknown')
self.can_sign = self.wallet.can_sign(self.tx)
self.ids.output_list.update(self.tx.get_outputs_for_UI())
- self.is_local_tx = height == TX_HEIGHT_LOCAL
+ self.is_local_tx = tx_mined_status.height == TX_HEIGHT_LOCAL
self.update_action_button()
def update_action_button(self):
diff --git a/electrum/gui/qt/transaction_dialog.py b/electrum/gui/qt/transaction_dialog.py
@@ -223,22 +223,25 @@ class TxDialog(QDialog, MessageBoxMixin):
desc = self.desc
base_unit = self.main_window.base_unit()
format_amount = self.main_window.format_amount
- tx_hash, status, label, can_broadcast, can_rbf, amount, fee, height, conf, timestamp, exp_n = self.wallet.get_tx_info(self.tx)
+ tx_details = self.wallet.get_tx_info(self.tx)
+ tx_mined_status = tx_details.tx_mined_status
+ exp_n = tx_details.mempool_depth_bytes
+ amount, fee = tx_details.amount, tx_details.fee
size = self.tx.estimated_size()
- self.broadcast_button.setEnabled(can_broadcast)
+ self.broadcast_button.setEnabled(tx_details.can_broadcast)
can_sign = not self.tx.is_complete() and \
(self.wallet.can_sign(self.tx) or bool(self.main_window.tx_external_keypairs))
self.sign_button.setEnabled(can_sign)
- self.tx_hash_e.setText(tx_hash or _('Unknown'))
+ self.tx_hash_e.setText(tx_details.txid or _('Unknown'))
if desc is None:
self.tx_desc.hide()
else:
self.tx_desc.setText(_("Description") + ': ' + desc)
self.tx_desc.show()
- self.status_label.setText(_('Status:') + ' ' + status)
+ self.status_label.setText(_('Status:') + ' ' + tx_details.status)
- if timestamp:
- time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
+ if tx_mined_status.timestamp:
+ time_str = datetime.datetime.fromtimestamp(tx_mined_status.timestamp).isoformat(' ')[:-3]
self.date_label.setText(_("Date: {}").format(time_str))
self.date_label.show()
elif exp_n:
diff --git a/electrum/wallet.py b/electrum/wallet.py
@@ -38,7 +38,7 @@ import traceback
from functools import partial
from numbers import Number
from decimal import Decimal
-from typing import TYPE_CHECKING, List, Optional, Tuple, Union
+from typing import TYPE_CHECKING, List, Optional, Tuple, Union, NamedTuple
from .i18n import _
from .util import (NotEnoughFunds, PrintError, UserCancelled, profiler,
@@ -180,6 +180,17 @@ class InternalAddressCorruption(Exception):
"Please restore your wallet from seed, and compare the addresses in both files")
+class TxWalletDetails(NamedTuple):
+ txid: Optional[str]
+ status: str
+ label: str
+ can_broadcast: bool
+ can_bump: bool
+ amount: Optional[int]
+ fee: Optional[int]
+ tx_mined_status: TxMinedInfo
+ mempool_depth_bytes: Optional[int]
+
class Abstract_Wallet(AddressSynchronizer):
"""
@@ -344,25 +355,23 @@ class Abstract_Wallet(AddressSynchronizer):
return True
#return self.history.values() != [[]] * len(self.history)
- def get_tx_info(self, tx):
+ def get_tx_info(self, tx) -> TxWalletDetails:
is_relevant, is_mine, v, fee = self.get_wallet_delta(tx)
exp_n = None
can_broadcast = False
can_bump = False
label = ''
- height = conf = timestamp = None
tx_hash = tx.txid()
+ tx_mined_status = self.get_tx_height(tx_hash)
if tx.is_complete():
if self.db.get_transaction(tx_hash):
label = self.get_label(tx_hash)
- tx_mined_status = self.get_tx_height(tx_hash)
- height, conf, timestamp = tx_mined_status.height, tx_mined_status.conf, tx_mined_status.timestamp
- if height > 0:
- if conf:
- status = _("{} confirmations").format(conf)
+ if tx_mined_status.height > 0:
+ if tx_mined_status.conf:
+ status = _("{} confirmations").format(tx_mined_status.conf)
else:
status = _('Not verified')
- elif height in (TX_HEIGHT_UNCONF_PARENT, TX_HEIGHT_UNCONFIRMED):
+ elif tx_mined_status.height in (TX_HEIGHT_UNCONF_PARENT, TX_HEIGHT_UNCONFIRMED):
status = _('Unconfirmed')
if fee is None:
fee = self.db.get_tx_fee(tx_hash)
@@ -392,7 +401,17 @@ class Abstract_Wallet(AddressSynchronizer):
else:
amount = None
- return tx_hash, status, label, can_broadcast, can_bump, amount, fee, height, conf, timestamp, exp_n
+ return TxWalletDetails(
+ txid=tx_hash,
+ status=status,
+ label=label,
+ can_broadcast=can_broadcast,
+ can_bump=can_bump,
+ amount=amount,
+ fee=fee,
+ tx_mined_status=tx_mined_status,
+ mempool_depth_bytes=exp_n,
+ )
def get_spendable_coins(self, domain, config, *, nonlocal_only=False):
confirmed_only = config.get('confirmed_only', False)