addresses.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.eth.tw.addresses: Ethereum base protocol tracking wallet address list class
  12. """
  13. from ....tw.addresses import TwAddresses
  14. from .view import EthereumTwView
  15. from .rpc import EthereumTwRPC
  16. class EthereumTwAddresses(TwAddresses, EthereumTwView, EthereumTwRPC):
  17. has_age = False
  18. prompt_fs_in = [
  19. 'Sort options: [a]mt, [M]mgen addr, [r]everse',
  20. 'Filters: show [E]mpty addrs, show all [L]abels',
  21. 'View/Print: pager [v]iew, [w]ide pager view, [p]rint{s}',
  22. 'Actions: [q]uit menu, r[e]draw, [D]elete addr, add [l]abel:']
  23. key_mappings = {
  24. 'a':'s_amt',
  25. 'M':'s_twmmid',
  26. 'r':'s_reverse',
  27. 'e':'d_redraw',
  28. 'E':'d_showempty',
  29. 'L':'d_all_labels',
  30. 'l':'i_comment_add',
  31. 'D':'i_addr_delete',
  32. 'v':'a_view',
  33. 'w':'a_view_detail',
  34. 'p':'a_print_detail'}
  35. def get_column_widths(self, data, *, wide, interactive):
  36. return self.compute_column_widths(
  37. widths = { # fixed cols
  38. 'num': max(2, len(str(len(data)))+1),
  39. 'mmid': max(len(d.twmmid.disp) for d in data),
  40. 'used': 0,
  41. 'amt': self.amt_widths['amt'],
  42. 'date': 0,
  43. 'block': 0,
  44. 'date_time': 0,
  45. 'spc': 5, # 4 spaces between cols + 1 leading space in fs
  46. },
  47. maxws = { # expandable cols
  48. 'addr': max(len(d.addr) for d in data) if self.showcoinaddrs else 0,
  49. 'comment': max(d.comment.screen_width for d in data),
  50. },
  51. minws = {
  52. 'addr': 12 if self.showcoinaddrs else 0,
  53. 'comment': len('Comment'),
  54. },
  55. maxws_nice = {'addr': 18},
  56. wide = wide,
  57. interactive = interactive,
  58. )
  59. async def get_rpc_data(self):
  60. amt0 = self.proto.coin_amt('0')
  61. self.total = amt0
  62. self.minconf = None
  63. addrs = {}
  64. for e in await self.twctl.get_label_addr_pairs():
  65. bal = await self.twctl.get_balance(e.coinaddr)
  66. addrs[e.label.mmid] = {
  67. 'addr': e.coinaddr,
  68. 'amt': bal,
  69. 'recvd': amt0,
  70. 'confs': 0,
  71. 'lbl': e.label}
  72. self.total += bal
  73. return addrs
  74. class EthereumTokenTwAddresses(EthereumTwAddresses):
  75. pass