[Mint] Fix: check keyset id in mint and allow custom split amounts for LIGHTNING=False (#253)

* check keyset existence and return error

* fix split specific amounts for LIGHTNING=False

* wallet loading

* remove wallet balance checks
This commit is contained in:
callebtc
2023-06-18 14:00:34 +02:00
committed by GitHub
parent 67caf5f532
commit 12bc0c23cb
4 changed files with 6 additions and 5 deletions

View File

@@ -191,6 +191,7 @@ class Ledger:
if not proof.id: if not proof.id:
private_key_amount = self.keyset.private_keys[proof.amount] private_key_amount = self.keyset.private_keys[proof.amount]
else: else:
assert proof.id in self.keysets.keysets, f"keyset {proof.id} unknown"
logger.trace( logger.trace(
f"Validating proof with keyset {self.keysets.keysets[proof.id].id}." f"Validating proof with keyset {self.keysets.keysets[proof.id].id}."
) )

View File

@@ -160,10 +160,10 @@ async def invoice(ctx: Context, amount: int, hash: str, split: int):
assert amount >= split, "split must smaller or equal amount" assert amount >= split, "split must smaller or equal amount"
n_splits = amount // split n_splits = amount // split
optional_split = [split] * n_splits optional_split = [split] * n_splits
print(f"Requesting split with {n_splits}*{split} sat tokens.") logger.debug(f"Requesting split with {n_splits} * {split} sat tokens.")
if not settings.lightning: if not settings.lightning:
r = await wallet.mint(amount) r = await wallet.mint(amount, split=optional_split)
# user requests an invoice # user requests an invoice
elif amount and not hash: elif amount and not hash:
invoice = await wallet.request_mint(amount) invoice = await wallet.request_mint(amount)

View File

@@ -253,7 +253,7 @@ class LedgerAPI:
url + "/keys", url + "/keys",
) )
resp.raise_for_status() resp.raise_for_status()
keys = resp.json() keys: dict = resp.json()
assert len(keys), Exception("did not receive any keys") assert len(keys), Exception("did not receive any keys")
keyset_keys = { keyset_keys = {
int(amt): PublicKey(bytes.fromhex(val), raw=True) int(amt): PublicKey(bytes.fromhex(val), raw=True)
@@ -536,6 +536,7 @@ class Wallet(LedgerAPI):
""" """
# specific split # specific split
if split: if split:
logger.trace(f"Mint with split: {split}")
assert sum(split) == amount, "split must sum to amount" assert sum(split) == amount, "split must sum to amount"
for a in split: for a in split:
if a not in [2**i for i in range(settings.max_order)]: if a not in [2**i for i in range(settings.max_order)]:

View File

@@ -41,8 +41,7 @@ async def test_invoice_with_split(wallet: Wallet):
assert response.json()["invoice"] assert response.json()["invoice"]
else: else:
assert response.json()["amount"] assert response.json()["amount"]
# wallet = asyncio.run(init_wallet()) # await wallet.load_proofs(reload=True)
# asyncio.run(wallet.load_proofs())
# assert wallet.proof_amounts.count(1) >= 10 # assert wallet.proof_amounts.count(1) >= 10