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:
|
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}."
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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)]:
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user