make every request a database transaction.

This commit is contained in:
fiatjaf
2020-09-11 14:17:09 -03:00
committed by fiatjaf
parent 487f082eb2
commit 4855e2cd3d
5 changed files with 174 additions and 159 deletions
+3 -1
View File
@@ -1,4 +1,5 @@
from typing import Optional, Tuple, Dict
from flask import g
try:
from typing import TypedDict # type: ignore
@@ -94,6 +95,7 @@ def pay_invoice(
wallet = get_wallet(wallet_id)
assert wallet, "invalid wallet id"
if wallet.balance_msat < 0:
g.db.rollback()
raise PermissionError("Insufficient balance.")
if internal:
@@ -108,7 +110,7 @@ def pay_invoice(
create_payment(checking_id=checking_id, fee=fee_msat, **payment_kwargs)
delete_payment(temp_id)
else:
raise Exception(error_message or "Unexpected backend error.")
raise Exception(error_message or "Failed to pay_invoice on backend.")
return invoice.payment_hash