Skip to content

Commit

Permalink
blink: return preimage (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc authored Feb 19, 2024
1 parent 1c2c01c commit c630fc8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
20 changes: 18 additions & 2 deletions cashu/lightning/blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -283,6 +290,14 @@ async def get_payment_status(self, checking_id: str) -> PaymentStatus:
status
direction
settlementFee
settlementVia {
... on SettlementViaIntraLedger {
preImage
}
... on SettlementViaLn {
preImage
}
}
}
}
}
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 10 additions & 2 deletions tests/test_mint_lightning_blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ async def test_blink_pay_invoice():
"data": {
"lnInvoicePaymentSend": {
"status": "SUCCESS",
"transaction": {"settlementFee": 10},
"transaction": {
"settlementFee": 10,
"settlementVia": {
"preImage": "123",
},
},
}
}
}
Expand Down Expand Up @@ -163,6 +168,9 @@ async def test_blink_get_payment_status():
"status": "SUCCESS",
"settlementFee": 10,
"direction": "SEND",
"settlementVia": {
"preImage": "123",
},
}
]
}
Expand All @@ -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
Expand Down

0 comments on commit c630fc8

Please sign in to comment.