tx-btc2bch.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env python
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2017 Philemon <mmgen-py@yandex.com>
  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 = lambda: {
  23. 'desc': """Convert {pnm} transaction files from BTC to BCH format""".format(pnm=g.proj_name),
  24. 'usage':'[opts] [mmgen transaction file]',
  25. 'options': """
  26. -h, --help Print this help message
  27. --, --longhelp Print help message for long options (common options)
  28. -v, --verbose Produce more verbose output
  29. """
  30. }
  31. cmd_args = opts.init(opts_data)
  32. if g.coin != 'BTC':
  33. die(1,"This program must be run with --coin set to 'BTC'")
  34. if len(cmd_args) != 1: opts.usage()
  35. from mmgen.protocol import CoinProtocol
  36. import mmgen.tx
  37. tx = mmgen.tx.MMGenTX(cmd_args[0])
  38. if opt.verbose:
  39. gmsg('Original transaction is in {} format'.format(g.coin))
  40. g.coin = 'BCH'
  41. g.proto = CoinProtocol(g.coin,g.testnet)
  42. reload(sys.modules['mmgen.tx'])
  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)