base_proto.bitcoin.rpc: add icall for gettransaction

This commit is contained in:
The MMGen Project 2022-05-23 16:28:57 +00:00
commit 85a9673d15
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
4 changed files with 41 additions and 4 deletions

View file

@ -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

View file

@ -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:

View file

@ -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:

View file

@ -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]