main_txsend.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2023 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. import sys
  22. import mmgen.opts as opts
  23. from .globalvars import g
  24. from .opts import opt
  25. from .util import vmsg,qmsg,async_run
  26. opts_data = {
  27. 'sets': [('yes', True, 'quiet', True)],
  28. 'text': {
  29. 'desc': f'Send a signed {g.proj_name} cryptocoin transaction',
  30. 'usage': '[opts] <signed transaction file>',
  31. 'options': """
  32. -h, --help Print this help message
  33. --, --longhelp Print help message for long options (common options)
  34. -d, --outdir= d Specify an alternate directory 'd' for output
  35. -q, --quiet Suppress warnings; overwrite files without prompting
  36. -s, --status Get status of a sent transaction
  37. -y, --yes Answer 'yes' to prompts, suppress non-essential output
  38. """
  39. }
  40. }
  41. cmd_args = opts.init(opts_data)
  42. if len(cmd_args) == 1:
  43. infile = cmd_args[0]
  44. from .fileutil import check_infile
  45. check_infile(infile)
  46. else:
  47. opts.usage()
  48. if not opt.status:
  49. from .ui import do_license_msg
  50. do_license_msg()
  51. async def main():
  52. from .tx import OnlineSignedTX
  53. tx = await OnlineSignedTX(
  54. filename = infile,
  55. quiet_open = True )
  56. from .rpc import rpc_init
  57. tx.rpc = await rpc_init(tx.proto)
  58. vmsg(f'Signed transaction file {infile!r} is valid')
  59. if opt.status:
  60. if tx.coin_txid:
  61. qmsg(f'{tx.proto.coin} txid: {tx.coin_txid.hl()}')
  62. await tx.status.display(usr_req=True)
  63. sys.exit(0)
  64. if not opt.yes:
  65. tx.info.view_with_prompt('View transaction details?')
  66. if tx.add_comment(): # edits an existing comment, returns true if changed
  67. tx.file.write(ask_write_default_yes=True)
  68. await tx.send(exit_on_fail=True)
  69. tx.file.write(ask_overwrite=False,ask_write=False)
  70. tx.print_contract_addr()
  71. async_run(main())