unspent.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.unspent: Bitcoin base protocol tracking wallet unspent outputs class
  12. """
  13. from ....tw.unspent import TwUnspentOutputs
  14. from ....addr import CoinAddr
  15. class BitcoinTwUnspentOutputs(TwUnspentOutputs):
  16. class MMGenTwUnspentOutput(TwUnspentOutputs.MMGenTwUnspentOutput):
  17. # required by gen_unspent(); setting valid_attrs explicitly is also more efficient
  18. valid_attrs = {'txid','vout','amt','amt2','comment','twmmid','addr','confs','date','scriptPubKey','skip'}
  19. invalid_attrs = {'proto'}
  20. has_age = True
  21. can_group = True
  22. hdr_lbl = 'unspent outputs'
  23. desc = 'unspent outputs'
  24. item_desc = 'unspent output'
  25. no_data_errmsg = 'No unspent outputs in tracking wallet!'
  26. dump_fn_pfx = 'listunspent'
  27. prompt_fs = 'Total to spend, excluding fees: {} {}\n\n'
  28. prompt = """
  29. Sort options: [t]xid, [a]mount, a[d]dress, [A]ge, [r]everse, [M]mgen addr
  30. Display options: toggle [D]ays/date, show [g]roup, show [m]mgen addr, r[e]draw
  31. Actions: [q]uit view, [p]rint to file, pager [v]iew, [w]ide view, add [l]abel:
  32. """
  33. key_mappings = {
  34. 't':'s_txid',
  35. 'a':'s_amt',
  36. 'd':'s_addr',
  37. 'A':'s_age',
  38. 'r':'d_reverse',
  39. 'M':'s_twmmid',
  40. 'D':'d_days',
  41. 'g':'d_group',
  42. 'm':'d_mmid',
  43. 'e':'d_redraw',
  44. 'q':'a_quit',
  45. 'p':'a_print_detail',
  46. 'v':'a_view',
  47. 'w':'a_view_detail',
  48. 'l':'a_comment_add' }
  49. async def get_rpc_data(self):
  50. # bitcoin-cli help listunspent:
  51. # Arguments:
  52. # 1. minconf (numeric, optional, default=1) The minimum confirmations to filter
  53. # 2. maxconf (numeric, optional, default=9999999) The maximum confirmations to filter
  54. # 3. addresses (json array, optional, default=empty array) A json array of bitcoin addresses
  55. # 4. include_unsafe (boolean, optional, default=true) Include outputs that are not safe to spend
  56. # 5. query_options (json object, optional) JSON with query options
  57. # for now, self.addrs is just an empty list for Bitcoin and friends
  58. add_args = (9999999,self.addrs) if self.addrs else ()
  59. return await self.rpc.call('listunspent',self.minconf,*add_args)