main_txsend.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2021 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 .common import *
  22. opts_data = {
  23. 'sets': [('yes', True, 'quiet', True)],
  24. 'text': {
  25. 'desc': f'Send a signed {g.proj_name} cryptocoin transaction',
  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. if len(cmd_args) == 1:
  39. infile = cmd_args[0]
  40. check_infile(infile)
  41. else:
  42. opts.usage()
  43. if not opt.status:
  44. do_license_msg()
  45. async def main():
  46. from .tx import MMGenTX
  47. tx = MMGenTX.Signed(
  48. filename = infile,
  49. quiet_open = True,
  50. tw = await MMGenTX.Signed.get_tracking_wallet(infile) )
  51. from .rpc import rpc_init
  52. tx.rpc = await rpc_init(tx.proto)
  53. vmsg(f'Signed transaction file {infile!r} is valid')
  54. if opt.status:
  55. if tx.coin_txid:
  56. qmsg(f'{tx.proto.coin} txid: {tx.coin_txid.hl()}')
  57. await tx.get_status(status=True)
  58. sys.exit(0)
  59. if not opt.yes:
  60. tx.view_with_prompt('View transaction details?')
  61. if tx.add_comment(): # edits an existing comment, returns true if changed
  62. tx.write_to_file(ask_write_default_yes=True)
  63. await tx.send(exit_on_fail=True)
  64. tx.write_to_file(ask_overwrite=False,ask_write=False)
  65. tx.print_contract_addr()
  66. run_session(main())