main_txsend.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2019 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 = {
  23. 'sets': [('yes', True, 'quiet', True)],
  24. 'text': {
  25. 'desc': 'Send a signed {pnm} cryptocoin transaction'.format(pnm=g.proj_name),
  26. 'usage': '[opts] <signed transaction file>',
  27. 'options': """
  28. -h, --help Print this help message
  29. --, --longhelp Print help message for long options (common options)
  30. -d, --outdir= d Specify an alternate directory 'd' for output
  31. -q, --quiet Suppress warnings; overwrite files without prompting
  32. -s, --status Get status of a sent transaction
  33. -y, --yes Answer 'yes' to prompts, suppress non-essential output
  34. """
  35. }
  36. }
  37. cmd_args = opts.init(opts_data)
  38. rpc_init()
  39. if len(cmd_args) == 1:
  40. infile = cmd_args[0]; check_infile(infile)
  41. else: opts.usage()
  42. if not opt.status: do_license_msg()
  43. from mmgen.tx import *
  44. tx = MMGenTX(infile,quiet_open=True) # sig check performed here
  45. vmsg("Signed transaction file '{}' is valid".format(infile))
  46. if not tx.marked_signed():
  47. die(1,'Transaction is not signed!')
  48. if opt.status:
  49. if tx.coin_txid: qmsg('{} txid: {}'.format(g.coin,tx.coin_txid.hl()))
  50. tx.get_status(status=True)
  51. sys.exit(0)
  52. if not opt.yes:
  53. tx.view_with_prompt('View transaction data?')
  54. if tx.add_comment(): # edits an existing comment, returns true if changed
  55. tx.write_to_file(ask_write_default_yes=True)
  56. tx.send(exit_on_fail=True)
  57. tx.write_to_file(ask_overwrite=False,ask_write=False)
  58. if hasattr(tx,'token_addr'):
  59. msg('Contract address: {}'.format(tx.token_addr.hl()))