mmgen-txsend 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/usr/bin/env python
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C) 2013 by 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 Bitcoin transaction to the network
  20. """
  21. import sys
  22. <<<<<<< HEAD
  23. #from hashlib import sha256
  24. =======
  25. >>>>>>> my
  26. from mmgen.Opts import *
  27. from mmgen.license import *
  28. from mmgen.config import *
  29. from mmgen.tx import *
  30. <<<<<<< HEAD
  31. from mmgen.utils import msg,check_infile,get_lines_from_file,confirm_or_exit
  32. =======
  33. from mmgen.utils import msg,check_opts,check_infile,get_lines_from_file,confirm_or_exit
  34. >>>>>>> my
  35. prog_name = sys.argv[0].split("/")[-1]
  36. help_data = {
  37. 'prog_name': prog_name,
  38. <<<<<<< HEAD
  39. 'desc': "Sign a Bitcoin transaction generated by mmgen-txcreate",
  40. 'usage': "[opts] <transaction file>",
  41. 'options': """
  42. -h, --help Print this help message
  43. -q, --quiet Suppress warnings; overwrite files without asking
  44. """
  45. }
  46. short_opts = "hq"
  47. long_opts = "help","quiet"
  48. opts,cmd_args = process_opts(sys.argv,help_data,short_opts,long_opts)
  49. =======
  50. 'desc': "Send a Bitcoin transaction signed by mmgen-txsign",
  51. 'usage': "[opts] <signed transaction file>",
  52. 'options': """
  53. -h, --help Print this help message
  54. -d, --outdir d Specify an alternate directory 'd' for output
  55. -q, --quiet Suppress warnings; overwrite files without asking
  56. """
  57. }
  58. short_opts = "hd:q"
  59. long_opts = "help","outdir=","quiet"
  60. opts,cmd_args = process_opts(sys.argv,help_data,short_opts,long_opts)
  61. # Exits on invalid input
  62. check_opts(opts, ('outdir',))
  63. >>>>>>> my
  64. if len(cmd_args) == 1:
  65. infile = cmd_args[0]
  66. check_infile(infile)
  67. else: usage(help_data)
  68. # Begin execution
  69. <<<<<<< HEAD
  70. c = connect_to_bitcoind()
  71. tx_sig = get_lines_from_file(infile,"signed transaction")[0]
  72. =======
  73. try:
  74. metadata,tx_sig = get_lines_from_file(infile,"signed transaction")
  75. except:
  76. msg("Invalid signed transaction file")
  77. sys.exit(3)
  78. metadata = metadata.split()
  79. if len(metadata) != 3:
  80. msg("Invalid file header")
  81. sys.exit(3)
  82. >>>>>>> my
  83. from binascii import unhexlify
  84. try: unhexlify(tx_sig)
  85. except:
  86. <<<<<<< HEAD
  87. msg("Invalid transaction data")
  88. sys.exit(3)
  89. msg("Successfully opened signed transaction file '%s'" % infile)
  90. confirm_or_exit("", "broadcast this transaction to the network")
  91. msg("Sending transaction")
  92. try:
  93. tx = c.sendrawtransaction(tx_sig)
  94. =======
  95. msg("Invalid signed transaction data")
  96. sys.exit(3)
  97. if not 'quiet' in opts: do_license_msg()
  98. msg("Signed transaction file '%s' appears valid" % infile)
  99. warn = "Once this transaction is sent, there's no taking it back!"
  100. what = "broadcast this transaction to the network"
  101. expect = "yes, i really want to do this".upper()
  102. confirm_or_exit(warn, what, expect)
  103. msg("Sending transaction")
  104. c = connect_to_bitcoind()
  105. try:
  106. tx = c.sendrawtransaction(tx_sig)
  107. # tx = "deadbeef"
  108. >>>>>>> my
  109. except:
  110. msg("Unable to send transaction")
  111. sys.exit(3)
  112. msg("Transaction sent: %s" % tx)
  113. <<<<<<< HEAD
  114. print_sent_tx_to_file(tx)
  115. =======
  116. print_sent_tx_to_file(tx,metadata,opts)
  117. >>>>>>> my