main_txcreate.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2024 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. from .cfg import gc,Config
  23. from .util import fmt_list,async_run
  24. opts_data = {
  25. 'sets': [('yes', True, 'quiet', True)],
  26. 'text': {
  27. 'desc': f'Create a transaction with outputs to specified coin or {gc.proj_name} addresses',
  28. 'usage': '[opts] [<addr,amt> ...] <change addr, addrlist ID or addr type> [addr file ...]',
  29. 'options': """
  30. -h, --help Print this help message
  31. --, --longhelp Print help message for long options (common options)
  32. -a, --autosign Create a transaction for offline autosigning (see
  33. ‘mmgen-autosign’). The removable device is mounted and
  34. unmounted automatically
  35. -A, --fee-adjust= f Adjust transaction fee by factor 'f' (see below)
  36. -B, --no-blank Don't blank screen before displaying unspent outputs
  37. -c, --comment-file=f Source the transaction's comment from file 'f'
  38. -C, --fee-estimate-confs=c Desired number of confirmations for fee estimation
  39. (default: {cfg.fee_estimate_confs})
  40. -d, --outdir= d Specify an alternate directory 'd' for output
  41. -D, --contract-data=D Path to hex-encoded contract data (ETH only)
  42. -E, --fee-estimate-mode=M Specify the network fee estimate mode. Choices:
  43. {fe_all}. Default: {fe_dfl!r}
  44. -f, --fee= f Transaction fee, as a decimal {cu} amount or as
  45. {fu} (an integer followed by {fl!r}).
  46. See FEE SPECIFICATION below. If omitted, fee will be
  47. calculated using network fee estimation.
  48. -g, --gas= g Specify start gas amount in Wei (ETH only)
  49. -i, --info Display unspent outputs and exit
  50. -I, --inputs= i Specify transaction inputs (comma-separated list of
  51. MMGen IDs or coin addresses). Note that ALL unspent
  52. outputs associated with each address will be included.
  53. -l, --locktime= t Lock time (block height or unix seconds) (default: 0)
  54. -L, --autochg-ignore-labels Ignore labels when autoselecting change addresses
  55. -m, --minconf= n Minimum number of confirmations required to spend
  56. outputs (default: 1)
  57. -q, --quiet Suppress warnings; overwrite files without prompting
  58. -R, --no-rbf Make transaction non-replaceable (non-replace-by-fee
  59. according to BIP 125)
  60. -v, --verbose Produce more verbose output
  61. -V, --vsize-adj= f Adjust transaction's estimated vsize by factor 'f'
  62. -y, --yes Answer 'yes' to prompts, suppress non-essential output
  63. -X, --cached-balances Use cached balances (Ethereum only)
  64. """,
  65. 'notes': '\n{c}\n{F}\n{x}',
  66. },
  67. 'code': {
  68. 'options': lambda cfg,proto,help_notes,s: s.format(
  69. fu=help_notes('rel_fee_desc'),
  70. fl=help_notes('fee_spec_letters'),
  71. fe_all=fmt_list(cfg._autoset_opts['fee_estimate_mode'].choices,fmt='no_spc'),
  72. fe_dfl=cfg._autoset_opts['fee_estimate_mode'].choices[0],
  73. cu=proto.coin,
  74. cfg=cfg),
  75. 'notes': lambda cfg,help_notes,s: s.format(
  76. c = help_notes('txcreate'),
  77. F = help_notes('fee'),
  78. x = help_notes('txcreate_examples') )
  79. }
  80. }
  81. cfg = Config(opts_data=opts_data)
  82. async def main():
  83. if cfg.autosign:
  84. from .tx.util import mount_removable_device
  85. from .autosign import Signable
  86. asi = mount_removable_device(cfg)
  87. Signable.automount_transaction(asi).check_create_ok()
  88. from .tx import NewTX
  89. tx1 = await NewTX(cfg=cfg,proto=cfg._proto)
  90. from .rpc import rpc_init
  91. tx1.rpc = await rpc_init(cfg)
  92. tx2 = await tx1.create(
  93. cmd_args = cfg._args,
  94. locktime = int(cfg.locktime or 0),
  95. do_info = cfg.info )
  96. tx2.file.write(
  97. outdir = asi.txauto_dir if cfg.autosign else None,
  98. ask_write = not cfg.yes,
  99. ask_overwrite = not cfg.yes,
  100. ask_write_default_yes = False)
  101. async_run(main())