tx-btc2bch.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2019 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. tx-btc2bch: Convert MMGen transaction files from BTC to BCH format
  20. """
  21. from mmgen.common import *
  22. opts_data = {
  23. 'text': {
  24. 'desc': """Convert {pnm} transaction files from BTC to BCH format""".format(pnm=g.proj_name),
  25. 'usage':'[opts] [mmgen transaction file]',
  26. 'options': """
  27. -h, --help Print this help message
  28. --, --longhelp Print help message for long options (common options)
  29. -v, --verbose Produce more verbose output
  30. """
  31. }
  32. }
  33. cmd_args = opts.init(opts_data)
  34. if g.coin != 'BTC':
  35. die(1,"This program must be run with --coin set to 'BTC'")
  36. if len(cmd_args) != 1: opts.usage()
  37. import mmgen.tx
  38. tx = mmgen.tx.MMGenTX(cmd_args[0])
  39. if opt.verbose:
  40. gmsg('Original transaction is in {} format'.format(g.coin))
  41. from mmgen.protocol import init_coin
  42. init_coin('BCH')
  43. if opt.verbose:
  44. gmsg('Converting transaction to {} format'.format(g.coin))
  45. tx.inputs.convert_coin(verbose=opt.verbose)
  46. tx.outputs.convert_coin(verbose=opt.verbose)
  47. tx.desc = 'converted transaction'
  48. tx.write_to_file(ask_write=False,ask_overwrite=False)