nostr: send to nip05 (#112)

* nostr: add sleep after send before closing threads

* cli: nostr send <amount> <npub> without option flag

* parse domain.com nip-05 addresses without user
This commit is contained in:
calle
2023-02-25 14:34:15 +01:00
committed by GitHub
parent da2d003291
commit d1c32e4c69
2 changed files with 12 additions and 4 deletions

View File

@@ -270,10 +270,12 @@ async def send(ctx: Context, amount: int, lock: str, legacy: bool):
@cli.command("send", help="Send tokens.")
@click.argument("amount", type=int)
@click.argument("nostr", type=str, required=False)
@click.option(
"--nostr",
"-n",
help="Send to nostr pubkey",
"nopt",
help="Send to nostr pubkey.",
type=str,
)
@click.option("--lock", "-l", default=None, help="Lock tokens (P2SH).", type=str)
@@ -302,15 +304,16 @@ async def send_command(
ctx,
amount: int,
nostr: str,
nopt: str,
lock: str,
legacy: bool,
verbose: bool,
yes: bool,
):
if nostr is None:
if not nostr and not nopt:
await send(ctx, amount, lock, legacy)
else:
await send_nostr(ctx, amount, nostr, verbose, yes)
await send_nostr(ctx, amount, nostr or nopt, verbose, yes)
async def receive(ctx: Context, token: str, lock: str):

View File

@@ -24,6 +24,9 @@ async def nip5_to_pubkey(wallet: Wallet, address: str):
"""
# we will be using the requests session from the wallet
await wallet._init_s()
# if no username is given, use default _ (NIP-05 stuff)
if "@" not in address:
address = "_@" + address
# now we can use it
user, host = address.split("@")
resp_dict = {}
@@ -50,7 +53,8 @@ async def send_nostr(ctx: Context, amount: int, pubkey: str, verbose: bool, yes:
# load a wallet for the chosen mint
wallet = await get_mint_wallet(ctx)
if "@" in pubkey:
if "@" in pubkey or "." in pubkey:
# parses user@domain.com and domain.com (which is _@domain.com)
pubkey = await nip5_to_pubkey(wallet, pubkey)
await wallet.load_proofs()
@@ -82,6 +86,7 @@ async def send_nostr(ctx: Context, amount: int, pubkey: str, verbose: bool, yes:
client.dm(token, pubkey_to)
print(f"Token sent to {pubkey_to.bech32()}")
await asyncio.sleep(5)
client.close()