main_txsend.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python
  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-txsend: Broadcast a transaction signed by 'mmgen-txsign' to the network
  20. """
  21. from mmgen.common import *
  22. opts_data = lambda: {
  23. 'desc': 'Send a cryptocoin transaction signed by {pnm}-txsign'.format(pnm=g.proj_name.lower()),
  24. 'usage': '[opts] <signed transaction file>',
  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. -d, --outdir= d Specify an alternate directory 'd' for output
  30. -q, --quiet Suppress warnings; overwrite files without prompting
  31. -s, --status Get status of a sent transaction
  32. -y, --yes Answer 'yes' to prompts, suppress non-essential output
  33. """
  34. }
  35. cmd_args = opts.init(opts_data)
  36. rpc_init()
  37. if len(cmd_args) == 1:
  38. infile = cmd_args[0]; check_infile(infile)
  39. else: opts.usage()
  40. if not opt.status: do_license_msg()
  41. from mmgen.tx import *
  42. tx = MMGenTX(infile,silent_open=True) # sig check performed here
  43. vmsg("Signed transaction file '%s' is valid" % infile)
  44. if not tx.marked_signed():
  45. die(1,'Transaction is not signed!')
  46. if opt.status:
  47. if tx.coin_txid: qmsg('{} txid: {}'.format(g.coin,tx.coin_txid.hl()))
  48. tx.get_status(status=True)
  49. sys.exit(0)
  50. if not opt.yes:
  51. tx.view_with_prompt('View transaction data?')
  52. if tx.add_comment(): # edits an existing comment, returns true if changed
  53. tx.write_to_file(ask_write_default_yes=True)
  54. tx.send(exit_on_fail=True)
  55. tx.write_to_file(ask_overwrite=False,ask_write=False)