From 85a9673d151f71a2b109f8d32224ff94bf68834b Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 23 May 2022 16:28:57 +0000 Subject: [PATCH] base_proto.bitcoin.rpc: add icall for `gettransaction` --- mmgen/base_proto/bitcoin/rpc.py | 18 ++++++++++++++++++ mmgen/base_proto/bitcoin/tx/status.py | 18 +++++++++++++++--- mmgen/rpc.py | 7 +++++++ mmgen/tw/common.py | 2 +- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/mmgen/base_proto/bitcoin/rpc.py b/mmgen/base_proto/bitcoin/rpc.py index f3837976..59c75ce3 100755 --- a/mmgen/base_proto/bitcoin/rpc.py +++ b/mmgen/base_proto/bitcoin/rpc.py @@ -41,6 +41,16 @@ class CallSigs: load_on_startup # 7. load_on_startup ) + @classmethod + def gettransaction(cls,txid,include_watchonly,verbose): + return ( + 'gettransaction', + txid, # 1. transaction id + include_watchonly, # 2. optional, default=true for watch-only wallets, otherwise false + verbose, # 3. optional, default=false -- include a `decoded` field containing + # the decoded transaction (equivalent to RPC decoderawtransaction) + ) + class litecoin_core(bitcoin_core): @classmethod @@ -52,6 +62,14 @@ class CallSigs: blank, # 3. blank (no keys or seed) ) + @classmethod + def gettransaction(cls,txid,include_watchonly,verbose): + return ( + 'gettransaction', + txid, # 1. transaction id + include_watchonly, # 2. optional, default=true for watch-only wallets, otherwise false + ) + class bitcoin_cash_node(litecoin_core): pass diff --git a/mmgen/base_proto/bitcoin/tx/status.py b/mmgen/base_proto/bitcoin/tx/status.py index e956f384..76efe679 100755 --- a/mmgen/base_proto/bitcoin/tx/status.py +++ b/mmgen/base_proto/bitcoin/tx/status.py @@ -29,7 +29,11 @@ class Status(TxBase.Status): async def is_in_wallet(): try: - ret = await tx.rpc.call('gettransaction',tx.coin_txid) + ret = await tx.rpc.icall( + 'gettransaction', + txid = tx.coin_txid, + include_watchonly = True, + verbose = False ) except: return False if ret.get('confirmations',0) > 0: @@ -54,7 +58,11 @@ class Status(TxBase.Status): if await is_in_mempool(): return False try: - ret = await tx.rpc.call('gettransaction',tx.coin_txid) + ret = await tx.rpc.icall( + 'gettransaction', + txid = tx.coin_txid, + include_watchonly = True, + verbose = False ) except: return False else: @@ -67,7 +75,11 @@ class Status(TxBase.Status): if await is_in_mempool(): if usr_req: - d = await tx.rpc.call('gettransaction',tx.coin_txid) + d = await tx.rpc.icall( + 'gettransaction', + txid = tx.coin_txid, + include_watchonly = True, + verbose = False ) rep = ('' if d.get('bip125-replaceable') == 'yes' else 'NOT ') + 'replaceable' t = d['timereceived'] if opt.quiet: diff --git a/mmgen/rpc.py b/mmgen/rpc.py index ccabee51..2039d8d4 100755 --- a/mmgen/rpc.py +++ b/mmgen/rpc.py @@ -386,6 +386,13 @@ class RPCClient(MMGenObject): timeout = timeout, wallet = wallet ) + def gathered_icall(self,method,args_list,timeout=None,wallet=None): + return self.gathered_call( + method, + [getattr(self.call_sigs,method)(*a)[1:] for a in args_list], + timeout = timeout, + wallet = wallet ) + async def process_http_resp(self,coro,batch=False): text,status = await coro if status == 200: diff --git a/mmgen/tw/common.py b/mmgen/tw/common.py index 6468a1fa..91c68d98 100755 --- a/mmgen/tw/common.py +++ b/mmgen/tw/common.py @@ -91,7 +91,7 @@ class TwCommon: if us and us[0].date is None: # 'blocktime' differs from 'time', is same as getblockheader['time'] dates = [ o.get('blocktime',0) - for o in await rpc.gathered_call('gettransaction',[(o.txid,) for o in us]) ] + for o in await rpc.gathered_icall('gettransaction',[(o.txid,True,False) for o in us]) ] for idx,o in enumerate(us): o.date = dates[idx]