misc.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.misc: miscellaneous functions for Bitcoin base protocol
  12. """
  13. from ...util import msg, msg_r
  14. async def scantxoutset(cfg, rpc, descriptor_list):
  15. import asyncio
  16. async def do_scan():
  17. return await rpc.call(
  18. 'scantxoutset',
  19. 'start',
  20. descriptor_list,
  21. timeout = 720) # call may take several minutes to complete
  22. async def do_status():
  23. CR = '\n' if cfg.test_suite else '\r'
  24. sleep_secs = 0.1 if cfg.test_suite else 2
  25. m = f'{CR}Scanning UTXO set: '
  26. msg_r(m + '0% completed ')
  27. while True:
  28. await asyncio.sleep(sleep_secs)
  29. res = await rpc.call('scantxoutset', 'status')
  30. if res:
  31. msg_r(m + f'{res["progress"]}% completed ')
  32. if task1.done():
  33. msg(m + '100% completed')
  34. return
  35. res = await rpc.call('scantxoutset', 'status')
  36. if res and res.get('progress'):
  37. msg_r('Aborting scan in progress...')
  38. await rpc.call('scantxoutset', 'abort')
  39. await asyncio.sleep(1)
  40. msg('done')
  41. if rpc.backend.name == 'aiohttp':
  42. task1 = asyncio.create_task(do_scan())
  43. task2 = asyncio.create_task(do_status())
  44. ret = await task1
  45. await task2
  46. else:
  47. msg_r('Scanning UTXO set, this could take several minutes...')
  48. ret = await do_scan()
  49. msg('done')
  50. return ret