diff --git a/cashu/tor/tor.py b/cashu/tor/tor.py index a4ba124..4d810fc 100755 --- a/cashu/tor/tor.py +++ b/cashu/tor/tor.py @@ -31,7 +31,8 @@ class TorProxy: logger.debug("Starting") self.run_daemon() - def check_platform(self): + @classmethod + def check_platform(cls): if platform.system() == "Linux": if platform.machine() != "x86_64": return False @@ -119,7 +120,7 @@ class TorProxy: print(".", end="", flush=True) if "Bootstrapped 100%" in str(line): if verbose: - print("done.", flush=True) + print("done", flush=True) break # tor is ready self.startup_finished = True diff --git a/cashu/wallet/cli.py b/cashu/wallet/cli.py index bfbffae..cb0285c 100755 --- a/cashu/wallet/cli.py +++ b/cashu/wallet/cli.py @@ -30,6 +30,7 @@ from cashu.core.settings import ( TOR, VERSION, ) +from cashu.tor.tor import TorProxy from cashu.wallet import migrations from cashu.wallet.crud import ( get_lightning_invoices, @@ -70,6 +71,13 @@ def cli(ctx, host: str, walletname: str): ctx.obj["HOST"] = host ctx.obj["WALLET_NAME"] = walletname wallet = Wallet(ctx.obj["HOST"], os.path.join(CASHU_DIR, walletname)) + + if TOR and not TorProxy().check_platform(): + print( + "WARNING: Your settings say TOR=true but the built-in Tor bundle is not supported on your system. Your IP will be visible to the mint! Please install Tor manually and set TOR=false and SOCKS_HOST=localhost and SOCKS_PORT=9050 in your Cashu config (recommended) or turn off Tor altogether by setting TOR=false (not recommended)." + ) + print("") + ctx.obj["WALLET"] = wallet asyncio.run(init_wallet(wallet)) pass diff --git a/cashu/wallet/wallet.py b/cashu/wallet/wallet.py index 28ef712..a7ce6ab 100644 --- a/cashu/wallet/wallet.py +++ b/cashu/wallet/wallet.py @@ -55,6 +55,7 @@ from cashu.wallet.crud import ( class LedgerAPI: keys: Dict[int, str] keyset: str + tor: TorProxy def __init__(self, url): self.url = url @@ -63,15 +64,10 @@ class LedgerAPI: s = requests.Session() s.headers.update({"Client-version": VERSION}) socks_host, socks_port = None, None - if TOR: - tor = TorProxy(keep_alive=True) - if not tor.check_platform(): - print( - "WARNING: The built-in Tor bundle is not supported on your System. Please install Tor and set the SOCKS_HOST and SOCKS_PORT variables in your Cashu configuration .env file (recommended) or turn off tor by setting TOR=false (not recommended)." - ) - else: - tor.wait_until_startup(verbose=True) - socks_host, socks_port = "localhost", 9050 + if TOR and TorProxy().check_platform(): + self.tor = TorProxy(keep_alive=True) + self.tor.wait_until_startup(verbose=True) + socks_host, socks_port = "localhost", 9050 else: socks_host, socks_port = SOCKS_HOST, SOCKS_PORT