dump.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python3
  2. #
  3. # MMGen Wallet, a terminal-based cryptocurrency wallet
  4. # Copyright (C)2013-2025 The MMGen Project <mmgen@tuta.io>
  5. # Licensed under the GNU General Public License, Version 3:
  6. # https://www.gnu.org/licenses
  7. # Public project repositories:
  8. # https://github.com/mmgen/mmgen-wallet
  9. # https://gitlab.com/mmgen/mmgen-wallet
  10. """
  11. xmrwallet.ops.dump: Monero wallet ops for the MMGen Suite
  12. """
  13. from ...util import msg, Msg
  14. from ..file.outputs import MoneroWalletDumpFile
  15. from ..rpc import MoneroWalletRPC
  16. from .wallet import OpWallet
  17. class OpDump(OpWallet):
  18. wallet_offline = True
  19. async def process_wallet(self, d, fn, last):
  20. h = MoneroWalletRPC(self, d)
  21. h.open_wallet('source')
  22. wallet_data = h.get_wallet_data(print=False)
  23. msg('')
  24. MoneroWalletDumpFile.New(
  25. parent = self,
  26. wallet_fn = fn,
  27. data = {'wallet_metadata': wallet_data.addrs_data}
  28. ).write()
  29. return True
  30. class OpDumpDataCommon(OpWallet):
  31. wallet_offline = True
  32. return_data = True
  33. async def process_wallet(self, d, fn, last):
  34. h = MoneroWalletRPC(self, d)
  35. h.open_wallet('source', refresh=False)
  36. return {
  37. 'seed_id': self.kal.al_id.sid,
  38. 'wallet_num': d.idx,
  39. 'data': h.get_wallet_data(print=False)}
  40. def post_main_success(self):
  41. pass
  42. class OpDumpData(OpDumpDataCommon):
  43. start_daemon = False
  44. stem = 'load'
  45. class OpDumpJson(OpDumpDataCommon):
  46. stem = 'dump'
  47. async def main(self):
  48. import json
  49. data = await super().main()
  50. Msg(json.dumps(data))
  51. return sum(map(bool, data))