- looks like around python3.9, they changed it so that
if we don't block on the main thread, it starts to shut things down
- polling thread.join() makes Ctrl+C work. kind of.
```
$ ./electrum/scripts/txradar.py 6bde84a981e72573666fcc51c81ec3f8f4a813709bf16451dce3f106a114d392
Exception in run: RuntimeError('cannot schedule new futures after interpreter shutdown')
Traceback (most recent call last):
File "/home/user/wspace/electrum/electrum/util.py", line 1218, in wrapper
return await func(*args, **kwargs)
File "/home/user/wspace/electrum/electrum/interface.py", line 649, in wrapper_func
return await func(self, *args, **kwargs)
File "/home/user/wspace/electrum/electrum/interface.py", line 675, in run
await self.open_session(ssl_context=ssl_context)
File "/home/user/wspace/electrum/electrum/interface.py", line 872, in open_session
async with _RSClient(
File "/home/user/.local/lib/python3.10/site-packages/aiorpcx/rawsocket.py", line 167, in __aenter__
_transport, protocol = await self.create_connection()
File "/home/user/wspace/electrum/electrum/interface.py", line 285, in create_connection
return await super().create_connection()
File "/home/user/.local/lib/python3.10/site-packages/aiorpcx/rawsocket.py", line 163, in create_connection
return await connector.create_connection(
File "/usr/lib/python3.10/asyncio/base_events.py", line 1036, in create_connection
infos = await self._ensure_resolved(
File "/usr/lib/python3.10/asyncio/base_events.py", line 1418, in _ensure_resolved
return await loop.getaddrinfo(host, port, family=family, type=type,
File "/usr/lib/python3.10/asyncio/base_events.py", line 863, in getaddrinfo
return await self.run_in_executor(
File "/usr/lib/python3.10/asyncio/base_events.py", line 821, in run_in_executor
executor.submit(func, *args), loop=self)
File "/usr/lib/python3.10/concurrent/futures/thread.py", line 169, in submit
raise RuntimeError('cannot schedule new futures after '
RuntimeError: cannot schedule new futures after interpreter shutdown
```
43 lines
1.3 KiB
Python
Executable File
43 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import asyncio
|
|
|
|
from electrum.util import json_encode, print_msg, create_and_start_event_loop, log_exceptions
|
|
from electrum.simple_config import SimpleConfig
|
|
from electrum.network import Network
|
|
from electrum.keystore import bip39_to_seed
|
|
from electrum.bip32 import BIP32Node
|
|
from electrum.bip39_recovery import account_discovery
|
|
|
|
try:
|
|
mnemonic = sys.argv[1]
|
|
passphrase = sys.argv[2] if len(sys.argv) > 2 else ""
|
|
except Exception:
|
|
print("usage: bip39_recovery <mnemonic> [<passphrase>]")
|
|
sys.exit(1)
|
|
|
|
loop, stopping_fut, loop_thread = create_and_start_event_loop()
|
|
|
|
config = SimpleConfig()
|
|
network = Network(config)
|
|
network.start()
|
|
|
|
@log_exceptions
|
|
async def f():
|
|
try:
|
|
def get_account_xpub(account_path):
|
|
root_seed = bip39_to_seed(mnemonic, passphrase=passphrase)
|
|
root_node = BIP32Node.from_rootseed(root_seed, xtype="standard")
|
|
account_node = root_node.subkey_at_private_derivation(account_path)
|
|
account_xpub = account_node.to_xpub()
|
|
return account_xpub
|
|
active_accounts = await account_discovery(network, get_account_xpub)
|
|
print_msg(json_encode(active_accounts))
|
|
finally:
|
|
stopping_fut.set_result(1)
|
|
|
|
asyncio.run_coroutine_threadsafe(f(), loop)
|
|
while loop_thread.is_alive():
|
|
loop_thread.join(1)
|