|
|
@@ -23,7 +23,7 @@ mmgen-txsend: Broadcast a transaction signed by 'mmgen-txsign' to the network
|
|
|
import sys
|
|
|
|
|
|
from .cfg import gc, Config
|
|
|
-from .util import async_run, die
|
|
|
+from .util import async_run, die, is_int
|
|
|
|
|
|
opts_data = {
|
|
|
'sets': [
|
|
|
@@ -32,7 +32,11 @@ opts_data = {
|
|
|
],
|
|
|
'text': {
|
|
|
'desc': f'Send a signed {gc.proj_name} cryptocoin transaction',
|
|
|
- 'usage': '[opts] [signed transaction file]',
|
|
|
+ 'usage2': [
|
|
|
+ '[opts] <signed transaction file>',
|
|
|
+ '[opts] --autosign',
|
|
|
+ '[opts] --autosign (--status | --receipt) [IDX]',
|
|
|
+ ],
|
|
|
'options': """
|
|
|
-h, --help Print this help message
|
|
|
--, --longhelp Print help message for long (global) options
|
|
|
@@ -65,6 +69,12 @@ opts_data = {
|
|
|
Use special value ‘env’ to honor *_PROXY environment vars
|
|
|
instead.
|
|
|
-y, --yes Answer 'yes' to prompts, suppress non-essential output
|
|
|
+""",
|
|
|
+ 'notes': """
|
|
|
+With --autosign, combined with --status or --receipt, the optional IDX arg
|
|
|
+represents an index into the list of sent transaction files on the removable
|
|
|
+device, in reverse chronological order. ‘0’ (the default) specifies the
|
|
|
+last sent transaction, ‘1’ the next-to-last, and so on.
|
|
|
"""
|
|
|
},
|
|
|
'code': {
|
|
|
@@ -88,27 +98,38 @@ if cfg.dump_hex and cfg.dump_hex != '-':
|
|
|
from .fileutil import check_outfile_dir
|
|
|
check_outfile_dir(cfg.dump_hex)
|
|
|
|
|
|
+post_send_op = cfg.status or cfg.receipt
|
|
|
+
|
|
|
asi = None
|
|
|
|
|
|
+def init_autosign(arg):
|
|
|
+ global asi, si, infile, tx_idx
|
|
|
+ from .tx.util import mount_removable_device
|
|
|
+ from .autosign import Signable
|
|
|
+ asi = mount_removable_device(cfg)
|
|
|
+ si = Signable.automount_transaction(asi)
|
|
|
+ if cfg.abort:
|
|
|
+ si.shred_abortable() # prompts user, then raises exception or exits
|
|
|
+ elif post_send_op:
|
|
|
+ if si.unsent:
|
|
|
+ die(1, 'Transaction is unsent')
|
|
|
+ if si.unsigned:
|
|
|
+ die(1, 'Transaction is unsigned')
|
|
|
+ if not is_int(arg):
|
|
|
+ die(2, f'{arg}: invalid transaction index (must be a non-negative integer)')
|
|
|
+ tx_idx = int(arg)
|
|
|
+ else:
|
|
|
+ infile = si.get_unsent()
|
|
|
+ cfg._util.qmsg(f'Got signed transaction file ‘{infile}’')
|
|
|
+
|
|
|
match cfg._args:
|
|
|
+ case [arg] if cfg.autosign and post_send_op:
|
|
|
+ init_autosign(arg)
|
|
|
+ case [] if cfg.autosign:
|
|
|
+ init_autosign(0)
|
|
|
case [infile]:
|
|
|
from .fileutil import check_infile
|
|
|
check_infile(infile)
|
|
|
- case [] if cfg.autosign:
|
|
|
- from .tx.util import mount_removable_device
|
|
|
- from .autosign import Signable
|
|
|
- asi = mount_removable_device(cfg)
|
|
|
- si = Signable.automount_transaction(asi)
|
|
|
- if cfg.abort:
|
|
|
- si.shred_abortable() # prompts user, then raises exception or exits
|
|
|
- elif cfg.status or cfg.receipt:
|
|
|
- if si.unsent:
|
|
|
- die(1, 'Transaction is unsent')
|
|
|
- if si.unsigned:
|
|
|
- die(1, 'Transaction is unsigned')
|
|
|
- else:
|
|
|
- infile = si.get_unsent()
|
|
|
- cfg._util.qmsg(f'Got signed transaction file ‘{infile}’')
|
|
|
case _:
|
|
|
cfg._usage()
|
|
|
|
|
|
@@ -122,8 +143,8 @@ async def main():
|
|
|
|
|
|
global cfg
|
|
|
|
|
|
- if (cfg.status or cfg.receipt) and cfg.autosign:
|
|
|
- tx = await si.get_last_created()
|
|
|
+ if cfg.autosign and post_send_op:
|
|
|
+ tx = await si.get_last_sent(idx=tx_idx)
|
|
|
else:
|
|
|
tx = await OnlineSignedTX(
|
|
|
cfg = cfg,
|
|
|
@@ -149,7 +170,7 @@ async def main():
|
|
|
await tx.post_send(asi)
|
|
|
sys.exit(0)
|
|
|
|
|
|
- if not (cfg.status or cfg.receipt):
|
|
|
+ if not post_send_op:
|
|
|
if tx.is_swap and not tx.check_swap_expiry():
|
|
|
die(1, 'Swap quote has expired. Please re-create the transaction')
|
|
|
|