diff --git a/cashu/lightning/strike.py b/cashu/lightning/strike.py index b4c1966e..c4d4d243 100644 --- a/cashu/lightning/strike.py +++ b/cashu/lightning/strike.py @@ -113,7 +113,7 @@ async def get_invoice_quote(self, bolt11: str) -> PaymentQuote: r.raise_for_status() except Exception: error_message = r.json()["data"]["message"] - return PaymentResponse(None, None, None, None, error_message) + raise Exception(error_message) data = r.json() amount_cent = int(float(data.get("amount").get("amount")) * 100) diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index 3c3077f8..7775e2c1 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -430,6 +430,8 @@ async def getmelt(self, bolt11: str) -> PaymentQuote: int: Amount to pay """ quote = await self.lightning.get_invoice_quote(bolt11) + if "error_message" in quote: + raise LightningError(quote["error_message"]) invoice = Invoice( amount=quote.amount, hash=quote.id, diff --git a/cashu/wallet/cli/cli.py b/cashu/wallet/cli/cli.py index b15718e1..e55c4870 100644 --- a/cashu/wallet/cli/cli.py +++ b/cashu/wallet/cli/cli.py @@ -183,7 +183,7 @@ async def pay(ctx: Context, invoice: str, yes: bool): @cli.command("invoice", help="Create Lighting invoice.") -@click.argument("amount", type=int) +@click.argument("amount", type=float) @click.option("--hash", default="", help="Hash of the paid invoice.", type=str) @click.option( "--split", @@ -194,7 +194,9 @@ async def pay(ctx: Context, invoice: str, yes: bool): ) @click.pass_context @coro -async def invoice(ctx: Context, amount: int, hash: str, split: int): +async def invoice(ctx: Context, amount: float, hash: str, split: int): + # USD to cent + amount = int(amount * 100) wallet: Wallet = ctx.obj["WALLET"] await wallet.load_mint() wallet.status() @@ -213,13 +215,13 @@ async def invoice(ctx: Context, amount: int, hash: str, split: int): elif amount and not hash: invoice = await wallet.request_mint(amount) if invoice.pr: - print(f"Pay invoice to mint {amount} sat:") + print(f"Pay invoice to mint {invoice.amount/100:.2f} USD:") print("") print(f"Invoice: {invoice.pr}") print("") print( "If you abort this you can use this command to recheck the" - f" invoice:\ncashu invoice {amount} --hash {invoice.hash}" + f" invoice:\ncashu invoice {amount/100:.2f} --hash {invoice.hash}" ) check_until = time.time() + 5 * 60 # check for five minutes print("") @@ -329,12 +331,12 @@ async def balance(ctx: Context, verbose): if verbose: print( - f"Balance: {wallet.available_balance} cent (pending:" - f" {wallet.balance-wallet.available_balance} cent) in" + f"Balance: {wallet.available_balance/100:.2f} USD (pending:" + f" {(wallet.balance-wallet.available_balance)/100:.2f} cent) in" f" {len([p for p in wallet.proofs if not p.reserved])} tokens" ) else: - print(f"Balance: {wallet.available_balance} cent") + print(f"Balance: {wallet.available_balance/100:.2f} USD") @cli.command("send", help="Send tokens.") diff --git a/cashu/wallet/wallet.py b/cashu/wallet/wallet.py index 9d9e6a03..b9b89bee 100644 --- a/cashu/wallet/wallet.py +++ b/cashu/wallet/wallet.py @@ -1269,7 +1269,7 @@ def proof_amounts(self): return [p.amount for p in sorted(self.proofs, key=lambda p: p.amount)] def status(self): - print(f"Balance: {self.available_balance} cents") + print(f"Balance: {self.available_balance/100:.2f} USD") def balance_per_keyset(self): return {