mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 17:55:20 +00:00
parent
32af83b7ae
commit
5376d37c24
4 changed files with 37 additions and 6 deletions
|
@ -25,7 +25,7 @@ import threading
|
||||||
import asyncio
|
import asyncio
|
||||||
import itertools
|
import itertools
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import TYPE_CHECKING, Dict
|
from typing import TYPE_CHECKING, Dict, Optional
|
||||||
|
|
||||||
from . import bitcoin
|
from . import bitcoin
|
||||||
from .bitcoin import COINBASE_MATURITY, TYPE_ADDRESS, TYPE_PUBKEY
|
from .bitcoin import COINBASE_MATURITY, TYPE_ADDRESS, TYPE_PUBKEY
|
||||||
|
@ -712,6 +712,19 @@ class AddressSynchronizer(PrintError):
|
||||||
fee = None
|
fee = None
|
||||||
return is_relevant, is_mine, v, fee
|
return is_relevant, is_mine, v, fee
|
||||||
|
|
||||||
|
def get_tx_fee(self, tx: Transaction) -> Optional[int]:
|
||||||
|
if not tx:
|
||||||
|
return None
|
||||||
|
if hasattr(tx, '_cached_fee'):
|
||||||
|
return tx._cached_fee
|
||||||
|
is_relevant, is_mine, v, fee = self.get_wallet_delta(tx)
|
||||||
|
if fee is None:
|
||||||
|
txid = tx.txid()
|
||||||
|
fee = self.tx_fees.get(txid)
|
||||||
|
if fee is not None:
|
||||||
|
tx._cached_fee = fee
|
||||||
|
return fee
|
||||||
|
|
||||||
def get_addr_io(self, address):
|
def get_addr_io(self, address):
|
||||||
with self.lock, self.transaction_lock:
|
with self.lock, self.transaction_lock:
|
||||||
h = self.get_address_history(address)
|
h = self.get_address_history(address)
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import datetime
|
import datetime
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from electrum.address_synchronizer import TX_HEIGHT_LOCAL
|
from electrum.address_synchronizer import TX_HEIGHT_LOCAL
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
|
@ -33,6 +34,9 @@ from electrum.util import block_explorer_URL, profiler, print_error, TxMinedStat
|
||||||
|
|
||||||
from .util import *
|
from .util import *
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from electrum.wallet import Abstract_Wallet
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from electrum.plot import plot_history, NothingToPlotException
|
from electrum.plot import plot_history, NothingToPlotException
|
||||||
except:
|
except:
|
||||||
|
@ -216,7 +220,7 @@ class HistoryList(MyTreeWidget, AcceptFileDragDrop):
|
||||||
|
|
||||||
@profiler
|
@profiler
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
self.wallet = self.parent.wallet
|
self.wallet = self.parent.wallet # type: Abstract_Wallet
|
||||||
fx = self.parent.fx
|
fx = self.parent.fx
|
||||||
r = self.wallet.get_full_history(domain=self.get_domain(), from_timestamp=self.start_timestamp, to_timestamp=self.end_timestamp, fx=fx)
|
r = self.wallet.get_full_history(domain=self.get_domain(), from_timestamp=self.start_timestamp, to_timestamp=self.end_timestamp, fx=fx)
|
||||||
self.transactions = r['transactions']
|
self.transactions = r['transactions']
|
||||||
|
@ -435,12 +439,21 @@ class HistoryList(MyTreeWidget, AcceptFileDragDrop):
|
||||||
item['confirmations'],
|
item['confirmations'],
|
||||||
item['value'],
|
item['value'],
|
||||||
item.get('fiat_value', ''),
|
item.get('fiat_value', ''),
|
||||||
|
item.get('fee', ''),
|
||||||
|
item.get('fiat_fee', ''),
|
||||||
item['date']])
|
item['date']])
|
||||||
with open(file_name, "w+", encoding='utf-8') as f:
|
with open(file_name, "w+", encoding='utf-8') as f:
|
||||||
if is_csv:
|
if is_csv:
|
||||||
import csv
|
import csv
|
||||||
transaction = csv.writer(f, lineterminator='\n')
|
transaction = csv.writer(f, lineterminator='\n')
|
||||||
transaction.writerow(["transaction_hash", "label", "confirmations", "value", "fiat_value", "timestamp"])
|
transaction.writerow(["transaction_hash",
|
||||||
|
"label",
|
||||||
|
"confirmations",
|
||||||
|
"value",
|
||||||
|
"fiat_value",
|
||||||
|
"fee",
|
||||||
|
"fiat_fee",
|
||||||
|
"timestamp"])
|
||||||
for line in lines:
|
for line in lines:
|
||||||
transaction.writerow(line)
|
transaction.writerow(line)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -156,7 +156,7 @@ class Fiat(object):
|
||||||
return 'Fiat(%s)'% self.__str__()
|
return 'Fiat(%s)'% self.__str__()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.value.is_nan():
|
if self.value is None or self.value.is_nan():
|
||||||
return _('No Data')
|
return _('No Data')
|
||||||
else:
|
else:
|
||||||
return "{:.2f}".format(self.value) + ' ' + self.ccy
|
return "{:.2f}".format(self.value) + ' ' + self.ccy
|
||||||
|
|
|
@ -396,6 +396,7 @@ class Abstract_Wallet(AddressSynchronizer):
|
||||||
continue
|
continue
|
||||||
if to_timestamp and (timestamp or now) >= to_timestamp:
|
if to_timestamp and (timestamp or now) >= to_timestamp:
|
||||||
continue
|
continue
|
||||||
|
tx = self.transactions.get(tx_hash)
|
||||||
item = {
|
item = {
|
||||||
'txid': tx_hash,
|
'txid': tx_hash,
|
||||||
'height': tx_mined_status.height,
|
'height': tx_mined_status.height,
|
||||||
|
@ -406,8 +407,9 @@ class Abstract_Wallet(AddressSynchronizer):
|
||||||
'date': timestamp_to_datetime(timestamp),
|
'date': timestamp_to_datetime(timestamp),
|
||||||
'label': self.get_label(tx_hash),
|
'label': self.get_label(tx_hash),
|
||||||
}
|
}
|
||||||
|
tx_fee = self.get_tx_fee(tx)
|
||||||
|
item['fee'] = Satoshis(tx_fee) if tx_fee is not None else None
|
||||||
if show_addresses:
|
if show_addresses:
|
||||||
tx = self.transactions.get(tx_hash)
|
|
||||||
item['inputs'] = list(map(lambda x: dict((k, x[k]) for k in ('prevout_hash', 'prevout_n')), tx.inputs()))
|
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)},
|
item['outputs'] = list(map(lambda x:{'address':x.address, 'value':Satoshis(x.value)},
|
||||||
tx.get_outputs_for_UI()))
|
tx.get_outputs_for_UI()))
|
||||||
|
@ -423,8 +425,11 @@ class Abstract_Wallet(AddressSynchronizer):
|
||||||
if fx and fx.is_enabled() and fx.get_history_config():
|
if fx and fx.is_enabled() and fx.get_history_config():
|
||||||
fiat_value = self.get_fiat_value(tx_hash, fx.ccy)
|
fiat_value = self.get_fiat_value(tx_hash, fx.ccy)
|
||||||
fiat_default = fiat_value is None
|
fiat_default = fiat_value is None
|
||||||
fiat_value = fiat_value if fiat_value is not None else value / Decimal(COIN) * self.price_at_timestamp(tx_hash, fx.timestamp_rate) #
|
fiat_rate = self.price_at_timestamp(tx_hash, fx.timestamp_rate)
|
||||||
|
fiat_value = fiat_value if fiat_value is not None else value / Decimal(COIN) * fiat_rate
|
||||||
|
fiat_fee = tx_fee / Decimal(COIN) * fiat_rate if tx_fee is not None else None
|
||||||
item['fiat_value'] = Fiat(fiat_value, fx.ccy)
|
item['fiat_value'] = Fiat(fiat_value, fx.ccy)
|
||||||
|
item['fiat_fee'] = Fiat(fiat_fee, fx.ccy) if fiat_fee else None
|
||||||
item['fiat_default'] = fiat_default
|
item['fiat_default'] = fiat_default
|
||||||
if value < 0:
|
if value < 0:
|
||||||
acquisition_price = - value / Decimal(COIN) * self.average_price(tx_hash, fx.timestamp_rate, fx.ccy)
|
acquisition_price = - value / Decimal(COIN) * self.average_price(tx_hash, fx.timestamp_rate, fx.ccy)
|
||||||
|
|
Loading…
Add table
Reference in a new issue