mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 18:44:20 +01:00
[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:
@@ -191,6 +191,7 @@ class Ledger:
|
||||
if not proof.id:
|
||||
private_key_amount = self.keyset.private_keys[proof.amount]
|
||||
else:
|
||||
assert proof.id in self.keysets.keysets, f"keyset {proof.id} unknown"
|
||||
logger.trace(
|
||||
f"Validating proof with keyset {self.keysets.keysets[proof.id].id}."
|
||||
)
|
||||
|
||||
@@ -160,10 +160,10 @@ async def invoice(ctx: Context, amount: int, hash: str, split: int):
|
||||
assert amount >= split, "split must smaller or equal amount"
|
||||
n_splits = amount // split
|
||||
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:
|
||||
r = await wallet.mint(amount)
|
||||
r = await wallet.mint(amount, split=optional_split)
|
||||
# user requests an invoice
|
||||
elif amount and not hash:
|
||||
invoice = await wallet.request_mint(amount)
|
||||
|
||||
@@ -253,7 +253,7 @@ class LedgerAPI:
|
||||
url + "/keys",
|
||||
)
|
||||
resp.raise_for_status()
|
||||
keys = resp.json()
|
||||
keys: dict = resp.json()
|
||||
assert len(keys), Exception("did not receive any keys")
|
||||
keyset_keys = {
|
||||
int(amt): PublicKey(bytes.fromhex(val), raw=True)
|
||||
@@ -536,6 +536,7 @@ class Wallet(LedgerAPI):
|
||||
"""
|
||||
# specific split
|
||||
if split:
|
||||
logger.trace(f"Mint with split: {split}")
|
||||
assert sum(split) == amount, "split must sum to amount"
|
||||
for a in split:
|
||||
if a not in [2**i for i in range(settings.max_order)]:
|
||||
|
||||
@@ -41,8 +41,7 @@ async def test_invoice_with_split(wallet: Wallet):
|
||||
assert response.json()["invoice"]
|
||||
else:
|
||||
assert response.json()["amount"]
|
||||
# wallet = asyncio.run(init_wallet())
|
||||
# asyncio.run(wallet.load_proofs())
|
||||
# await wallet.load_proofs(reload=True)
|
||||
# assert wallet.proof_amounts.count(1) >= 10
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user