Browse Source

cli history: add option to filter by block height

sqlite_db
SomberNight 6 years ago
parent
commit
2174fc0676
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 11
      electrum/commands.py
  2. 13
      electrum/wallet.py

11
electrum/commands.py

@ -537,11 +537,14 @@ class Commands:
return tx.as_dict() return tx.as_dict()
@command('w') @command('w')
def history(self, year=None, show_addresses=False, show_fiat=False, show_fees=False): def history(self, year=None, show_addresses=False, show_fiat=False, show_fees=False,
from_height=None, to_height=None):
"""Wallet history. Returns the transaction history of your wallet.""" """Wallet history. Returns the transaction history of your wallet."""
kwargs = { kwargs = {
'show_addresses': show_addresses, 'show_addresses': show_addresses,
'show_fees': show_fees, 'show_fees': show_fees,
'from_height': from_height,
'to_height': to_height,
} }
if year: if year:
import time import time
@ -831,7 +834,9 @@ command_options = {
'show_fees': (None, "Show miner fees paid by transactions"), 'show_fees': (None, "Show miner fees paid by transactions"),
'year': (None, "Show history for a given year"), 'year': (None, "Show history for a given year"),
'fee_method': (None, "Fee estimation method to use"), 'fee_method': (None, "Fee estimation method to use"),
'fee_level': (None, "Float between 0.0 and 1.0, representing fee slider position") 'fee_level': (None, "Float between 0.0 and 1.0, representing fee slider position"),
'from_height': (None, "Only show transactions that confirmed after given block height"),
'to_height': (None, "Only show transactions that confirmed before given block height"),
} }
@ -843,6 +848,8 @@ arg_types = {
'nbits': int, 'nbits': int,
'imax': int, 'imax': int,
'year': int, 'year': int,
'from_height': int,
'to_height': int,
'tx': tx_from_str, 'tx': tx_from_str,
'pubkeys': json_loads, 'pubkeys': json_loads,
'jsontx': json_loads, 'jsontx': json_loads,

13
electrum/wallet.py

@ -422,7 +422,11 @@ class Abstract_Wallet(AddressSynchronizer):
@profiler @profiler
def get_full_history(self, domain=None, from_timestamp=None, to_timestamp=None, def get_full_history(self, domain=None, from_timestamp=None, to_timestamp=None,
fx=None, show_addresses=False, show_fees=False): fx=None, show_addresses=False, show_fees=False,
from_height=None, to_height=None):
if (from_timestamp is not None or to_timestamp is not None) \
and (from_height is not None or to_height is not None):
raise Exception('timestamp and block height based filtering cannot be used together')
out = [] out = []
income = 0 income = 0
expenditures = 0 expenditures = 0
@ -437,10 +441,15 @@ 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
height = tx_mined_status.height
if from_height is not None and height < from_height:
continue
if to_height is not None and height >= to_height:
continue
tx = self.transactions.get(tx_hash) tx = self.transactions.get(tx_hash)
item = { item = {
'txid': tx_hash, 'txid': tx_hash,
'height': tx_mined_status.height, 'height': height,
'confirmations': tx_mined_status.conf, 'confirmations': tx_mined_status.conf,
'timestamp': timestamp, 'timestamp': timestamp,
'incoming': True if value>0 else False, 'incoming': True if value>0 else False,

Loading…
Cancel
Save