main_txcreate.py 4.0 KB

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