main_txsend.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. -y, --yes Answer 'yes' to prompts, suppress non-essential output
  36. """
  37. }
  38. }
  39. cfg = Config(opts_data=opts_data)
  40. if len(cfg._args) == 1:
  41. infile = cfg._args[0]
  42. from .fileutil import check_infile
  43. check_infile(infile)
  44. else:
  45. cfg._opts.usage()
  46. if not cfg.status:
  47. from .ui import do_license_msg
  48. do_license_msg(cfg)
  49. async def main():
  50. from .tx import OnlineSignedTX
  51. tx = await OnlineSignedTX(
  52. cfg = cfg,
  53. filename = infile,
  54. quiet_open = True )
  55. from .rpc import rpc_init
  56. tx.rpc = await rpc_init(cfg,tx.proto)
  57. cfg._util.vmsg(f'Signed transaction file {infile!r} is valid')
  58. if cfg.status:
  59. if tx.coin_txid:
  60. cfg._util.qmsg(f'{tx.proto.coin} txid: {tx.coin_txid.hl()}')
  61. await tx.status.display(usr_req=True)
  62. sys.exit(0)
  63. if not cfg.yes:
  64. tx.info.view_with_prompt('View transaction details?')
  65. if tx.add_comment(): # edits an existing comment, returns true if changed
  66. tx.file.write(ask_write_default_yes=True)
  67. await tx.send(exit_on_fail=True)
  68. tx.file.write(ask_overwrite=False,ask_write=False)
  69. tx.print_contract_addr()
  70. async_run(main())