Merge pull request #228 from evildido/fix-concurrent-withdraw
Fix concurrent withdrawal behavior
This commit is contained in:
commit
0a884e8983
1 changed files with 19 additions and 7 deletions
|
|
@ -98,19 +98,21 @@ async def api_lnurl_callback(unique_hash):
|
||||||
HTTPStatus.OK,
|
HTTPStatus.OK,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
await pay_invoice(
|
|
||||||
wallet_id=link.wallet,
|
|
||||||
payment_request=payment_request,
|
|
||||||
max_sat=link.max_withdrawable,
|
|
||||||
extra={"tag": "withdraw"},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
try:
|
||||||
usescsv = ""
|
usescsv = ""
|
||||||
for x in range(1, link.uses - link.used):
|
for x in range(1, link.uses - link.used):
|
||||||
usecv = link.usescsv.split(",")
|
usecv = link.usescsv.split(",")
|
||||||
usescsv += "," + str(usecv[x])
|
usescsv += "," + str(usecv[x])
|
||||||
|
usecsvback = usescsv
|
||||||
usescsv = usescsv[1:]
|
usescsv = usescsv[1:]
|
||||||
|
|
||||||
|
changesback = {
|
||||||
|
"open_time": link.wait_time,
|
||||||
|
"used": link.used,
|
||||||
|
"usescsv": usecsvback,
|
||||||
|
}
|
||||||
|
|
||||||
changes = {
|
changes = {
|
||||||
"open_time": link.wait_time + now,
|
"open_time": link.wait_time + now,
|
||||||
"used": link.used + 1,
|
"used": link.used + 1,
|
||||||
|
|
@ -118,11 +120,21 @@ async def api_lnurl_callback(unique_hash):
|
||||||
}
|
}
|
||||||
|
|
||||||
await update_withdraw_link(link.id, **changes)
|
await update_withdraw_link(link.id, **changes)
|
||||||
|
|
||||||
|
await pay_invoice(
|
||||||
|
wallet_id=link.wallet,
|
||||||
|
payment_request=payment_request,
|
||||||
|
max_sat=link.max_withdrawable,
|
||||||
|
extra={"tag": "withdraw"},
|
||||||
|
)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
|
await update_withdraw_link(link.id, **changesback)
|
||||||
return jsonify({"status": "ERROR", "reason": str(e)})
|
return jsonify({"status": "ERROR", "reason": str(e)})
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
|
await update_withdraw_link(link.id, **changesback)
|
||||||
return jsonify({"status": "ERROR", "reason": "Withdraw link is empty."})
|
return jsonify({"status": "ERROR", "reason": "Withdraw link is empty."})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
await update_withdraw_link(link.id, **changesback)
|
||||||
return jsonify({"status": "ERROR", "reason": str(e)})
|
return jsonify({"status": "ERROR", "reason": str(e)})
|
||||||
|
|
||||||
return jsonify({"status": "OK"}), HTTPStatus.OK
|
return jsonify({"status": "OK"}), HTTPStatus.OK
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue