Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blink: return preimage #447

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading