tAdd back the 'to_height' and 'from_height' to onchain_history command Exclude unconfirmed transactions from --to_height and include them into --from_height. The reason being that an unconfirmed transaction will end up eventually into the last block which most of the time will be higher than --from_height - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 55fdddb0b80482c2622d97a0bd8305ead6ad7707 DIR parent d75f9c6e800ca1c78f596a9c3d437339fe8bb217 HTML Author: Marius Baisan <marius@softbinator.com> Date: Fri, 19 Feb 2021 12:45:45 +0200 Add back the 'to_height' and 'from_height' to onchain_history command Exclude unconfirmed transactions from --to_height and include them into --from_height. The reason being that an unconfirmed transaction will end up eventually into the last block which most of the time will be higher than --from_height Diffstat: M electrum/commands.py | 6 +++++- M electrum/wallet.py | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) --- DIR diff --git a/electrum/commands.py b/electrum/commands.py t@@ -662,10 +662,13 @@ class Commands: return result @command('w') - async def onchain_history(self, year=None, show_addresses=False, show_fiat=False, wallet: Abstract_Wallet = None): + async def onchain_history(self, year=None, show_addresses=False, show_fiat=False, wallet: Abstract_Wallet = None, + from_height=None, to_height=None): """Wallet onchain history. Returns the transaction history of your wallet.""" kwargs = { 'show_addresses': show_addresses, + 'from_height': from_height, + 'to_height': to_height, } if year: import time t@@ -677,6 +680,7 @@ class Commands: from .exchange_rate import FxThread fx = FxThread(self.config, None) kwargs['fx'] = fx + return json_normalize(wallet.get_detailed_history(**kwargs)) @command('w') DIR diff --git a/electrum/wallet.py b/electrum/wallet.py t@@ -950,9 +950,12 @@ class Abstract_Wallet(AddressSynchronizer, ABC): @profiler def get_detailed_history(self, from_timestamp=None, to_timestamp=None, - fx=None, show_addresses=False): + fx=None, show_addresses=False, from_height=None, to_height=None): # History with capital gains, using utxo pricing # FIXME: Lightning capital gains would requires FIFO + 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 = [] income = 0 expenditures = 0 t@@ -966,6 +969,11 @@ class Abstract_Wallet(AddressSynchronizer, ABC): continue if to_timestamp and (timestamp or now) >= to_timestamp: continue + height = item['height'] + if from_height is not None and from_height > height > 0: + continue + if to_height is not None and (height >= to_height or height <= 0): + continue tx_hash = item['txid'] tx = self.db.get_transaction(tx_hash) tx_fee = item['fee_sat'] t@@ -1005,6 +1013,8 @@ class Abstract_Wallet(AddressSynchronizer, ABC): summary = { 'start_date': start_date, 'end_date': end_date, + 'from_height': from_height, + 'to_height': to_height, 'start_balance': Satoshis(start_balance), 'end_balance': Satoshis(end_balance), 'incoming': Satoshis(income),