Mint: Fakewallet support for USD (#488)

* fakewallet usd wip

* FakeWallet support for USD

* fix api return for receive

* use MINT_BACKEND_BOLT11_SAT everywhere
This commit is contained in:
callebtc
2024-03-22 12:11:40 +01:00
committed by GitHub
parent f4621345f3
commit 3ba1e81fcb
21 changed files with 168 additions and 93 deletions

View File

@@ -184,7 +184,7 @@ async def cli(ctx: Context, host: str, walletname: str, unit: str, tests: bool):
async def pay(ctx: Context, invoice: str, yes: bool):
wallet: Wallet = ctx.obj["WALLET"]
await wallet.load_mint()
print_balance(ctx)
await print_balance(ctx)
quote = await wallet.get_pay_amount_with_fees(invoice)
logger.debug(f"Quote: {quote}")
total_amount = quote.amount + quote.fee_reserve
@@ -219,7 +219,7 @@ async def pay(ctx: Context, invoice: str, yes: bool):
print(f" (Preimage: {melt_response.payment_preimage}).")
else:
print(".")
print_balance(ctx)
await print_balance(ctx)
@cli.command("invoice", help="Create Lighting invoice.")
@@ -242,11 +242,12 @@ async def pay(ctx: Context, invoice: str, yes: bool):
)
@click.pass_context
@coro
async def invoice(ctx: Context, amount: int, id: str, split: int, no_check: bool):
async def invoice(ctx: Context, amount: float, id: str, split: int, no_check: bool):
wallet: Wallet = ctx.obj["WALLET"]
await wallet.load_mint()
print_balance(ctx)
await print_balance(ctx)
amount = int(amount * 100) if wallet.unit == Unit.usd else int(amount)
print(f"Requesting invoice for {wallet.unit.str(amount)} {wallet.unit}.")
# in case the user wants a specific split, we create a list of amounts
optional_split = None
if split:
@@ -305,7 +306,7 @@ async def invoice(ctx: Context, amount: int, id: str, split: int, no_check: bool
elif amount and id:
await wallet.mint(amount, split=optional_split, id=id)
print("")
print_balance(ctx)
await print_balance(ctx)
return
@@ -474,7 +475,7 @@ async def send_command(
await send_nostr(
wallet, amount=amount, pubkey=nostr or nopt, verbose=verbose, yes=yes
)
print_balance(ctx)
await print_balance(ctx)
@cli.command("receive", help="Receive tokens.")
@@ -508,8 +509,9 @@ async def receive_cli(
mint_url, os.path.join(settings.cashu_dir, wallet.name)
)
await verify_mint(mint_wallet, mint_url)
receive_wallet = await receive(wallet, tokenObj)
ctx.obj["WALLET"] = receive_wallet
await receive(wallet, tokenObj)
elif nostr:
await receive_nostr(wallet)
# exit on keypress
@@ -530,11 +532,12 @@ async def receive_cli(
mint_url, os.path.join(settings.cashu_dir, wallet.name)
)
await verify_mint(mint_wallet, mint_url)
await receive(wallet, tokenObj)
receive_wallet = await receive(wallet, tokenObj)
ctx.obj["WALLET"] = receive_wallet
else:
print("Error: enter token or use either flag --nostr or --all.")
return
print_balance(ctx)
await print_balance(ctx)
@cli.command("burn", help="Burn spent tokens.")
@@ -586,7 +589,7 @@ async def burn(ctx: Context, token: str, all: bool, force: bool, delete: str):
for i in range(0, len(proofs), settings.proofs_batch_size)
]:
await wallet.invalidate(_proofs, check_spendable=True)
print_balance(ctx)
await print_balance(ctx)
@cli.command("pending", help="Show pending tokens.")
@@ -865,7 +868,7 @@ async def restore(ctx: Context, to: int, batch: int):
await wallet.restore_wallet_from_mnemonic(mnemonic, to=to, batch=batch)
await wallet.load_proofs()
print_balance(ctx)
await print_balance(ctx)
@cli.command("selfpay", help="Refresh tokens.")