main_txcreate.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2023 The MMGen Project <mmgen@tuta.io>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. mmgen-txcreate: Create a cryptocoin transaction with MMGen- and/or non-MMGen
  20. inputs and outputs
  21. """
  22. import mmgen.opts as opts
  23. from .globalvars import g
  24. from .opts import opt
  25. from .util import fmt_list,async_run
  26. opts_data = {
  27. 'sets': [('yes', True, 'quiet', True)],
  28. 'text': {
  29. 'desc': f'Create a transaction with outputs to specified coin or {g.proj_name} addresses',
  30. 'usage': '[opts] [<addr,amt> ...] <change addr, addrlist ID or addr type> [addr file ...]',
  31. 'options': """
  32. -h, --help Print this help message
  33. --, --longhelp Print help message for long options (common options)
  34. -a, --fee-adjust= f Adjust transaction fee by factor 'f' (see below)
  35. -B, --no-blank Don't blank screen before displaying unspent outputs
  36. -c, --comment-file=f Source the transaction's comment from file 'f'
  37. -C, --fee-estimate-confs=c Desired number of confirmations for fee estimation
  38. (default: {g.fee_estimate_confs})
  39. -d, --outdir= d Specify an alternate directory 'd' for output
  40. -D, --contract-data=D Path to hex-encoded contract data (ETH only)
  41. -E, --fee-estimate-mode=M Specify the network fee estimate mode. Choices:
  42. {fe_all}. Default: {fe_dfl!r}
  43. -f, --fee= f Transaction fee, as a decimal {cu} amount or as
  44. {fu} (an integer followed by {fl!r}).
  45. See FEE SPECIFICATION below. If omitted, fee will be
  46. calculated using network fee estimation.
  47. -g, --gas= g Specify start gas amount in Wei (ETH only)
  48. -i, --info Display unspent outputs and exit
  49. -I, --inputs= i Specify transaction inputs (comma-separated list of
  50. MMGen IDs or coin addresses). Note that ALL unspent
  51. outputs associated with each address will be included.
  52. -l, --locktime= t Lock time (block height or unix seconds) (default: 0)
  53. -L, --autochg-ignore-labels Ignore labels when autoselecting change addresses
  54. -m, --minconf= n Minimum number of confirmations required to spend
  55. outputs (default: 1)
  56. -q, --quiet Suppress warnings; overwrite files without prompting
  57. -r, --rbf Make transaction BIP 125 replaceable (replace-by-fee)
  58. -v, --verbose Produce more verbose output
  59. -V, --vsize-adj= f Adjust transaction's estimated vsize by factor 'f'
  60. -y, --yes Answer 'yes' to prompts, suppress non-essential output
  61. -X, --cached-balances Use cached balances (Ethereum only)
  62. """,
  63. 'notes': '\n{c}\n{F}\n{x}',
  64. },
  65. 'code': {
  66. 'options': lambda proto,help_notes,s: s.format(
  67. fu=help_notes('rel_fee_desc'),
  68. fl=help_notes('fee_spec_letters'),
  69. fe_all=fmt_list(g.autoset_opts['fee_estimate_mode'].choices,fmt='no_spc'),
  70. fe_dfl=g.autoset_opts['fee_estimate_mode'].choices[0],
  71. cu=proto.coin,
  72. g=g),
  73. 'notes': lambda help_notes,s: s.format(
  74. c = help_notes('txcreate'),
  75. F = help_notes('fee'),
  76. x = help_notes('txcreate_examples') )
  77. }
  78. }
  79. cmd_args = opts.init(opts_data)
  80. async def main():
  81. from .protocol import init_proto_from_opts
  82. proto = init_proto_from_opts(need_amt=True)
  83. from .tx import NewTX
  84. tx1 = await NewTX(proto=proto)
  85. from .rpc import rpc_init
  86. tx1.rpc = await rpc_init(proto)
  87. tx2 = await tx1.create(
  88. cmd_args = cmd_args,
  89. locktime = int(opt.locktime or 0),
  90. do_info = opt.info )
  91. tx2.file.write(
  92. ask_write = not opt.yes,
  93. ask_overwrite = not opt.yes,
  94. ask_write_default_yes = False )
  95. async_run(main())