main_txdo.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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-txdo: Create, sign and broadcast an online MMGen transaction
  20. """
  21. from mmgen.common import *
  22. opts_data = lambda: {
  23. 'desc': 'Create, sign and send an {g.proj_name} transaction'.format(g=g),
  24. 'usage': '[opts] <addr,amt> ... [change addr] [addr file] ... [seed source] ...',
  25. 'sets': ( ('yes', True, 'quiet', True), ),
  26. 'options': """
  27. -h, --help Print this help message
  28. --, --longhelp Print help message for long options (common options)
  29. -a, --tx-fee-adj= f Adjust transaction fee by factor 'f' (see below)
  30. -b, --brain-params=l,p Use seed length 'l' and hash preset 'p' for
  31. brainwallet input
  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, --echo-passphrase Print passphrase to screen when typing it
  38. -f, --tx-fee= f Transaction fee, as a decimal {cu} amount or as
  39. {fu} (an integer followed by {fl}).
  40. See FEE SPECIFICATION below. If omitted, fee will be
  41. calculated using network fee estimation.
  42. -g, --tx-gas= g Specify start gas amount in Wei (ETH only)
  43. -H, --hidden-incog-input-params=f,o Read hidden incognito data from file
  44. 'f' at offset 'o' (comma-separated)
  45. -i, --in-fmt= f Input is from wallet format 'f' (see FMT CODES below)
  46. -I, --inputs= i Specify transaction inputs (comma-separated list of
  47. MMGen IDs or coin addresses). Note that ALL unspent
  48. outputs associated with each address will be included.
  49. -l, --seed-len= l Specify wallet seed length of 'l' bits. This option
  50. is required only for brainwallet and incognito inputs
  51. with non-standard (< {g.seed_len}-bit) seed lengths.
  52. -k, --keys-from-file=f Provide additional keys for non-{pnm} addresses
  53. -K, --key-generator= m Use method 'm' for public key generation
  54. Options: {kgs}
  55. (default: {kg})
  56. -L, --locktime= t Lock time (block height or unix seconds) (default: 0)
  57. -m, --minconf=n Minimum number of confirmations required to spend
  58. outputs (default: 1)
  59. -M, --mmgen-keys-from-file=f Provide keys for {pnm} addresses in a key-
  60. address file (output of '{pnl}-keygen'). Permits
  61. online signing without an {pnm} seed source. The
  62. key-address file is also used to verify {pnm}-to-{cu}
  63. mappings, so the user should record its checksum.
  64. -O, --old-incog-fmt Specify old-format incognito input
  65. -p, --hash-preset= p Use the scrypt hash parameters defined by preset 'p'
  66. for password hashing (default: '{g.hash_preset}')
  67. -P, --passwd-file= f Get {pnm} wallet passphrase from file 'f'
  68. -r, --rbf Make transaction BIP 125 (replace-by-fee) replaceable
  69. -q, --quiet Suppress warnings; overwrite files without prompting
  70. -v, --verbose Produce more verbose output
  71. -V, --vsize-adj= f Adjust transaction's estimated vsize by factor 'f'
  72. -y, --yes Answer 'yes' to prompts, suppress non-essential output
  73. -z, --show-hash-presets Show information on available hash presets
  74. """,
  75. 'options_fmt_args': lambda: dict(
  76. g=g,pnm=g.proj_name,pnl=g.proj_name.lower(),
  77. kgs=' '.join(['{}:{}'.format(n,k) for n,k in enumerate(g.key_generators,1)]),
  78. fu=help_notes('rel_fee_desc'),
  79. fl=help_notes('fee_spec_letters'),
  80. kg=g.key_generator,
  81. cu=g.coin),
  82. 'notes': lambda: '\n' + help_notes('txcreate') + help_notes('fee') + help_notes('txsign')
  83. }
  84. cmd_args = opts.init(opts_data)
  85. rpc_init()
  86. from mmgen.tx import *
  87. from mmgen.txsign import *
  88. seed_files = get_seed_files(opt,cmd_args)
  89. kal = get_keyaddrlist(opt)
  90. kl = get_keylist(opt)
  91. if kl and kal: kl.remove_dup_keys(kal)
  92. tx = MMGenTX(caller='txdo')
  93. tx.create(cmd_args,int(opt.locktime or 0))
  94. if txsign(tx,seed_files,kl,kal):
  95. tx.write_to_file(ask_write=False)
  96. tx.send(exit_on_fail=True)
  97. tx.write_to_file(ask_overwrite=False,ask_write=False)
  98. if hasattr(tx,'token_addr'):
  99. msg('Contract address: {}'.format(tx.token_addr.hl()))
  100. else:
  101. die(2,'Transaction could not be signed')