Browse Source

fix schema so payments can be sent between lnbits wallets.

fee_issues
fiatjaf 5 years ago
parent
commit
ce94fc8984
  1. 9
      LNbits/__init__.py
  2. 4
      LNbits/bolt11.py
  3. 6
      LNbits/data/schema.sql

9
LNbits/__init__.py

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

4
LNbits/bolt11.py

@ -49,9 +49,9 @@ def decode(pr: str) -> Invoice:
if tag == "d": if tag == "d":
invoice.description = trim_to_bytes(tagdata).decode("utf-8") invoice.description = trim_to_bytes(tagdata).decode("utf-8")
elif tag == "h" and data_length == 52: 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: 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 return invoice

6
LNbits/data/schema.sql

@ -13,13 +13,15 @@ CREATE TABLE IF NOT EXISTS wallets (
); );
CREATE TABLE IF NOT EXISTS apipayments ( CREATE TABLE IF NOT EXISTS apipayments (
payhash text PRIMARY KEY, payhash text NOT NULL,
amount integer NOT NULL, amount integer NOT NULL,
fee integer NOT NULL DEFAULT 0, fee integer NOT NULL DEFAULT 0,
wallet text NOT NULL, wallet text NOT NULL,
pending boolean NOT NULL, pending boolean NOT NULL,
memo text, 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 CREATE VIEW IF NOT EXISTS balances AS

Loading…
Cancel
Save