Skip to content

Commit

Permalink
update wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Apr 20, 2024
1 parent e2ed5c3 commit 282356b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cashu/gateway/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ async def _startup_gateway(self):
async def melt_quote(
self, melt_quote_request: GatewayMeltQuoteRequest
) -> GatewayMeltQuoteResponse:
if melt_quote_request.mint != settings.mint_url:
raise TransactionError("mint url does not match gateway mint url")

request = melt_quote_request.request
invoice = bolt11.decode(pr=request)
amount_msat = bolt11.decode(pr=request).amount_msat
Expand Down
3 changes: 3 additions & 0 deletions cashu/wallet/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from ...wallet.wallet import Wallet as Wallet
from ..api.api_server import start_api_server
from ..cli.cli_helpers import (
get_gateway,
get_mint_wallet,
get_unit_wallet,
print_balance,
Expand Down Expand Up @@ -245,6 +246,7 @@ async def pay(ctx: Context, invoice: str, yes: bool, gateway: bool):
async def pay_gateway(ctx: Context, invoice: str, yes: bool):
_wallet: Wallet = ctx.obj["WALLET"]
await print_balance(ctx)
gateway_url = get_gateway(ctx)

async def mint_wallet(
mint_url: Optional[str] = None, raise_connection_error: bool = True
Expand All @@ -254,6 +256,7 @@ async def mint_wallet(
db=os.path.join(settings.cashu_dir, settings.wallet_name),
name=settings.wallet_name,
)
lightning_wallet.gateway = gateway_url
await lightning_wallet.async_init(raise_connection_error=raise_connection_error)
return lightning_wallet

Expand Down
28 changes: 28 additions & 0 deletions cashu/wallet/cli/cli_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,34 @@ async def get_mint_wallet(ctx: Context, force_select: bool = False):
return mint_wallet


def get_gateway(ctx: Context):
"""
Helper function that shows all settings.wallet_gateways and asks the user to select one.
"""
gateway = settings.wallet_gateways[0]
if len(settings.wallet_gateways) > 1:
print(f"You have {len(settings.wallet_gateways)} gateways:")
print("")
for i, gw in enumerate(settings.wallet_gateways):
print(f"Gateway {i+1}: {gw}")
print("")
gateway_nr_str = input(
f"Select gateway [1-{len(settings.wallet_gateways)}] or "
f"press enter for default '{settings.wallet_gateways[0]}': "
)
if not gateway_nr_str: # default gateway
gateway = settings.wallet_gateways[0]
elif gateway_nr_str.isdigit() and int(gateway_nr_str) <= len(
settings.wallet_gateways
): # specific gateway
gateway = settings.wallet_gateways[int(gateway_nr_str) - 1]
else:
raise Exception("invalid input.")
print(f"Selected gateway: {gateway}")
print("")
return gateway


async def print_mint_balances(wallet: Wallet, show_mints: bool = False):
"""
Helper function that prints the balances for each mint URL that we have tokens from.
Expand Down

0 comments on commit 282356b

Please sign in to comment.