addresses.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
  4. # Copyright (C)2013-2022 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
  9. # https://gitlab.com/mmgen/mmgen
  10. """
  11. proto.eth.tw.addresses: Ethereum base protocol tracking wallet address list class
  12. """
  13. from ....tw.addresses import TwAddresses
  14. from ....tw.ctl import TrackingWallet
  15. from ....addr import CoinAddr
  16. from .common import EthereumTwCommon
  17. class EthereumTwAddresses(EthereumTwCommon,TwAddresses):
  18. has_age = False
  19. prompt = """
  20. Sort options: [a]mt, [M]mid, [r]everse
  21. Filters: show [E]mpty addrs, all [L]abels
  22. View/Print: pager [v]iew, [w]ide view, [p]rint
  23. Actions: [q]uit, r[e]draw, [D]elete address, add [l]abel:
  24. """
  25. key_mappings = {
  26. 'a':'s_amt',
  27. 'M':'s_twmmid',
  28. 'r':'d_reverse',
  29. 'e':'d_redraw',
  30. 'E':'d_showempty',
  31. 'L':'d_all_labels',
  32. 'q':'a_quit',
  33. 'l':'a_comment_add',
  34. 'D':'a_addr_delete',
  35. 'v':'a_view',
  36. 'w':'a_view_detail',
  37. 'p':'a_print_detail' }
  38. def get_column_widths(self,data,wide=False):
  39. return self.compute_column_widths(
  40. widths = { # fixed cols
  41. 'num': max(2,len(str(len(data)))+1),
  42. 'mmid': max(len(d.twmmid.disp) for d in data),
  43. 'used': 0,
  44. 'amt': self.disp_prec + 5,
  45. 'date': 0,
  46. 'block': 0,
  47. 'date_time': 0,
  48. 'spc': 5, # 4 spaces between cols + 1 leading space in fs
  49. },
  50. maxws = { # expandable cols
  51. 'addr': max(len(d.addr) for d in data) if self.showcoinaddrs else 0,
  52. 'comment': max(d.comment.screen_width for d in data),
  53. },
  54. minws = {
  55. 'addr': 12 if self.showcoinaddrs else 0,
  56. 'comment': len('Comment'),
  57. },
  58. maxws_nice = {'addr': 18},
  59. wide = wide,
  60. )
  61. async def get_rpc_data(self):
  62. amt0 = self.proto.coin_amt('0')
  63. self.total = amt0
  64. self.minconf = None
  65. addrs = {}
  66. for label,addr in await self.get_addr_label_pairs():
  67. bal = await self.wallet.get_balance(addr)
  68. addrs[label.mmid] = {
  69. 'addr': addr,
  70. 'amt': bal,
  71. 'recvd': amt0,
  72. 'confs': 0,
  73. 'lbl': label }
  74. self.total += bal
  75. return addrs
  76. class EthereumTokenTwAddresses(EthereumTwAddresses):
  77. pass