Browse Source

internal invoices resolved internally.

fee_issues
fiatjaf 5 years ago
parent
commit
21598f862d
  1. 40
      LNbits/__init__.py

40
LNbits/__init__.py

@ -280,25 +280,31 @@ def api_transactions():
# check balance # check balance
balance = db.fetchone("SELECT balance/1000 FROM balances WHERE wallet = ?", (wallet["id"],))[0] balance = db.fetchone("SELECT balance/1000 FROM balances WHERE wallet = ?", (wallet["id"],))[0]
if balance < 0: if balance < 0:
db.execute("DELETE FROM apipayments WHERE payhash = ? AND wallet = ?", (invoice.payment_hash, wallet["id"]))
return jsonify({"ERROR": "INSUFFICIENT BALANCE"}), 403 return jsonify({"ERROR": "INSUFFICIENT BALANCE"}), 403
# actually send the payment # check if the invoice is an internal one
r = WALLET.pay_invoice(data["payment_request"]) if db.fetchone("SELECT count(*) FROM apipayments WHERE payhash = ?", (invoice.payment_hash,))[0] == 2:
if not r.ok or r.json().get('error'): # internal. mark both sides as fulfilled.
return jsonify({"ERROR": "UNEXPECTED PAYMENT ERROR"}), 500 db.execute("UPDATE apipayments SET pending = 0, fee = 0 WHERE payhash = ?", (invoice.payment_hash,))
else:
data = r.json() # actually send the payment
if r.ok and "error" in data: r = WALLET.pay_invoice(data["payment_request"])
# payment didn't went through, delete it here if not r.ok or r.json().get('error'):
# (these guarantees specific to lntxbot) return jsonify({"ERROR": "UNEXPECTED PAYMENT ERROR"}), 500
db.execute("DELETE FROM apipayments WHERE payhash = ?", (invoice.payment_hash,))
return jsonify({"PAID": "FALSE"}), 200 data = r.json()
if r.ok and "error" in data:
# payment went through, not pending anymore, save actual fees # payment didn't went through, delete it here
db.execute( # (these guarantees specific to lntxbot)
"UPDATE apipayments SET pending = 0, fee = ? WHERE payhash = ? AND wallet = ?", db.execute("DELETE FROM apipayments WHERE payhash = ?", (invoice.payment_hash,))
(data["fee_msat"], invoice.payment_hash, wallet['id']), return jsonify({"PAID": "FALSE"}), 200
)
# payment went through, not pending anymore, save actual fees
db.execute(
"UPDATE apipayments SET pending = 0, fee = ? WHERE payhash = ? AND wallet = ?",
(data["fee_msat"], invoice.payment_hash, wallet['id']),
)
return jsonify({"PAID": "TRUE"}), 200 return jsonify({"PAID": "TRUE"}), 200

Loading…
Cancel
Save