From 5022d4e47fe017f7a899d375b5b4b0719ad08b90 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Fri, 14 Oct 2022 00:05:47 +0200 Subject: [PATCH] test melt without lightning --- cashu/core/base.py | 1 - cashu/mint/ledger.py | 22 +++++++++++++--------- cashu/mint/router.py | 4 ++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/cashu/core/base.py b/cashu/core/base.py index 2eaa808..4cb12e6 100644 --- a/cashu/core/base.py +++ b/cashu/core/base.py @@ -95,7 +95,6 @@ class Invoice(BaseModel): class BlindedMessage(BaseModel): - id: str = "" amount: int B_: str diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index 0ff1827..c9c62cc 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -94,15 +94,13 @@ class Ledger: self, amount: int, B_: PublicKey, keyset: MintKeyset = None ): """Generates a promise for given amount and returns a pair (amount, C').""" - if keyset: - private_key_amount = keyset.private_keys[amount] - else: - private_key_amount = self.keyset.private_keys[amount] # Get the correct key + keyset = keyset if keyset else self.keyset + private_key_amount = keyset.private_keys[amount] C_ = b_dhke.step2_bob(B_, private_key_amount) await self.crud.store_promise( amount=amount, B_=B_.serialize().hex(), C_=C_.serialize().hex(), db=self.db ) - return BlindedSignature(amount=amount, C_=C_.serialize().hex()) + return BlindedSignature(id=keyset.id, amount=amount, C_=C_.serialize().hex()) def _check_spendable(self, proof: Proof): """Checks whether the proof was already spent.""" @@ -277,7 +275,7 @@ class Ledger: # Public methods def get_keyset(self, keyset_id: str = None): - keyset = self.keysets[keyset_id] if keyset_id else self.keyset + keyset = self.keysets.keysets[keyset_id] if keyset_id else self.keyset return {a: p.serialize().hex() for a, p in keyset.public_keys.items()} async def request_mint(self, amount): @@ -332,7 +330,10 @@ class Ledger: "provided proofs not enough for Lightning payment." ) - status, preimage = await self._pay_lightning_invoice(invoice, fees_msat) + if LIGHTNING: + status, preimage = await self._pay_lightning_invoice(invoice, fees_msat) + else: + status, preimage = True, "preimage" if status == True: await self._invalidate_proofs(proofs) return status, preimage @@ -347,8 +348,11 @@ class Ledger: amount = math.ceil(decoded_invoice.amount_msat / 1000) # hack: check if it's internal, if it exists, it will return paid = False, # if id does not exist (not internal), it returns paid = None - paid = await self.lightning.get_invoice_status(decoded_invoice.payment_hash) - internal = paid.paid == False + if LIGHTNING: + paid = await self.lightning.get_invoice_status(decoded_invoice.payment_hash) + internal = paid.paid == False + else: + internal = True fees_msat = fee_reserve(amount * 1000, internal) return fees_msat diff --git a/cashu/mint/router.py b/cashu/mint/router.py index b846ae4..79b3ca7 100644 --- a/cashu/mint/router.py +++ b/cashu/mint/router.py @@ -59,6 +59,7 @@ async def mint( Call this endpoint after `GET /mint`. """ + print(mint_request.dict()) try: promises = await ledger.mint( mint_request.blinded_messages, payment_hash=payment_hash @@ -73,6 +74,7 @@ async def melt(payload: MeltRequest) -> GetMeltResponse: """ Requests tokens to be destroyed and sent out via Lightning. """ + print(payload) ok, preimage = await ledger.melt(payload.proofs, payload.invoice) resp = GetMeltResponse(paid=ok, preimage=preimage) return resp @@ -81,6 +83,7 @@ async def melt(payload: MeltRequest) -> GetMeltResponse: @router.post("/check") async def check_spendable(payload: CheckRequest) -> Dict[int, bool]: """Check whether a secret has been spent already or not.""" + print(payload) return await ledger.check_spendable(payload.proofs) @@ -91,6 +94,7 @@ async def check_fees(payload: CheckFeesRequest) -> CheckFeesResponse: Used by wallets for figuring out the fees they need to supply. This is can be useful for checking whether an invoice is internal (Cashu-to-Cashu). """ + print(payload) fees_msat = await ledger.check_fees(payload.pr) return CheckFeesResponse(fee=fees_msat / 1000)