main_txdo.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env python
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2017 Philemon <mmgen-py@yandex.com>
  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.txcreate import *
  22. from mmgen.txsign import *
  23. def opts_data(): return {
  24. 'desc': 'Create, sign and send an {g.proj_name} transaction'.format(g=g),
  25. 'usage': '[opts] <addr,amt> ... [change addr] [addr file] ... [seed source] ...',
  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, --aug1hf Sign transaction for the Aug. 1 2017 UAHF chain
  31. -a, --tx-fee-adj= f Adjust transaction fee by factor 'f' (see below)
  32. -b, --brain-params=l,p Use seed length 'l' and hash preset 'p' for
  33. brainwallet input
  34. -B, --no-blank Don't blank screen before displaying unspent outputs
  35. -c, --comment-file= f Source the transaction's comment from file 'f'
  36. -C, --tx-confs= c Desired number of confirmations (default: {g.tx_confs})
  37. -d, --outdir= d Specify an alternate directory 'd' for output
  38. -e, --echo-passphrase Print passphrase to screen when typing it
  39. -f, --tx-fee= f Transaction fee, as a decimal {cu} amount or in
  40. satoshis per byte (an integer followed by 's').
  41. If omitted, bitcoind's 'estimatefee' will be used
  42. to calculate the fee.
  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. -l, --seed-len= l Specify wallet seed length of 'l' bits. This option
  47. is required only for brainwallet and incognito inputs
  48. with non-standard (< {g.seed_len}-bit) seed lengths.
  49. -k, --keys-from-file=f Provide additional keys for non-{pnm} addresses
  50. -K, --key-generator= m Use method 'm' for public key generation
  51. Options: {kgs}
  52. (default: {kg})
  53. -m, --minconf=n Minimum number of confirmations required to spend
  54. outputs (default: 1)
  55. -M, --mmgen-keys-from-file=f Provide keys for {pnm} addresses in a key-
  56. address file (output of '{pnl}-keygen'). Permits
  57. online signing without an {pnm} seed source. The
  58. key-address file is also used to verify {pnm}-to-{cu}
  59. mappings, so the user should record its checksum.
  60. -O, --old-incog-fmt Specify old-format incognito input
  61. -p, --hash-preset= p Use the scrypt hash parameters defined by preset 'p'
  62. for password hashing (default: '{g.hash_preset}')
  63. -P, --passwd-file= f Get {pnm} wallet passphrase from file 'f'
  64. -r, --rbf Make transaction BIP 125 (replace-by-fee) replaceable
  65. -q, --quiet Suppress warnings; overwrite files without prompting
  66. -v, --verbose Produce more verbose output
  67. -y, --yes Answer 'yes' to prompts, suppress non-essential output
  68. -z, --show-hash-presets Show information on available hash presets
  69. """.format(g=g,pnm=pnm,pnl=pnm.lower(),
  70. kgs=' '.join(['{}:{}'.format(n,k) for n,k in enumerate(g.key_generators,1)]),
  71. kg=g.key_generator,
  72. cu=g.coin
  73. ),
  74. 'notes': '\n' + txcreate_notes + fee_notes.format(g.coin) + txsign_notes
  75. }
  76. cmd_args = opts.init(opts_data)
  77. if opt.aug1hf: # TODO: remove in 0.9.4
  78. msg(yellow('The --aug1hf option is deprecated. Please use --coin=bch instead'))
  79. g.coin = 'BCH'
  80. seed_files = get_seed_files(opt,cmd_args)
  81. c = bitcoin_connection()
  82. do_license_msg()
  83. kal = get_keyaddrlist(opt)
  84. kl = get_keylist(opt)
  85. if kl and kal: kl.remove_dups(kal,key='wif')
  86. tx = txcreate(cmd_args,caller='txdo')
  87. txsign(opt,c,tx,seed_files,kl,kal)
  88. tx.write_to_file(ask_write=False)
  89. if tx.send(c):
  90. tx.write_to_file(ask_overwrite=False,ask_write=False)