mirror of
https://github.com/fusion44/blitz_api.git
synced 2026-08-16 12:20:14 +02:00
feat: check pay status before attempting payment
CLN returns no error when a payment was already completed before. This commit adds a check to the payment status before attempting to complete the payment. If the payment was already completed, the API returns an exception.
This commit is contained in:
parent
114b76c3d2
commit
60bb7e519f
1 changed files with 21 additions and 1 deletions
|
|
@ -516,6 +516,23 @@ class LnNodeCLNjRPC(LightningNodeBase):
|
|||
# [retry_for] [maxdelay] [exemptfee] [localinvreqid] [exclude]
|
||||
# [maxfee] [description]
|
||||
|
||||
res = await self._send_request("listpays", {"bolt11": pay_req})
|
||||
if "error" in res:
|
||||
e = res["error"]["message"]
|
||||
if "Invalid invstring: unexpected prefix" in e:
|
||||
raise HTTPException(
|
||||
status.HTTP_400_BAD_REQUEST,
|
||||
detail="invalid bech32 string",
|
||||
)
|
||||
|
||||
self._raise_internal_server_error("checking if invoice was paid", res)
|
||||
|
||||
pays = res["result"]["pays"]
|
||||
if len(pays) > 0 and pays[0]["status"] == "complete":
|
||||
raise HTTPException(
|
||||
status.HTTP_409_CONFLICT, detail="invoice is already paid"
|
||||
)
|
||||
|
||||
params = {
|
||||
"bolt11": pay_req,
|
||||
"maxfee": fee_limit_msat,
|
||||
|
|
@ -549,7 +566,10 @@ class LnNodeCLNjRPC(LightningNodeBase):
|
|||
detail="amount must be specified when paying a zero amount invoice",
|
||||
)
|
||||
|
||||
if "amount_msat parameter unnecessary" in message:
|
||||
if (
|
||||
"amount_msat parameter unnecessary" in message
|
||||
or "msatoshi parameter unnecessary" in message
|
||||
):
|
||||
raise HTTPException(
|
||||
status.HTTP_400_BAD_REQUEST,
|
||||
detail="amount must not be specified when paying a non-zero amount invoice",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue