main_txsend.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2016 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-txsend: Broadcast a transaction signed by 'mmgen-txsign' to the network
  20. """
  21. from mmgen.common import *
  22. from mmgen.tx import *
  23. opts_data = {
  24. 'desc': 'Send a Bitcoin transaction signed by {pnm}-txsign'.format(
  25. pnm=g.proj_name.lower()),
  26. 'usage': '[opts] <signed transaction file>',
  27. 'options': """
  28. -h, --help Print this help message
  29. -d, --outdir= d Specify an alternate directory 'd' for output
  30. -q, --quiet Suppress warnings; overwrite files without prompting
  31. """
  32. }
  33. cmd_args = opts.init(opts_data)
  34. if len(cmd_args) == 1:
  35. infile = cmd_args[0]; check_infile(infile)
  36. else: opts.usage()
  37. # Begin execution
  38. do_license_msg()
  39. tx = MMGenTX()
  40. tx.parse_tx_file(infile,'signed transaction data')
  41. c = bitcoin_connection()
  42. if not tx.check_signed(c):
  43. die(1,'Transaction has no signature!')
  44. qmsg("Signed transaction file '%s' is valid" % infile)
  45. tx.view_with_prompt('View transaction data?')
  46. if tx.add_comment(): # edits an existing comment, returns true if changed
  47. tx.write_to_file(ask_write_default_yes=True)
  48. warn = "Once this transaction is sent, there's no taking it back!"
  49. action = 'broadcast this transaction to the network'
  50. expect = 'YES, I REALLY WANT TO DO THIS'
  51. if opt.quiet: warn,expect = '','YES'
  52. confirm_or_exit(warn,action,expect)
  53. msg('Sending transaction')
  54. tx.send(c,bogus=True)
  55. tx.write_txid_to_file()