From 7a8652cd32dd1b4367dca3e9961e4316336a1e64 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 3 Jun 2022 12:32:32 +0000 Subject: [PATCH] minor changes and fixes --- mmgen/base_proto/bitcoin/tw/txhistory.py | 6 +++++- mmgen/main_tool.py | 5 ++++- mmgen/main_xmrwallet.py | 17 ++++++++--------- mmgen/rpc.py | 15 +++++++++++---- mmgen/tool/help.py | 7 ++++--- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/mmgen/base_proto/bitcoin/tw/txhistory.py b/mmgen/base_proto/bitcoin/tw/txhistory.py index 6c113a1e..5dc0a5fd 100755 --- a/mmgen/base_proto/bitcoin/tw/txhistory.py +++ b/mmgen/base_proto/bitcoin/tw/txhistory.py @@ -109,7 +109,11 @@ class BitcoinTwTransaction(BitcoinTwCommon): self.label = get_best_label() self.vsize = self.tx['decoded'].get('vsize') or self.tx['decoded']['size'] self.txid = CoinTxID(self.tx['txid']) - self.time = self.tx['time'] + # Though 'blocktime' is flagged as an “optional” field, it’s always present for transactions + # that are in the blockchain. However, Bitcoin Core wallet saves a record of broadcast but + # unconfirmed transactions, e.g. replaced transactions, and the 'blocktime' field is missing + # for these, so use 'time' as a fallback. + self.time = self.tx.get('blocktime') or self.tx['time'] def blockheight_disp(self,color): return ( diff --git a/mmgen/main_tool.py b/mmgen/main_tool.py index 71b51445..231d5f7f 100755 --- a/mmgen/main_tool.py +++ b/mmgen/main_tool.py @@ -362,4 +362,7 @@ if g.prog_name == 'mmgen-tool' and not opt._lock: if type(ret).__name__ == 'coroutine': ret = run_session(ret) - process_result(ret,pager='pager' in kwargs and kwargs['pager'],print_result=True) + process_result( + ret, + pager = kwargs.get('pager'), + print_result = True ) diff --git a/mmgen/main_xmrwallet.py b/mmgen/main_xmrwallet.py index 706534c4..e8519dbe 100755 --- a/mmgen/main_xmrwallet.py +++ b/mmgen/main_xmrwallet.py @@ -31,8 +31,8 @@ opts_data = { 'usage2': [ '[opts] create [wallets]', '[opts] sync [wallets]', - '[opts] transfer ', - '[opts] sweep ', + '[opts] transfer TRANSFER_SPEC', + '[opts] sweep SWEEP_SPEC', '[opts] relay ', ], 'options': """ @@ -83,7 +83,7 @@ relay - relay a transaction from a transaction file created using 'sweep' or 'transfer' with the --do-not-relay option - CREATE AND SYNC OPERATION NOTES + 'CREATE' AND 'SYNC' OPERATION NOTES These operations take an optional `wallets` argument: one or more address indexes (expressed as a comma-separated list, hyphenated range, or both) @@ -91,10 +91,9 @@ in the specified key-address file, each corresponding to a Monero wallet to be created or synced. If omitted, all wallets are operated upon. - TRANSFER OPERATION NOTES + 'TRANSFER' OPERATION NOTES -The transfer operation takes a `transfer specifier` arg with the following -format: +The transfer operation takes a TRANSFER_SPEC arg with the following format: SOURCE:ACCOUNT:ADDRESS,AMOUNT @@ -102,9 +101,9 @@ where SOURCE is a wallet number; ACCOUNT the source account index; and ADDRESS and AMOUNT the destination Monero address and XMR amount, respectively. - SWEEP OPERATION NOTES + 'SWEEP' OPERATION NOTES -The sweep operation takes a `sweep specifier` arg with the following format: +The sweep operation takes a SWEEP_SPEC arg with the following format: SOURCE:ACCOUNT[,DEST] @@ -123,7 +122,7 @@ Note that multiple sweep operations may be required to sweep all the funds in an account. - RELAY OPERATION NOTES + 'RELAY' OPERATION NOTES By default, transactions are relayed to a monerod running on localhost at the default RPC port. To relay transactions to a remote or non-default monerod diff --git a/mmgen/rpc.py b/mmgen/rpc.py index bd8de2a4..2335f7d3 100755 --- a/mmgen/rpc.py +++ b/mmgen/rpc.py @@ -60,6 +60,13 @@ def dmsg_rpc(fs,data=None,is_json=False): fs.format(pp_fmt(json.loads(data) if is_json else data)) ) +def dmsg_rpc_backend(host_url,host_path,payload): + if g.debug_rpc: + msg( + f'\n RPC URL: {host_url}{host_path}' + + f'\n RPC PAYLOAD data (httplib) ==>' + + f'\n{pp_fmt(payload)}\n' ) + class IPPort(str,Hilite,InitErrors): color = 'yellow' width = 0 @@ -124,7 +131,7 @@ class RPCBackends: self.auth = None async def run(self,payload,timeout,host_path): - dmsg_rpc('\n RPC PAYLOAD data (aiohttp) ==>\n{}\n',payload) + dmsg_rpc_backend(self.host_url,host_path,payload) async with self.session.post( url = self.host_url + host_path, auth = self.auth, @@ -155,7 +162,7 @@ class RPCBackends: }) async def run(self,payload,timeout,host_path): - dmsg_rpc('\n RPC PAYLOAD data (requests) ==>\n{}\n',payload) + dmsg_rpc_backend(self.host_url,host_path,payload) res = self.session.post( url = self.host_url + host_path, data = json.dumps(payload,cls=json_encoder), @@ -184,7 +191,7 @@ class RPCBackends: auth_str_b64 )) async def run(self,payload,timeout,host_path): - dmsg_rpc('\n RPC PAYLOAD data (httplib) ==>\n{}\n',payload) + dmsg_rpc_backend(self.host_url,host_path,payload) if timeout: import http.client @@ -237,7 +244,7 @@ class RPCBackends: data = json.dumps(payload,cls=json_encoder) if len(data) > self.arg_max: return self.httplib(payload,timeout=timeout) - dmsg_rpc('\n RPC PAYLOAD data (curl) ==>\n{}\n',payload) + dmsg_rpc_backend(self.host_url,host_path,payload) exec_cmd = [ 'curl', '--proxy', f'socks5h://{self.proxy}' if self.proxy else '', diff --git a/mmgen/tool/help.py b/mmgen/tool/help.py index 0eeaa4b4..3697f3ae 100755 --- a/mmgen/tool/help.py +++ b/mmgen/tool/help.py @@ -64,9 +64,10 @@ def usage(cmdname=None,exit_val=1): m1 = """ USAGE INFORMATION FOR MMGEN-TOOL COMMANDS: - Unquoted arguments are mandatory - Quoted arguments are optional, default values will be used - Argument types and default values are shown in square brackets + Arguments with only type specified in square brackets are required + + Arguments with both type and default value specified in square brackets are + optional; if used, they must be supplied in the form ‘name=value’ """ m2 = """