mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-21 19:14:19 +01:00
Merge pull request #77 from cashubtc/fix/cli_multimint_ask_url
ask for mint url
This commit is contained in:
@@ -303,19 +303,26 @@ async def receive(ctx, token: str, lock: str):
|
|||||||
# LNbits token link parsing
|
# LNbits token link parsing
|
||||||
# can extract minut URL from LNbits token links like:
|
# can extract minut URL from LNbits token links like:
|
||||||
# https://lnbits.server/cashu/wallet?mint_id=aMintId&recv_token=W3siaWQiOiJHY2...
|
# https://lnbits.server/cashu/wallet?mint_id=aMintId&recv_token=W3siaWQiOiJHY2...
|
||||||
url = None
|
|
||||||
if len(token.split("&recv_token=")) == 2:
|
def parse_lnbits_link(link):
|
||||||
|
url, token = "", ""
|
||||||
|
if len(link.split("&recv_token=")) == 2:
|
||||||
# extract URL params
|
# extract URL params
|
||||||
params = urllib.parse.parse_qs(token.split("?")[1])
|
params = urllib.parse.parse_qs(link.split("?")[1])
|
||||||
# extract URL
|
# extract URL
|
||||||
if "mint_id" in params:
|
if "mint_id" in params:
|
||||||
url = (
|
url = (
|
||||||
token.split("?")[0].split("/wallet")[0]
|
link.split("?")[0].split("/wallet")[0]
|
||||||
+ "/api/v1/"
|
+ "/api/v1/"
|
||||||
+ params["mint_id"][0]
|
+ params["mint_id"][0]
|
||||||
)
|
)
|
||||||
# extract token
|
# extract token
|
||||||
token = params["recv_token"][0]
|
token = params["recv_token"][0]
|
||||||
|
return token, url
|
||||||
|
else:
|
||||||
|
return link, ""
|
||||||
|
|
||||||
|
token, url = parse_lnbits_link(token)
|
||||||
|
|
||||||
# assume W3siaWQiOiJH.. token
|
# assume W3siaWQiOiJH.. token
|
||||||
# trows an error if the desirialization with the old format doesn't work
|
# trows an error if the desirialization with the old format doesn't work
|
||||||
@@ -325,12 +332,13 @@ async def receive(ctx, token: str, lock: str):
|
|||||||
include_mints=False,
|
include_mints=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
# if it was an LNbits link
|
# if it was not an lnbits link
|
||||||
# and add url and keyset id to token from link extraction above
|
url = url or (
|
||||||
if url:
|
input(f"Enter mint URL (press enter for default {MINT_URL}): ") or MINT_URL
|
||||||
token_object: TokenJson = await wallet._make_token(
|
|
||||||
proofs, include_mints=False
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# and add url and keyset id to token
|
||||||
|
token_object: TokenJson = await wallet._make_token(proofs, include_mints=False)
|
||||||
token_object.mints = {}
|
token_object.mints = {}
|
||||||
keysets = list(set([p.id for p in proofs]))
|
keysets = list(set([p.id for p in proofs]))
|
||||||
assert keysets is not None, "no keysets"
|
assert keysets is not None, "no keysets"
|
||||||
@@ -513,6 +521,31 @@ async def invoices(ctx):
|
|||||||
print("No invoices found.")
|
print("No invoices found.")
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("wallets", help="List of all available wallets.")
|
||||||
|
@click.pass_context
|
||||||
|
@coro
|
||||||
|
async def wallets(ctx):
|
||||||
|
# list all directories
|
||||||
|
wallets = [d for d in listdir(CASHU_DIR) if isdir(join(CASHU_DIR, d))]
|
||||||
|
try:
|
||||||
|
wallets.remove("mint")
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
for w in wallets:
|
||||||
|
wallet = Wallet(ctx.obj["HOST"], os.path.join(CASHU_DIR, w))
|
||||||
|
try:
|
||||||
|
await init_wallet(wallet)
|
||||||
|
if wallet.proofs and len(wallet.proofs):
|
||||||
|
active_wallet = False
|
||||||
|
if w == ctx.obj["WALLET_NAME"]:
|
||||||
|
active_wallet = True
|
||||||
|
print(
|
||||||
|
f"Wallet: {w}\tBalance: {sum_proofs(wallet.proofs)} sat (available: {sum_proofs([p for p in wallet.proofs if not p.reserved])} sat){' *' if active_wallet else ''}"
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@cli.command("nsend", help="Send tokens via nostr.")
|
@cli.command("nsend", help="Send tokens via nostr.")
|
||||||
@click.argument("amount", type=int)
|
@click.argument("amount", type=int)
|
||||||
@click.argument(
|
@click.argument(
|
||||||
@@ -606,31 +639,6 @@ async def nreceive(ctx, verbose: bool):
|
|||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
|
|
||||||
@cli.command("wallets", help="List of all available wallets.")
|
|
||||||
@click.pass_context
|
|
||||||
@coro
|
|
||||||
async def wallets(ctx):
|
|
||||||
# list all directories
|
|
||||||
wallets = [d for d in listdir(CASHU_DIR) if isdir(join(CASHU_DIR, d))]
|
|
||||||
try:
|
|
||||||
wallets.remove("mint")
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
for w in wallets:
|
|
||||||
wallet = Wallet(ctx.obj["HOST"], os.path.join(CASHU_DIR, w))
|
|
||||||
try:
|
|
||||||
await init_wallet(wallet)
|
|
||||||
if wallet.proofs and len(wallet.proofs):
|
|
||||||
active_wallet = False
|
|
||||||
if w == ctx.obj["WALLET_NAME"]:
|
|
||||||
active_wallet = True
|
|
||||||
print(
|
|
||||||
f"Wallet: {w}\tBalance: {sum_proofs(wallet.proofs)} sat (available: {sum_proofs([p for p in wallet.proofs if not p.reserved])} sat){' *' if active_wallet else ''}"
|
|
||||||
)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command("info", help="Information about Cashu wallet.")
|
@cli.command("info", help="Information about Cashu wallet.")
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
@coro
|
@coro
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ async def print_mint_balances(ctx, wallet, show_mints=False):
|
|||||||
print("")
|
print("")
|
||||||
for i, (k, v) in enumerate(mint_balances.items()):
|
for i, (k, v) in enumerate(mint_balances.items()):
|
||||||
print(
|
print(
|
||||||
f"Mint {i+1}: {k} - Balance: {v['available']} sat (pending: {v['balance']-v['available']} sat)"
|
f"Mint {i+1}: Balance: {v['available']} sat (pending: {v['balance']-v['available']} sat) URL: {k}"
|
||||||
)
|
)
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
@@ -103,10 +103,10 @@ async def get_mint_wallet(ctx):
|
|||||||
|
|
||||||
await print_mint_balances(ctx, wallet, show_mints=True)
|
await print_mint_balances(ctx, wallet, show_mints=True)
|
||||||
|
|
||||||
mint_nr = input(
|
mint_nr = (
|
||||||
f"Which mint do you want to use? [1-{len(mint_balances)}, default: 1] "
|
input(f"Select mint [1-{len(mint_balances)}, press enter for default 1]: ")
|
||||||
|
or "1"
|
||||||
)
|
)
|
||||||
mint_nr = "1" if mint_nr == "" else mint_nr
|
|
||||||
if not mint_nr.isdigit():
|
if not mint_nr.isdigit():
|
||||||
raise Exception("invalid input.")
|
raise Exception("invalid input.")
|
||||||
mint_nr = int(mint_nr)
|
mint_nr = int(mint_nr)
|
||||||
|
|||||||
Reference in New Issue
Block a user