view.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. proto.xmr.tw.view: Monero protocol base class for tracking wallet view classes
  12. """
  13. from ....xmrwallet import op as xmrwallet_op
  14. from ....tw.view import TwView
  15. class MoneroTwView:
  16. class rpc:
  17. caps = ()
  18. is_remote = False
  19. async def get_rpc_data(self):
  20. from mmgen.tw.shared import TwMMGenID, TwLabel
  21. op = xmrwallet_op('dump_data', self.cfg, None, None, compat_call=True)
  22. await op.restart_wallet_daemon()
  23. wallets_data = await op.main()
  24. self.total = self.proto.coin_amt('0')
  25. def gen_addrs():
  26. for wdata in wallets_data:
  27. bals_data = {i: {} for i in range(len(wdata['data'].accts_data['subaddress_accounts']))}
  28. for d in wdata['data'].bals_data.get('per_subaddress', []):
  29. bals_data[d['account_index']].update({d['address_index']: d['unlocked_balance']})
  30. for acct_idx, acct_data in enumerate(wdata['data'].addrs_data):
  31. for addr_data in acct_data['addresses']:
  32. addr_idx = addr_data['address_index']
  33. self.total += (bal := self.proto.coin_amt(
  34. bals_data[acct_idx].get(addr_idx, 0),
  35. from_unit = 'atomic'))
  36. if self.include_empty or bal:
  37. mmid = '{}:M:{}-{}/{}'.format(
  38. wdata['seed_id'],
  39. wdata['wallet_num'],
  40. acct_idx,
  41. addr_idx)
  42. yield (TwMMGenID(self.proto, mmid), {
  43. 'addr': addr_data['address'],
  44. 'amt': bal,
  45. 'recvd': bal,
  46. 'is_used': addr_data['used'],
  47. 'confs': 1,
  48. 'lbl': TwLabel(self.proto, mmid + ' ' + addr_data['label'])})
  49. return dict(gen_addrs())
  50. class action(TwView.action):
  51. async def a_sync_wallets(self, parent):
  52. from ....util import msg, msg_r
  53. from ....tw.view import CUR_HOME, ERASE_ALL
  54. msg('')
  55. op = xmrwallet_op('sync', parent.cfg, None, None, compat_call=True)
  56. await op.restart_wallet_daemon()
  57. await op.main()
  58. await parent.get_data()
  59. msg_r(CUR_HOME + ERASE_ALL)