addresses.py 2.3 KB

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