From a77b7dd5e81d65e7cc7cde4d86e9377c3b3eebb6 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Mon, 26 Feb 2024 01:25:05 +0100 Subject: [PATCH] Wallet: fix nostr receive (#460) * fix wallet nostr receive * add log * add more relays and print info nicer --- cashu/core/settings.py | 8 +++++++- cashu/wallet/cli/cli.py | 45 ++++++++++++++++++++++++----------------- cashu/wallet/nostr.py | 10 ++++----- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/cashu/core/settings.py b/cashu/core/settings.py index 77bf6cb..178eb43 100644 --- a/cashu/core/settings.py +++ b/cashu/core/settings.py @@ -132,9 +132,15 @@ class WalletSettings(CashuSettings): default=[ "wss://nostr-pub.wellorder.net", "wss://relay.damus.io", - "wss://nostr.zebedee.cloud", + "wss://nostr.mom", "wss://relay.snort.social", "wss://nostr.fmt.wiz.biz", + "wss://relay.minibits.cash", + "wss://nos.lol", + "wss://relay.nostr.band", + "wss://relay.bitcoiner.social", + "wss://140.f7z.io", + "wss://relayable.org", ] ) diff --git a/cashu/wallet/cli/cli.py b/cashu/wallet/cli/cli.py index b2010b8..b9b3ad1 100644 --- a/cashu/wallet/cli/cli.py +++ b/cashu/wallet/cli/cli.py @@ -512,6 +512,11 @@ async def receive_cli( await receive(wallet, tokenObj) elif nostr: await receive_nostr(wallet) + # exit on keypress + print("Press any key to exit.") + click.getchar() + print("Exiting.") + os._exit(0) elif all: reserved_proofs = await get_reserved_proofs(wallet.db) if len(reserved_proofs): @@ -762,25 +767,11 @@ async def info(ctx: Context, mint: bool, mnemonic: bool): if settings.debug: print(f"Debug: {settings.debug}") print(f"Cashu dir: {settings.cashu_dir}") - if settings.env_file: - print(f"Settings: {settings.env_file}") - if settings.tor: - print(f"Tor enabled: {settings.tor}") - if settings.nostr_private_key: - try: - client = NostrClient(private_key=settings.nostr_private_key, connect=False) - print(f"Nostr public key: {client.public_key.bech32()}") - print(f"Nostr relays: {settings.nostr_relays}") - except Exception: - print("Nostr: Error. Invalid key.") - if settings.socks_proxy: - print(f"Socks proxy: {settings.socks_proxy}") - if settings.http_proxy: - print(f"HTTP proxy: {settings.http_proxy}") mint_list = await list_mints(wallet) - print(f"Mint URLs: {mint_list}") - if mint: - for mint_url in mint_list: + print("Mints:") + for mint_url in mint_list: + print(f" - {mint_url}") + if mint: wallet.url = mint_url try: mint_info: dict = (await wallet._load_mint_info()).dict() @@ -805,13 +796,29 @@ async def info(ctx: Context, mint: bool, mnemonic: bool): "Supported NUTS:" f" {', '.join(['NUT-'+str(k) for k in mint_info['nuts'].keys()])}" ) + print("") except Exception as e: print("") print(f"Error fetching mint information for {mint_url}: {e}") if mnemonic: assert wallet.mnemonic - print(f"Mnemonic: {wallet.mnemonic}") + print(f"Mnemonic:\n - {wallet.mnemonic}") + if settings.env_file: + print(f"Settings: {settings.env_file}") + if settings.tor: + print(f"Tor enabled: {settings.tor}") + if settings.nostr_private_key: + try: + client = NostrClient(private_key=settings.nostr_private_key, connect=False) + print(f"Nostr public key: {client.public_key.bech32()}") + print(f"Nostr relays: {', '.join(settings.nostr_relays)}") + except Exception: + print("Nostr: Error. Invalid key.") + if settings.socks_proxy: + print(f"Socks proxy: {settings.socks_proxy}") + if settings.http_proxy: + print(f"HTTP proxy: {settings.http_proxy}") return diff --git a/cashu/wallet/nostr.py b/cashu/wallet/nostr.py index 56dfe73..72b1a60 100644 --- a/cashu/wallet/nostr.py +++ b/cashu/wallet/nostr.py @@ -111,7 +111,7 @@ async def receive_nostr( private_key=settings.nostr_private_key, relays=settings.nostr_relays ) print(f"Your nostr public key: {client.public_key.bech32()}") - # print(f"Your nostr private key (do not share!): {client.private_key.bech32()}") + await asyncio.sleep(2) def get_token_callback(event: Event, decrypted_content: str): @@ -126,10 +126,6 @@ async def receive_nostr( words = decrypted_content.split(" ") for w in words: try: - logger.trace( - "Nostr: setting last check timestamp to" - f" {event.created_at} ({date_str})" - ) # call the receive method tokenObj: TokenV3 = deserialize_token_from_string(w) print( @@ -143,6 +139,10 @@ async def receive_nostr( tokenObj, ) ) + logger.trace( + "Nostr: setting last check timestamp to" + f" {event.created_at} ({date_str})" + ) asyncio.run( set_nostr_last_check_timestamp( timestamp=event.created_at, db=wallet.db