main_txcreate.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2018 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 mmgen.common import *
  23. opts_data = lambda: {
  24. 'desc': 'Create a transaction with outputs to specified coin or {g.proj_name} addresses'.format(g=g),
  25. 'usage': '[opts] <addr,amt> ... [change addr] [addr file] ...',
  26. 'sets': ( ('yes', True, 'quiet', True), ),
  27. 'options': """
  28. -h, --help Print this help message
  29. --, --longhelp Print help message for long options (common options)
  30. -a, --tx-fee-adj= f Adjust transaction fee by factor 'f' (see below)
  31. -B, --no-blank Don't blank screen before displaying unspent outputs
  32. -c, --comment-file=f Source the transaction's comment from file 'f'
  33. -C, --tx-confs= c Desired number of confirmations (default: {g.tx_confs})
  34. -d, --outdir= d Specify an alternate directory 'd' for output
  35. -D, --contract-data=D Path to hex-encoded contract data (ETH only)
  36. -f, --tx-fee= f Transaction fee, as a decimal {cu} amount or as
  37. {fu} (an integer followed by {fl}).
  38. See FEE SPECIFICATION below. If omitted, fee will be
  39. calculated using network fee estimation.
  40. -g, --tx-gas= g Specify start gas amount in Wei (ETH only)
  41. -i, --info Display unspent outputs and exit
  42. -I, --inputs= i Specify transaction inputs (comma-separated list of
  43. MMGen IDs or coin addresses). Note that ALL unspent
  44. outputs associated with each address will be included.
  45. -L, --locktime= t Lock time (block height or unix seconds) (default: 0)
  46. -m, --minconf= n Minimum number of confirmations required to spend
  47. outputs (default: 1)
  48. -q, --quiet Suppress warnings; overwrite files without prompting
  49. -r, --rbf Make transaction BIP 125 replaceable (replace-by-fee)
  50. -v, --verbose Produce more verbose output
  51. -V, --vsize-adj= f Adjust transaction's estimated vsize by factor 'f'
  52. -y, --yes Answer 'yes' to prompts, suppress non-essential output
  53. """,
  54. 'options_fmt_args': lambda: dict(
  55. g=g,cu=g.coin,
  56. fu=help_notes('rel_fee_desc'),
  57. fl=help_notes('fee_spec_letters') ),
  58. 'notes': lambda: '\n' + help_notes('txcreate') + help_notes('fee')
  59. }
  60. cmd_args = opts.init(opts_data)
  61. rpc_init()
  62. from mmgen.tx import MMGenTX
  63. tx = MMGenTX()
  64. tx.create(cmd_args,int(opt.locktime or 0),do_info=opt.info)
  65. tx.write_to_file(ask_write=not opt.yes,ask_overwrite=not opt.yes,ask_write_default_yes=False)