fix: handle extra updates for internal payments
This commit is contained in:
+14
-8
@@ -452,18 +452,27 @@ async def update_payment_details(
|
||||
|
||||
|
||||
async def update_payment_extra(
|
||||
payment_hash: str,
|
||||
hash: str,
|
||||
extra: dict,
|
||||
outgoing: bool = False,
|
||||
incoming: bool = False,
|
||||
conn: Optional[Connection] = None,
|
||||
) -> None:
|
||||
"""
|
||||
Only update the `extra` field for the payment.
|
||||
Old values in the `extra` JSON object will be kept unless the new `extra` overwrites them.
|
||||
"""
|
||||
amount_clause = ""
|
||||
|
||||
if outgoing != incoming:
|
||||
if outgoing:
|
||||
amount_clause = "AND amount < 0"
|
||||
else:
|
||||
amount_clause = "AND amount > 0"
|
||||
|
||||
row = await (conn or db).fetchone(
|
||||
"SELECT hash, extra from apipayments WHERE hash = ?",
|
||||
(payment_hash,),
|
||||
f"SELECT hash, extra from apipayments WHERE hash = ? {amount_clause}",
|
||||
(hash,),
|
||||
)
|
||||
if not row:
|
||||
return
|
||||
@@ -471,11 +480,8 @@ async def update_payment_extra(
|
||||
db_extra.update(extra)
|
||||
|
||||
await (conn or db).execute(
|
||||
"""
|
||||
UPDATE apipayments SET extra = ?
|
||||
WHERE hash = ?
|
||||
""",
|
||||
(json.dumps(db_extra), payment_hash),
|
||||
f"UPDATE apipayments SET extra = ? WHERE hash = ? {amount_clause} ",
|
||||
(json.dumps(db_extra), hash),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user