fix schema so payments can be sent between lnbits wallets.

This commit is contained in:
fiatjaf 2019-12-16 16:23:00 +00:00
parent 377243b9cb
commit ce94fc8984
3 changed files with 10 additions and 9 deletions

View File

@ -20,7 +20,7 @@ app.jinja_env.filters["megajson"] = megajson
def init():
with Database() as db:
with open(os.path.join(LNBITS_PATH, "data", "schema.sql")) as schemafile:
for stmt in schemafile.read().split("\n\n"):
for stmt in schemafile.read().split(";\n\n"):
db.execute(stmt, [])
@ -75,7 +75,6 @@ def lnurlwallet():
params={**withdraw_res.callback.query_params, **{"k1": withdraw_res.k1, "pr": invoice["pay_req"]}},
)
if not r.ok:
print('error2', r.text)
return redirect(url_for('home'))
data = json.loads(r.text)
@ -192,7 +191,7 @@ def wallet():
(usr, wallet_id),
)
transactions = db.fetchall("SELECT * FROM apipayments WHERE wallet = ?", (wallet_id,))
transactions = db.fetchall("SELECT * FROM apipayments WHERE wallet = ? AND pending = 0", (wallet_id,))
return render_template(
"wallet.html", user_wallets=user_wallets, wallet=wallet, user=usr, transactions=transactions,
@ -297,8 +296,8 @@ def api_transactions():
# payment went through, not pending anymore, save actual fees
db.execute(
"UPDATE apipayments SET pending = 0, fee = ? WHERE payhash = ?",
(data["fee_msat"], invoice.payment_hash,),
"UPDATE apipayments SET pending = 0, fee = ? WHERE payhash = ? AND wallet = ?",
(data["fee_msat"], invoice.payment_hash, wallet['id']),
)
return jsonify({"PAID": "TRUE"}), 200

View File

@ -49,9 +49,9 @@ def decode(pr: str) -> Invoice:
if tag == "d":
invoice.description = trim_to_bytes(tagdata).decode("utf-8")
elif tag == "h" and data_length == 52:
invoice.description = str(hexlify(trim_to_bytes(tagdata)))
invoice.description = hexlify(trim_to_bytes(tagdata)).decode('ascii')
elif tag == "p" and data_length == 52:
invoice.payment_hash = str(hexlify(trim_to_bytes(tagdata)))
invoice.payment_hash = hexlify(trim_to_bytes(tagdata)).decode('ascii')
return invoice

View File

@ -13,13 +13,15 @@ CREATE TABLE IF NOT EXISTS wallets (
);
CREATE TABLE IF NOT EXISTS apipayments (
payhash text PRIMARY KEY,
payhash text NOT NULL,
amount integer NOT NULL,
fee integer NOT NULL DEFAULT 0,
wallet text NOT NULL,
pending boolean NOT NULL,
memo text,
time timestamp NOT NULL DEFAULT (strftime('%s', 'now'))
time timestamp NOT NULL DEFAULT (strftime('%s', 'now')),
UNIQUE (wallet, payhash)
);
CREATE VIEW IF NOT EXISTS balances AS