From 68c5f5be76d06dd8f5bcc4b042fa4a42e6be9311 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 26 Oct 2025 10:35:54 +0000 Subject: [PATCH] rpc: use icall mechanism for `listreceivedbylabel` and `listsinceblock` --- mmgen/proto/btc/rpc/local.py | 62 +++++++++++++++++++++++++++++++++ mmgen/proto/btc/tw/addresses.py | 3 +- mmgen/proto/btc/tw/txhistory.py | 17 +++------ 3 files changed, 67 insertions(+), 15 deletions(-) diff --git a/mmgen/proto/btc/rpc/local.py b/mmgen/proto/btc/rpc/local.py index 154b66b7..a1d3f1d6 100755 --- a/mmgen/proto/btc/rpc/local.py +++ b/mmgen/proto/btc/rpc/local.py @@ -91,6 +91,55 @@ class CallSigs: include_watchonly, verbose) + # List received transactions by label. + # 1. minconf (numeric, optional, default=1) The minimum number of + # confirmations before payments are included. + # 2. include_empty (boolean, optional, default=false) Whether to include labels + # that haven't received any payments. + # 3. include_watchonly (boolean, optional, default=true for watch-only wallets, + # otherwise false) Whether to include watch-only addresses + # (see 'importaddress') + # 4. include_immature_coinbase (boolean, optional, default=false) Include immature coinbase + # transactions. + def listreceivedbylabel( + self, + *, + minconf = 1, + include_empty = False, + include_watchonly = True, + include_immature_coinbase = False): + return ( + 'listreceivedbylabel', + minconf, + include_empty, + include_watchonly, + include_immature_coinbase) + + # Get all transactions in blocks since block [blockhash], or all transactions if omitted. + # 1. blockhash (string, optional) If set, the block hash to list transactions since, + # otherwise list all transactions. + # 2. target_confirmations (numeric, optional, default=1) Return the nth block hash from the main + # chain. e.g. 1 would mean the best block hash. Note: this is not used + # as a filter, but only affects [lastblock] in the return value + # 3. include_watchonly (boolean, optional, default=true for watch-only wallets, otherwise + # false) Include transactions to watch-only addresses + # 4. include_removed (boolean, optional, default=true) Show transactions that were removed + # due to a reorg in the "removed" array (not guaranteed to work on + # pruned nodes) + def listsinceblock( + self, + *, + blockhash = '', + target_confirmations = 1, + include_watchonly = True, + include_removed = True): + return ( + 'listsinceblock', + blockhash, + target_confirmations, + include_watchonly, + include_removed) + class litecoin_core(bitcoin_core): def createwallet( @@ -114,6 +163,19 @@ class CallSigs: txid, # 1. transaction id include_watchonly) # 2. optional, default=true for watch-only wallets, otherwise false + def listreceivedbylabel( + self, + *, + minconf = 1, + include_empty = False, + include_watchonly = True, + include_immature_coinbase = False): + return ( + 'listreceivedbylabel', + minconf, + include_empty, + include_watchonly) + class bitcoin_cash_node(litecoin_core): pass diff --git a/mmgen/proto/btc/tw/addresses.py b/mmgen/proto/btc/tw/addresses.py index f4b126e1..a6c8bd40 100755 --- a/mmgen/proto/btc/tw/addresses.py +++ b/mmgen/proto/btc/tw/addresses.py @@ -62,8 +62,7 @@ class BitcoinTwAddresses(BitcoinTwView, TwAddresses, BitcoinTwRPC): qmsg('done') qmsg_r('Getting received funds data...') - # args: 1:minconf, 2:include_empty, 3:include_watchonly, 4:include_immature_coinbase (>=v23.0.0) - for d in await self.rpc.call('listreceivedbylabel', 1, True, True): + for d in await self.rpc.icall('listreceivedbylabel', include_empty=True): label = get_obj(TwLabel, proto=self.proto, text=d['label']) if label: assert label.mmid in addrs, f'{label.mmid!r} not found in addrlist!' diff --git a/mmgen/proto/btc/tw/txhistory.py b/mmgen/proto/btc/tw/txhistory.py index b3a7d032..d1ff24c1 100755 --- a/mmgen/proto/btc/tw/txhistory.py +++ b/mmgen/proto/btc/tw/txhistory.py @@ -275,19 +275,10 @@ class BitcoinTwTxHistory(BitcoinTwView, TwTxHistory, BitcoinTwRPC): blockhash = ( await self.rpc.call('getblockhash', self.sinceblock) if self.sinceblock else '') - # bitcoin-cli help listsinceblock: - # Arguments: - # 1. blockhash (string, optional) If set, the block hash to list transactions since, - # otherwise list all transactions. - # 2. target_confirmations (numeric, optional, default=1) Return the nth block hash from the main - # chain. e.g. 1 would mean the best block hash. Note: this is not used - # as a filter, but only affects [lastblock] in the return value - # 3. include_watchonly (boolean, optional, default=true for watch-only wallets, otherwise - # false) Include transactions to watch-only addresses - # 4. include_removed (boolean, optional, default=true) Show transactions that were removed - # due to a reorg in the "removed" array (not guaranteed to work on - # pruned nodes) - return (await self.rpc.call('listsinceblock', blockhash, 1, True, False))['transactions'] + return (await self.rpc.icall( + 'listsinceblock', + blockhash = blockhash, + include_removed = False))['transactions'] async def gen_data(self, rpc_data, lbl_id):