tx-v2-to-v3.py 975 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python3
  2. """
  3. Convert an MMGen 'v2' transaction file (amounts as BTCAmt()) to 'v3' (amounts as
  4. strings). Version 3 TX files were introduced with MMGen version 0.9.7
  5. """
  6. import sys,os,asyncio
  7. from mmgen.cfg import Config
  8. from mmgen.tx import CompletedTX
  9. repo_root = os.path.split(os.path.abspath(os.path.dirname(sys.argv[0])))[0]
  10. sys.path = [repo_root] + sys.path
  11. opts_data = {
  12. 'text': {
  13. 'desc': "Convert MMGen transaction file from v2 format to v3 format",
  14. 'usage': "<tx file>",
  15. 'options': """
  16. -h, --help Print this help message
  17. -d, --outdir=d Output files to directory 'd' instead of working dir
  18. -q, --quiet Write (and overwrite) files without prompting
  19. -S, --stdout Write data to STDOUT instead of file
  20. """
  21. }
  22. }
  23. cfg = Config(opts_data=opts_data)
  24. if len(cfg._args) != 1:
  25. cfg._opts.usage()
  26. tx = asyncio.run(CompletedTX(cfg._args[0],quiet_open=True))
  27. tx.file.write(ask_tty=False,ask_overwrite=not cfg.quiet,ask_write=not cfg.quiet)