addresses.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.btc.tw.addresses: Bitcoin base protocol tracking wallet address list class
  12. """
  13. from ....tw.addresses import TwAddresses
  14. from ....tw.shared import TwLabel
  15. from ....obj import get_obj
  16. from .rpc import BitcoinTwRPC
  17. from .view import BitcoinTwView
  18. class BitcoinTwAddresses(BitcoinTwView, TwAddresses, BitcoinTwRPC):
  19. has_age = True
  20. has_used = True
  21. prompt_fs_in = [
  22. 'Sort options: [a]mt, [A]ge, [M]mgen addr, [r]everse',
  23. 'Column options: toggle [D]ays/date/confs/block',
  24. 'Filters: show [E]mpty addrs, [u]sed addrs, all [L]abels',
  25. 'View/Print: pager [v]iew, [w]ide pager view, [p]rint{s}',
  26. 'Actions: [q]uit menu, r[e]draw, add [l]abel:']
  27. prompt_fs_repl = {
  28. 'BCH': (1, 'Column options: toggle [D]ays/date/confs/block, cas[h]addr')}
  29. extra_key_mappings = {
  30. 'A':'s_age',
  31. 'D':'d_days',
  32. 'u':'d_showused'}
  33. async def get_rpc_data(self):
  34. qmsg = self.cfg._util.qmsg
  35. qmsg_r = self.cfg._util.qmsg_r
  36. qmsg_r('Getting unspent outputs...')
  37. addrs = await self.get_unspent_by_mmid(minconf=self.minconf)
  38. qmsg('done')
  39. coin_amt = self.proto.coin_amt
  40. amt0 = coin_amt('0')
  41. self.total = sum((v['amt'] for v in addrs.values()), start=amt0)
  42. qmsg_r('Getting labels and associated addresses...')
  43. for e in await self.get_label_addr_pairs():
  44. if e.label and e.label.mmid not in addrs:
  45. addrs[e.label.mmid] = {
  46. 'addr': e.coinaddr,
  47. 'amt': amt0,
  48. 'recvd': amt0,
  49. 'is_used': False,
  50. 'confs': 0,
  51. 'lbl': e.label}
  52. qmsg('done')
  53. qmsg_r('Getting received funds data...')
  54. for d in await self.rpc.icall('listreceivedbylabel', include_empty=True):
  55. label = get_obj(TwLabel, proto=self.proto, text=d['label'])
  56. if label:
  57. assert label.mmid in addrs, f'{label.mmid!r} not found in addrlist!'
  58. amt = coin_amt(d['amount'])
  59. addrs[label.mmid]['recvd'] = amt
  60. addrs[label.mmid]['is_used'] = bool(amt)
  61. addrs[label.mmid]['confs'] = d['confirmations']
  62. qmsg('done')
  63. return addrs