Skip to content

Commit

Permalink
Wallet: fix nostr receive (#460)
Browse files Browse the repository at this point in the history
* fix wallet nostr receive

* add log

* add more relays and print info nicer
  • Loading branch information
callebtc authored Feb 26, 2024
1 parent be7a8a7 commit a77b7dd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
8 changes: 7 additions & 1 deletion cashu/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
)

Expand Down
45 changes: 26 additions & 19 deletions cashu/wallet/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand All @@ -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


Expand Down
10 changes: 5 additions & 5 deletions cashu/wallet/nostr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -126,10 +126,6 @@ def get_token_callback(event: Event, decrypted_content: str):
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(
Expand All @@ -143,6 +139,10 @@ def get_token_callback(event: Event, decrypted_content: str):
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
Expand Down

0 comments on commit a77b7dd

Please sign in to comment.