misc.py 1.5 KB

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