From d5f226c15b3beb6a76288e268383d815fe1c0116 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Mon, 19 Feb 2024 20:13:58 +0100 Subject: [PATCH] blink: return preimage --- cashu/lightning/blink.py | 20 ++++++++++++++++++-- tests/test_mint_lightning_blink.py | 12 ++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/cashu/lightning/blink.py b/cashu/lightning/blink.py index 625419d8..5379120b 100644 --- a/cashu/lightning/blink.py +++ b/cashu/lightning/blink.py @@ -223,13 +223,20 @@ async def pay_invoice( .get("transaction", {}) .get("settlementFee") ) + checking_id = quote.request + # we check the payment status to get the preimage + preimage: Union[None, str] = None + payment_status = await self.get_payment_status(checking_id) + if payment_status.paid: + preimage = payment_status.preimage + return PaymentResponse( ok=paid, checking_id=checking_id, fee=Amount(Unit.sat, fee) if fee else None, - preimage=None, + preimage=preimage, error_message=error_message, ) @@ -283,6 +290,14 @@ async def get_payment_status(self, checking_id: str) -> PaymentStatus: status direction settlementFee + settlementVia { + ... on SettlementViaIntraLedger { + preImage + } + ... on SettlementViaLn { + preImage + } + } } } } @@ -348,11 +363,12 @@ async def get_payment_status(self, checking_id: str) -> PaymentStatus: # we read the status of the payment paid = self.payment_statuses[payment["status"]] fee = payment["settlementFee"] + preimage = payment["settlementVia"].get("preImage") return PaymentStatus( paid=paid, fee=Amount(Unit.sat, fee), - preimage=None, + preimage=preimage, ) async def get_payment_quote(self, bolt11: str) -> PaymentQuoteResponse: diff --git a/tests/test_mint_lightning_blink.py b/tests/test_mint_lightning_blink.py index 739af2ee..224a6358 100644 --- a/tests/test_mint_lightning_blink.py +++ b/tests/test_mint_lightning_blink.py @@ -79,7 +79,12 @@ async def test_blink_pay_invoice(): "data": { "lnInvoicePaymentSend": { "status": "SUCCESS", - "transaction": {"settlementFee": 10}, + "transaction": { + "settlementFee": 10, + "settlementVia": { + "preImage": "123", + }, + }, } } } @@ -163,6 +168,9 @@ async def test_blink_get_payment_status(): "status": "SUCCESS", "settlementFee": 10, "direction": "SEND", + "settlementVia": { + "preImage": "123", + }, } ] } @@ -175,7 +183,7 @@ async def test_blink_get_payment_status(): assert status.paid assert status.fee assert status.fee.amount == 10 - assert status.preimage is None + assert status.preimage == "123" @respx.mock