main_txsend.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2024 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. from .cfg import gc,Config
  23. from .util import async_run
  24. opts_data = {
  25. 'sets': [('yes', True, 'quiet', True)],
  26. 'text': {
  27. 'desc': f'Send a signed {gc.proj_name} cryptocoin transaction',
  28. 'usage': '[opts] <signed transaction file>',
  29. 'options': """
  30. -h, --help Print this help message
  31. --, --longhelp Print help message for long options (common options)
  32. -d, --outdir= d Specify an alternate directory 'd' for output
  33. -q, --quiet Suppress warnings; overwrite files without prompting
  34. -s, --status Get status of a sent transaction
  35. -v, --verbose Be more verbose
  36. -y, --yes Answer 'yes' to prompts, suppress non-essential output
  37. """
  38. }
  39. }
  40. cfg = Config(opts_data=opts_data)
  41. if len(cfg._args) == 1:
  42. infile = cfg._args[0]
  43. from .fileutil import check_infile
  44. check_infile(infile)
  45. else:
  46. cfg._opts.usage()
  47. if not cfg.status:
  48. from .ui import do_license_msg
  49. do_license_msg(cfg)
  50. async def main():
  51. from .tx import OnlineSignedTX, SentTX
  52. tx = await OnlineSignedTX(
  53. cfg = cfg,
  54. filename = infile,
  55. quiet_open = True)
  56. from .rpc import rpc_init
  57. tx.rpc = await rpc_init(cfg,tx.proto)
  58. cfg._util.vmsg(f'Getting {tx.desc} ‘{tx.infile}’')
  59. if cfg.status:
  60. if tx.coin_txid:
  61. cfg._util.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 cfg.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. if await tx.send():
  69. tx2 = await SentTX(cfg=cfg, data=tx.__dict__)
  70. tx2.file.write(
  71. ask_overwrite = False,
  72. ask_write = False)
  73. tx2.print_contract_addr()
  74. async_run(main())