addresses.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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.btc.tw.addresses: Bitcoin base protocol tracking wallet address list class
  12. """
  13. from ....tw.addresses import TwAddresses
  14. from ....tw.common import TwLabel,get_obj
  15. from ....util import msg,msg_r
  16. from ....addr import CoinAddr
  17. from ....obj import NonNegativeInt
  18. from .common import BitcoinTwCommon
  19. class BitcoinTwAddresses(TwAddresses,BitcoinTwCommon):
  20. has_age = True
  21. prompt = """
  22. Sort options: [a]mt, [A]ge, [M]mid, [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 view, [p]rint
  26. Actions: [q]uit, r[e]draw, add [l]abel:
  27. """
  28. key_mappings = {
  29. 'a':'s_amt',
  30. 'A':'s_age',
  31. 'M':'s_twmmid',
  32. 'r':'d_reverse',
  33. 'D':'d_days',
  34. 'e':'d_redraw',
  35. 'E':'d_showempty',
  36. 'u':'d_showused',
  37. 'L':'d_all_labels',
  38. 'q':'a_quit',
  39. 'v':'a_view',
  40. 'w':'a_view_detail',
  41. 'p':'a_print_detail',
  42. 'l':'a_comment_add' }
  43. async def get_rpc_data(self):
  44. msg_r('Getting unspent outputs...')
  45. addrs = await self.get_unspent_by_mmid(self.minconf)
  46. msg('done')
  47. amt0 = self.proto.coin_amt('0')
  48. self.total = sum((v['amt'] for v in addrs.values()), start=amt0 )
  49. msg_r('Getting labels and associated addresses...')
  50. for label,addr in await self.get_addr_label_pairs():
  51. if label and label.mmid not in addrs:
  52. addrs[label.mmid] = {
  53. 'addr': addr,
  54. 'amt': amt0,
  55. 'recvd': amt0,
  56. 'confs': 0,
  57. 'lbl': label }
  58. msg('done')
  59. msg_r('Getting received funds data...')
  60. # args: 1:minconf, 2:include_empty, 3:include_watchonly, 4:include_immature_coinbase
  61. for d in await self.rpc.call( 'listreceivedbylabel', 1, False, True ):
  62. label = get_obj( TwLabel, proto=self.proto, text=d['label'] )
  63. if label:
  64. assert label.mmid in addrs, f'{label.mmid!r} not found in addrlist!'
  65. addrs[label.mmid]['recvd'] = d['amount']
  66. addrs[label.mmid]['confs'] = d['confirmations']
  67. msg('done')
  68. return addrs