commit 65b88dca8644b6a1be819029d81e3c8b83b11bc0
parent a47a2c1b720b184aa01c5e822599e1c341d7a8fe
Author: ThomasV <thomasv@electrum.org>
Date: Wed, 11 Sep 2019 17:02:03 +0200
return fees in history, show them in kivy GUI
Diffstat:
6 files changed, 34 insertions(+), 17 deletions(-)
diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py
@@ -439,14 +439,16 @@ class AddressSynchronizer(Logger):
for tx_hash in tx_deltas:
delta = tx_deltas[tx_hash]
tx_mined_status = self.get_tx_height(tx_hash)
- history.append((tx_hash, tx_mined_status, delta))
+ # FIXME: db should only store fees computed by us...
+ fee = self.db.get_tx_fee(tx_hash)
+ history.append((tx_hash, tx_mined_status, delta, fee))
history.sort(key = lambda x: self.get_txpos(x[0]), reverse=True)
# 3. add balance
c, u, x = self.get_balance(domain)
balance = c + u + x
h2 = []
- for tx_hash, tx_mined_status, delta in history:
- h2.append((tx_hash, tx_mined_status, delta, balance))
+ for tx_hash, tx_mined_status, delta, fee in history:
+ h2.append((tx_hash, tx_mined_status, delta, fee, balance))
if balance is None or delta is None:
balance = None
else:
diff --git a/electrum/commands.py b/electrum/commands.py
@@ -591,11 +591,10 @@ class Commands:
return tx.as_dict()
@command('w')
- async def onchain_history(self, year=None, show_addresses=False, show_fiat=False, show_fees=False, wallet=None):
+ async def onchain_history(self, year=None, show_addresses=False, show_fiat=False, wallet=None):
"""Wallet onchain history. Returns the transaction history of your wallet."""
kwargs = {
'show_addresses': show_addresses,
- 'show_fees': show_fees,
}
if year:
import time
diff --git a/electrum/gui/kivy/uix/screens.py b/electrum/gui/kivy/uix/screens.py
@@ -134,6 +134,9 @@ class HistoryScreen(CScreen):
status_str = 'unconfirmed' if timestamp is None else format_time(int(timestamp))
icon = "atlas://electrum/gui/kivy/theming/light/lightning"
message = tx_item['label']
+ fee_msat = tx_item['fee_msat']
+ fee = int(fee_msat/1000) if fee_msat else None
+ fee_text = '' if fee is None else 'fee: %d sat'%fee
else:
tx_hash = tx_item['txid']
conf = tx_item['confirmations']
@@ -145,15 +148,20 @@ class HistoryScreen(CScreen):
status, status_str = self.app.wallet.get_tx_status(tx_hash, tx_mined_info)
icon = "atlas://electrum/gui/kivy/theming/light/" + TX_ICONS[status]
message = tx_item['label'] or tx_hash
+ fee = tx_item['fee_sat']
+ fee_text = '' if fee is None else 'fee: %d sat'%fee
ri = {}
ri['screen'] = self
ri['key'] = key
ri['icon'] = icon
ri['date'] = status_str
ri['message'] = message
+ ri['fee_text'] = fee_text
value = tx_item['value'].value
if value is not None:
- ri['is_mine'] = value < 0
+ if fee is not None:
+ value = value + int(fee)
+ ri['is_mine'] = value <= 0
ri['amount'] = self.app.format_amount(value, is_diff = True)
if 'fiat_value' in tx_item:
ri['quote_text'] = str(tx_item['fiat_value'])
diff --git a/electrum/gui/kivy/uix/ui_screens/history.kv b/electrum/gui/kivy/uix/ui_screens/history.kv
@@ -17,6 +17,7 @@
<HistoryItem@CardItem>
icon: 'atlas://electrum/gui/kivy/theming/light/important'
message: ''
+ fee_text: ''
is_mine: True
amount: '--'
amount_color: '#FF6657' if self.is_mine else '#2EA442'
@@ -60,7 +61,7 @@
font_size: '15sp'
Widget
CardLabel:
- text: ''
+ text: root.fee_text
halign: 'right'
font_size: '12sp'
Widget
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
@@ -453,9 +453,15 @@ class LNWallet(LNWorker):
elif len(plist) == 1:
chan_id, htlc, _direction, status = plist[0]
direction = 'sent' if _direction == SENT else 'received'
- amount_msat= int(_direction) * htlc.amount_msat
+ amount_msat = int(_direction) * htlc.amount_msat
timestamp = htlc.timestamp
label = self.wallet.get_label(payment_hash)
+ req = self.get_request(payment_hash)
+ if req and _direction == SENT:
+ req_amount_msat = -req['amount']*1000
+ fee_msat = req_amount_msat - amount_msat
+ else:
+ fee_msat = None
else:
# assume forwarding
direction = 'forwarding'
@@ -463,15 +469,17 @@ class LNWallet(LNWorker):
status = ''
label = _('Forwarding')
timestamp = min([htlc.timestamp for chan_id, htlc, _direction, status in plist])
+ fee_msat = None # fixme
item = {
'type': 'payment',
'label': label,
- 'timestamp':timestamp or 0,
+ 'timestamp': timestamp or 0,
'date': timestamp_to_datetime(timestamp),
'direction': direction,
'status': status,
'amount_msat': amount_msat,
+ 'fee_msat': fee_msat,
'payment_hash': payment_hash
}
out.append(item)
diff --git a/electrum/wallet.py b/electrum/wallet.py
@@ -482,16 +482,17 @@ class Abstract_Wallet(AddressSynchronizer):
# we also assume that block timestamps are monotonic (which is false...!)
h = self.get_history(domain)
balance = 0
- for tx_hash, tx_mined_status, value, balance in h:
+ for tx_hash, tx_mined_status, value, fee, balance in h:
if tx_mined_status.timestamp is None or tx_mined_status.timestamp > target_timestamp:
return balance - value
# return last balance
return balance
def get_onchain_history(self):
- for tx_hash, tx_mined_status, value, balance in self.get_history():
+ for tx_hash, tx_mined_status, value, fee, balance in self.get_history():
yield {
'txid': tx_hash,
+ 'fee_sat': fee,
'height': tx_mined_status.height,
'confirmations': tx_mined_status.conf,
'timestamp': tx_mined_status.timestamp,
@@ -592,7 +593,7 @@ class Abstract_Wallet(AddressSynchronizer):
@profiler
def get_detailed_history(self, from_timestamp=None, to_timestamp=None,
- fx=None, show_addresses=False, show_fees=False):
+ fx=None, show_addresses=False):
# History with capital gains, using utxo pricing
# FIXME: Lightning capital gains would requires FIFO
out = []
@@ -610,10 +611,8 @@ class Abstract_Wallet(AddressSynchronizer):
continue
tx_hash = item['txid']
tx = self.db.get_transaction(tx_hash)
- tx_fee = None
- if show_fees:
- tx_fee = self.get_tx_fee(tx)
- item['fee'] = Satoshis(tx_fee) if tx_fee is not None else None
+ tx_fee = item['fee_sat']
+ item['fee'] = Satoshis(tx_fee) if tx_fee is not None else None
if show_addresses:
item['inputs'] = list(map(lambda x: dict((k, x[k]) for k in ('prevout_hash', 'prevout_n')), tx.inputs()))
item['outputs'] = list(map(lambda x:{'address':x.address, 'value':Satoshis(x.value)},
@@ -758,7 +757,7 @@ class Abstract_Wallet(AddressSynchronizer):
def get_unconfirmed_base_tx_for_batching(self) -> Optional[Transaction]:
candidate = None
- for tx_hash, tx_mined_status, delta, balance in self.get_history():
+ for tx_hash, tx_mined_status, delta, fee, balance in self.get_history():
# tx should not be mined yet
if tx_mined_status.conf > 0: continue
# tx should be "outgoing" from wallet