|
@@ -0,0 +1,62 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+#
|
|
|
+# mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
|
|
|
+# Copyright (C)2013-2022 The MMGen Project <mmgen@tuta.io>
|
|
|
+# Licensed under the GNU General Public License, Version 3:
|
|
|
+# https://www.gnu.org/licenses
|
|
|
+# Public project repositories:
|
|
|
+# https://github.com/mmgen/mmgen
|
|
|
+# https://gitlab.com/mmgen/mmgen
|
|
|
+
|
|
|
+"""
|
|
|
+base_proto.bitcoin.misc: miscellaneous functions for Bitcoin base protocol
|
|
|
+"""
|
|
|
+
|
|
|
+from ...globalvars import g
|
|
|
+from ...util import msg,msg_r
|
|
|
+
|
|
|
+async def scantxoutset(rpc,descriptor_list):
|
|
|
+
|
|
|
+ import asyncio
|
|
|
+
|
|
|
+ async def do_scan():
|
|
|
+ return await rpc.call(
|
|
|
+ 'scantxoutset',
|
|
|
+ 'start',
|
|
|
+ descriptor_list,
|
|
|
+ timeout = 720 ) # call may take several minutes to complete
|
|
|
+
|
|
|
+ async def do_status():
|
|
|
+
|
|
|
+ CR = '\n' if g.test_suite else '\r'
|
|
|
+ sleep_secs = 0.1 if g.test_suite else 2
|
|
|
+ m = f'{CR}Scanning UTXO set: '
|
|
|
+ msg_r(m + '0% completed ')
|
|
|
+
|
|
|
+ while True:
|
|
|
+ await asyncio.sleep(sleep_secs)
|
|
|
+ res = await rpc.call('scantxoutset','status')
|
|
|
+ if res:
|
|
|
+ msg_r(m + f'{res["progress"]}% completed ')
|
|
|
+ if task1.done():
|
|
|
+ msg(m + '100% completed')
|
|
|
+ return
|
|
|
+
|
|
|
+ res = await rpc.call('scantxoutset','status')
|
|
|
+ if res and res.get('progress'):
|
|
|
+ msg_r('Aborting scan in progress...')
|
|
|
+ await rpc.call('scantxoutset','abort')
|
|
|
+ await asyncio.sleep(1)
|
|
|
+ msg('done')
|
|
|
+
|
|
|
+ if rpc.backend.name == 'aiohttp':
|
|
|
+ task1 = asyncio.create_task( do_scan() )
|
|
|
+ task2 = asyncio.create_task( do_status() )
|
|
|
+ ret = await task1
|
|
|
+ await task2
|
|
|
+ else:
|
|
|
+ msg_r(f'Scanning UTXO set, this could take several minutes...')
|
|
|
+ ret = await do_scan()
|
|
|
+ msg('done')
|
|
|
+
|
|
|
+ return ret
|