refactor: use Flask Blueprints to organize extensions
- extensions are now blueprints: keep views, templastes and statics in the same folder
- increase app security using `flask-talisman`
- whenever possible use {{ url_for }} for links between pages
- remove references to non-existing JavaScript code
- add missing favicon.ico
This commit is contained in:
parent
4beb7be852
commit
9e90aabead
29 changed files with 541 additions and 1115 deletions
|
|
@ -1,41 +1,57 @@
|
|||
import uuid
|
||||
import os
|
||||
import json
|
||||
import os
|
||||
import requests
|
||||
import re
|
||||
import uuid
|
||||
|
||||
from flask import Flask, jsonify, render_template, request, redirect, url_for
|
||||
from lnurl import Lnurl, LnurlWithdrawResponse, encode
|
||||
from datetime import datetime
|
||||
from flask import Flask, jsonify, redirect, render_template, request, url_for
|
||||
from flask_talisman import Talisman
|
||||
from lnurl import Lnurl, LnurlWithdrawResponse
|
||||
|
||||
from . import bolt11
|
||||
from .db import Database, ExtDatabase, FauDatabase
|
||||
from .core import core_app
|
||||
from .db import open_db, open_ext_db
|
||||
from .extensions.withdraw import withdraw_ext
|
||||
from .helpers import megajson
|
||||
from .settings import LNBITS_PATH, WALLET, DEFAULT_USER_WALLET_NAME, FEE_RESERVE
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
Talisman(app, content_security_policy={
|
||||
"default-src": [
|
||||
"'self'",
|
||||
"'unsafe-eval'",
|
||||
"'unsafe-inline'",
|
||||
"cdnjs.cloudflare.com",
|
||||
"code.ionicframework.com",
|
||||
"code.jquery.com",
|
||||
"fonts.googleapis.com",
|
||||
"fonts.gstatic.com",
|
||||
"maxcdn.bootstrapcdn.com",
|
||||
]
|
||||
})
|
||||
|
||||
# filters
|
||||
app.jinja_env.filters["megajson"] = megajson
|
||||
|
||||
# blueprints
|
||||
app.register_blueprint(core_app)
|
||||
app.register_blueprint(withdraw_ext, url_prefix="/withdraw")
|
||||
|
||||
|
||||
@app.before_first_request
|
||||
def init():
|
||||
with Database() as db:
|
||||
with open_db() as db:
|
||||
with open(os.path.join(LNBITS_PATH, "data", "schema.sql")) as schemafile:
|
||||
for stmt in schemafile.read().split(";\n\n"):
|
||||
db.execute(stmt, [])
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
return render_template("index.html")
|
||||
|
||||
|
||||
@app.route("/deletewallet")
|
||||
def deletewallet():
|
||||
user_id = request.args.get("usr")
|
||||
wallet_id = request.args.get("wal")
|
||||
|
||||
with Database() as db:
|
||||
with open_db() as db:
|
||||
db.execute(
|
||||
"""
|
||||
UPDATE wallets AS w
|
||||
|
|
@ -94,7 +110,7 @@ def lnurlwallet():
|
|||
data = r.json()
|
||||
break
|
||||
|
||||
with Database() as db:
|
||||
with open_db() as db:
|
||||
wallet_id = uuid.uuid4().hex
|
||||
user_id = uuid.uuid4().hex
|
||||
wallet_name = DEFAULT_USER_WALLET_NAME
|
||||
|
|
@ -135,7 +151,7 @@ def wallet():
|
|||
# just wallet_name: create a user, then generate a wallet_id and create
|
||||
# nothing: create everything
|
||||
|
||||
with Database() as db:
|
||||
with open_db() as db:
|
||||
# ensure this user exists
|
||||
# -------------------------------
|
||||
|
||||
|
|
@ -224,7 +240,7 @@ def wallet():
|
|||
)
|
||||
|
||||
|
||||
@app.route("/v1/invoices", methods=["GET", "POST"])
|
||||
@app.route("/api/v1/invoices", methods=["GET", "POST"])
|
||||
def api_invoices():
|
||||
if request.headers["Content-Type"] != "application/json":
|
||||
return jsonify({"ERROR": "MUST BE JSON"}), 400
|
||||
|
|
@ -232,7 +248,7 @@ def api_invoices():
|
|||
postedjson = request.json
|
||||
|
||||
# Form validation
|
||||
if int(postedjson["value"]) < 0 or not postedjson["memo"].replace(' ','').isalnum():
|
||||
if int(postedjson["value"]) < 0 or not postedjson["memo"].replace(" ", "").isalnum():
|
||||
return jsonify({"ERROR": "FORM ERROR"}), 401
|
||||
|
||||
if "value" not in postedjson:
|
||||
|
|
@ -247,7 +263,7 @@ def api_invoices():
|
|||
if "memo" not in postedjson:
|
||||
return jsonify({"ERROR": "NO MEMO"}), 400
|
||||
|
||||
with Database() as db:
|
||||
with open_db() as db:
|
||||
wallet = db.fetchone(
|
||||
"SELECT id FROM wallets WHERE inkey = ? OR adminkey = ?",
|
||||
(request.headers["Grpc-Metadata-macaroon"], request.headers["Grpc-Metadata-macaroon"],),
|
||||
|
|
@ -271,7 +287,7 @@ def api_invoices():
|
|||
return jsonify({"pay_req": pay_req, "payment_hash": pay_hash}), 200
|
||||
|
||||
|
||||
@app.route("/v1/channels/transactions", methods=["GET", "POST"])
|
||||
@app.route("/api/v1/channels/transactions", methods=["GET", "POST"])
|
||||
def api_transactions():
|
||||
|
||||
if request.headers["Content-Type"] != "application/json":
|
||||
|
|
@ -283,7 +299,7 @@ def api_transactions():
|
|||
if "payment_request" not in data:
|
||||
return jsonify({"ERROR": "NO PAY REQ"}), 400
|
||||
|
||||
with Database() as db:
|
||||
with open_db() as db:
|
||||
wallet = db.fetchone("SELECT id FROM wallets WHERE adminkey = ?", (request.headers["Grpc-Metadata-macaroon"],))
|
||||
|
||||
if not wallet:
|
||||
|
|
@ -332,12 +348,12 @@ def api_transactions():
|
|||
return jsonify({"PAID": "TRUE", "payment_hash": invoice.payment_hash}), 200
|
||||
|
||||
|
||||
@app.route("/v1/invoice/<payhash>", methods=["GET"])
|
||||
@app.route("/api/v1/invoice/<payhash>", methods=["GET"])
|
||||
def api_checkinvoice(payhash):
|
||||
if request.headers["Content-Type"] != "application/json":
|
||||
return jsonify({"ERROR": "MUST BE JSON"}), 400
|
||||
|
||||
with Database() as db:
|
||||
with open_db() as db:
|
||||
payment = db.fetchone(
|
||||
"""
|
||||
SELECT pending
|
||||
|
|
@ -362,12 +378,12 @@ def api_checkinvoice(payhash):
|
|||
return jsonify({"PAID": "TRUE"}), 200
|
||||
|
||||
|
||||
@app.route("/v1/payment/<payhash>", methods=["GET"])
|
||||
@app.route("/api/v1/payment/<payhash>", methods=["GET"])
|
||||
def api_checkpayment(payhash):
|
||||
if request.headers["Content-Type"] != "application/json":
|
||||
return jsonify({"ERROR": "MUST BE JSON"}), 400
|
||||
|
||||
with Database() as db:
|
||||
with open_db() as db:
|
||||
payment = db.fetchone(
|
||||
"""
|
||||
SELECT pending
|
||||
|
|
@ -392,9 +408,9 @@ def api_checkpayment(payhash):
|
|||
return jsonify({"PAID": "TRUE"}), 200
|
||||
|
||||
|
||||
@app.route("/v1/checkpending", methods=["POST"])
|
||||
@app.route("/api/v1/checkpending", methods=["POST"])
|
||||
def api_checkpending():
|
||||
with Database() as db:
|
||||
with open_db() as db:
|
||||
for pendingtx in db.fetchall(
|
||||
"""
|
||||
SELECT
|
||||
|
|
@ -427,10 +443,6 @@ def api_checkpending():
|
|||
return ""
|
||||
|
||||
|
||||
|
||||
|
||||
###########EXTENSIONS STUFF - ADD TO LNFAUCET FOLDER IF POSS
|
||||
|
||||
# Checks DB to see if the extensions are activated or not activated for the user
|
||||
@app.route("/extensions")
|
||||
def extensions():
|
||||
|
|
@ -442,14 +454,13 @@ def extensions():
|
|||
if not len(usr) > 20:
|
||||
return redirect(url_for("home"))
|
||||
|
||||
with Database() as db:
|
||||
|
||||
with open_db() as db:
|
||||
user_wallets = db.fetchall("SELECT * FROM wallets WHERE user = ?", (usr,))
|
||||
|
||||
with ExtDatabase() as Extdd:
|
||||
user_ext = Extdd.fetchall("SELECT * FROM overview WHERE user = ?", (usr,))
|
||||
with open_ext_db() as ext_db:
|
||||
user_ext = ext_db.fetchall("SELECT * FROM overview WHERE user = ?", (usr,))
|
||||
if not user_ext:
|
||||
Extdd.execute(
|
||||
ext_db.execute(
|
||||
"""
|
||||
INSERT OR IGNORE INTO overview (user) VALUES (?)
|
||||
""",
|
||||
|
|
@ -459,283 +470,15 @@ def extensions():
|
|||
|
||||
if lnevents:
|
||||
if int(lnevents) != user_ext[0][1] and int(lnevents) < 2:
|
||||
Extdd.execute("UPDATE overview SET lnevents = ? WHERE user = ?", (int(lnevents),usr,))
|
||||
user_ext = Extdd.fetchall("SELECT * FROM overview WHERE user = ?", (usr,))
|
||||
ext_db.execute("UPDATE overview SET lnevents = ? WHERE user = ?", (int(lnevents), usr,))
|
||||
user_ext = ext_db.fetchall("SELECT * FROM overview WHERE user = ?", (usr,))
|
||||
if lnjoust:
|
||||
if int(lnjoust) != user_ext[0][2] and int(lnjoust) < 2:
|
||||
Extdd.execute("UPDATE overview SET lnjoust = ? WHERE user = ?", (int(lnjoust),usr,))
|
||||
user_ext = Extdd.fetchall("SELECT * FROM overview WHERE user = ?", (usr,))
|
||||
ext_db.execute("UPDATE overview SET lnjoust = ? WHERE user = ?", (int(lnjoust), usr,))
|
||||
user_ext = ext_db.fetchall("SELECT * FROM overview WHERE user = ?", (usr,))
|
||||
if withdraw:
|
||||
if int(withdraw) != user_ext[0][3] and int(withdraw) < 2:
|
||||
Extdd.execute("UPDATE overview SET withdraw = ? WHERE user = ?", (int(withdraw),usr,))
|
||||
user_ext = Extdd.fetchall("SELECT * FROM overview WHERE user = ?", (usr,))
|
||||
ext_db.execute("UPDATE overview SET withdraw = ? WHERE user = ?", (int(withdraw), usr,))
|
||||
user_ext = ext_db.fetchall("SELECT * FROM overview WHERE user = ?", (usr,))
|
||||
|
||||
return render_template(
|
||||
"extensions.html", user_wallets=user_wallets, user=usr, user_ext=user_ext
|
||||
)
|
||||
|
||||
|
||||
# Main withdraw link page
|
||||
@app.route("/withdraw")
|
||||
def withdraw():
|
||||
usr = request.args.get("usr")
|
||||
fauc = request.args.get("fauc")
|
||||
|
||||
if usr:
|
||||
if not len(usr) > 20:
|
||||
return redirect(url_for("home"))
|
||||
|
||||
#Get all the data
|
||||
with Database() as db:
|
||||
user_wallets = db.fetchall("SELECT * FROM wallets WHERE user = ?", (usr,))
|
||||
|
||||
with ExtDatabase() as Extdd:
|
||||
user_ext = Extdd.fetchall("SELECT * FROM overview WHERE user = ?", (usr,))
|
||||
|
||||
with FauDatabase() as Faudb:
|
||||
user_fau = Faudb.fetchall("SELECT * FROM withdraws WHERE usr = ?", (usr,))
|
||||
|
||||
#If del is selected by user from withdraw page, the withdraw link is to be deleted
|
||||
faudel = request.args.get("del")
|
||||
if faudel:
|
||||
Faudb.execute("DELETE FROM withdraws WHERE uni = ?", (faudel,))
|
||||
user_fau = Faudb.fetchall("SELECT * FROM withdraws WHERE usr = ?", (usr,))
|
||||
|
||||
return render_template(
|
||||
"withdraw.html", user_wallets=user_wallets, user=usr, user_ext=user_ext, user_fau=user_fau
|
||||
)
|
||||
|
||||
|
||||
#Returns encoded LNURL if web url and parameter gieven
|
||||
@app.route("/v1/lnurlencode/<urlstr>/<parstr>", methods=["GET"])
|
||||
def api_lnurlencode(urlstr, parstr):
|
||||
|
||||
if not urlstr:
|
||||
return jsonify({"STATUS": "FALSE"}), 200
|
||||
|
||||
with FauDatabase() as Faudb:
|
||||
user_fau = Faudb.fetchall("SELECT * FROM withdraws WHERE uni = ?", (parstr,))
|
||||
randar = user_fau[0][15].split(",")
|
||||
# randar = randar[:-1]
|
||||
print(int(user_fau[0][10])-1)
|
||||
#If "Unique links" selected get correct rand, if not there is only one rand
|
||||
if user_fau[0][12] > 0:
|
||||
rand = randar[user_fau[0][10]-2]
|
||||
print(rand)
|
||||
else:
|
||||
rand = randar[0]
|
||||
|
||||
lnurlstr = encode( "https://" + urlstr + "/v1/lnurlfetch/" + urlstr + "/" + parstr + "/" + rand)
|
||||
|
||||
return jsonify({"STATUS": "TRUE", "LNURL": lnurlstr}), 200
|
||||
|
||||
|
||||
#Returns LNURL json
|
||||
@app.route("/v1/lnurlfetch/<urlstr>/<parstr>/<rand>", methods=["GET"])
|
||||
def api_lnurlfetch(parstr, urlstr, rand):
|
||||
|
||||
if not parstr:
|
||||
return jsonify({"STATUS": "FALSE", "ERROR": "NO WALL ID"}), 200
|
||||
|
||||
if not urlstr:
|
||||
|
||||
return jsonify({"STATUS": "FALSE", "ERROR": "NO URL"}), 200
|
||||
|
||||
with FauDatabase() as Faudb:
|
||||
|
||||
user_fau = Faudb.fetchall("SELECT * FROM withdraws WHERE uni = ?", (parstr,))
|
||||
print(user_fau[0][0])
|
||||
|
||||
k1str = uuid.uuid4().hex
|
||||
|
||||
Faudb.execute("UPDATE withdraws SET withdrawals = ? WHERE uni = ?", (k1str ,parstr,))
|
||||
|
||||
res = LnurlWithdrawResponse(
|
||||
callback='https://' + urlstr + '/v1/lnurlwithdraw/' + rand + '/',
|
||||
k1=k1str,
|
||||
min_withdrawable=user_fau[0][8]*1000,
|
||||
max_withdrawable=user_fau[0][7]*1000,
|
||||
default_description="LNURL withdraw",
|
||||
)
|
||||
print("res")
|
||||
return res.json(), 200
|
||||
|
||||
|
||||
|
||||
#Pays invoice if passed k1 invoice and rand
|
||||
@app.route("/v1/lnurlwithdraw/<rand>/", methods=["GET"])
|
||||
def api_lnurlwithdraw(rand):
|
||||
k1 = request.args.get("k1")
|
||||
pr = request.args.get("pr")
|
||||
print(rand)
|
||||
|
||||
|
||||
if not k1:
|
||||
return jsonify({"STATUS": "FALSE", "ERROR": "NO k1"}), 200
|
||||
|
||||
if not pr:
|
||||
return jsonify({"STATUS": "FALSE", "ERROR": "NO PR"}), 200
|
||||
|
||||
with FauDatabase() as Faudb:
|
||||
user_fau = Faudb.fetchall("SELECT * FROM withdraws WHERE withdrawals = ?", (k1,))
|
||||
|
||||
if not user_fau:
|
||||
return jsonify({"status":"ERROR", "reason":"NO AUTH"}), 400
|
||||
|
||||
if user_fau[0][10] <1:
|
||||
return jsonify({"status":"ERROR", "reason":"withdraw SPENT"}), 400
|
||||
|
||||
# Check withdraw time
|
||||
dt = datetime.now()
|
||||
seconds = dt.timestamp()
|
||||
secspast = seconds - user_fau[0][14]
|
||||
print(secspast)
|
||||
|
||||
if secspast < user_fau[0][11]:
|
||||
return jsonify({"status":"ERROR", "reason":"WAIT " + str(int(user_fau[0][11] - secspast)) + "s"}), 400
|
||||
|
||||
randar = user_fau[0][15].split(",")
|
||||
if rand not in randar:
|
||||
return jsonify({"status":"ERROR", "reason":"BAD AUTH"}), 400
|
||||
if len(randar) > 2:
|
||||
randar.remove(rand)
|
||||
randstr = ','.join(randar)
|
||||
|
||||
print(randstr)
|
||||
|
||||
# Update time and increments
|
||||
upinc = (int(user_fau[0][10]) - 1)
|
||||
Faudb.execute("UPDATE withdraws SET inc = ?, rand = ?, tmestmp = ? WHERE withdrawals = ?", (upinc, randstr, seconds, k1,))
|
||||
|
||||
header = {'Content-Type': 'application/json','Grpc-Metadata-macaroon':str(user_fau[0][4])}
|
||||
|
||||
data = {'payment_request': pr}
|
||||
|
||||
r = requests.post(url = "https://lnbits.com/v1/channels/transactions", headers=header, data=json.dumps(data))
|
||||
|
||||
r_json=r.json()
|
||||
if "ERROR" in r_json:
|
||||
return jsonify({"status":"ERROR", "reason":r_json["ERROR"]}), 400
|
||||
|
||||
with FauDatabase() as Faudb:
|
||||
user_fau = Faudb.fetchall("SELECT * FROM withdraws WHERE withdrawals = ?", (k1,))
|
||||
|
||||
return jsonify({"status":"OK"}), 200
|
||||
|
||||
|
||||
|
||||
@app.route("/withdrawmaker", methods=["GET", "POST"])
|
||||
def withdrawmaker():
|
||||
data = request.json
|
||||
amt = data["amt"]
|
||||
tit = data["tit"]
|
||||
wal = data["wal"]
|
||||
minamt = data["minamt"]
|
||||
maxamt = data["maxamt"]
|
||||
tme = data["tme"]
|
||||
uniq = data["uniq"]
|
||||
usr = data["usr"]
|
||||
wall = wal.split("-")
|
||||
|
||||
#Form validation
|
||||
if int(amt) < 0 or not tit.replace(' ','').isalnum() or wal == "" or int(minamt) < 0 or int(maxamt) < 0 or int(minamt) > int(maxamt) or int(tme) < 0:
|
||||
return jsonify({"ERROR": "FORM ERROR"}), 401
|
||||
|
||||
#If id that means its a link being edited, delet the record first
|
||||
if "id" in data:
|
||||
unid = data["id"].split("-")
|
||||
uni = unid[1]
|
||||
print(data["id"])
|
||||
print(uni)
|
||||
with FauDatabase() as Faudb:
|
||||
Faudb.execute("DELETE FROM withdraws WHERE uni = ?", (unid[1],))
|
||||
else:
|
||||
uni = uuid.uuid4().hex
|
||||
|
||||
# Randomiser for random QR option
|
||||
rand = ""
|
||||
if uniq > 0:
|
||||
for x in range(0,int(amt)):
|
||||
rand += uuid.uuid4().hex[0:5] + ","
|
||||
else:
|
||||
rand = uuid.uuid4().hex[0:5] + ","
|
||||
|
||||
with Database() as dbb:
|
||||
user_wallets = dbb.fetchall("SELECT * FROM wallets WHERE user = ? AND id = ?", (usr,wall[1],))
|
||||
if not user_wallets:
|
||||
return jsonify({"ERROR": "NO WALLET USER"}), 401
|
||||
|
||||
# Get time
|
||||
dt = datetime.now()
|
||||
seconds = dt.timestamp()
|
||||
print(seconds)
|
||||
|
||||
#Add to DB
|
||||
with FauDatabase() as db:
|
||||
db.execute(
|
||||
"INSERT OR IGNORE INTO withdraws (usr, wal, walnme, adm, uni, tit, maxamt, minamt, spent, inc, tme, uniq, withdrawals, tmestmp, rand) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(
|
||||
usr,
|
||||
wall[1],
|
||||
user_wallets[0][1],
|
||||
user_wallets[0][3],
|
||||
uni,
|
||||
tit,
|
||||
maxamt,
|
||||
minamt,
|
||||
0,
|
||||
amt,
|
||||
tme,
|
||||
uniq,
|
||||
0,
|
||||
seconds,
|
||||
rand,
|
||||
),
|
||||
)
|
||||
|
||||
#Get updated records
|
||||
with ExtDatabase() as Extdd:
|
||||
user_ext = Extdd.fetchall("SELECT * FROM overview WHERE user = ?", (usr,))
|
||||
if not user_ext:
|
||||
return jsonify({"ERROR": "NO WALLET USER"}), 401
|
||||
|
||||
with FauDatabase() as Faudb:
|
||||
user_fau = Faudb.fetchall("SELECT * FROM withdraws WHERE usr = ?", (usr,))
|
||||
if not user_fau:
|
||||
return jsonify({"ERROR": "NO WALLET USER"}), 401
|
||||
|
||||
|
||||
return render_template(
|
||||
"withdraw.html", user_wallets=user_wallets, user=usr, user_ext=user_ext, user_fau=user_fau
|
||||
)
|
||||
|
||||
|
||||
#Simple shareable link
|
||||
@app.route("/displaywithdraw", methods=["GET", "POST"])
|
||||
def displaywithdraw():
|
||||
fauid = request.args.get("id")
|
||||
|
||||
with FauDatabase() as Faudb:
|
||||
user_fau = Faudb.fetchall("SELECT * FROM withdraws WHERE uni = ?", (fauid,))
|
||||
|
||||
return render_template(
|
||||
"displaywithdraw.html", user_fau=user_fau,
|
||||
)
|
||||
|
||||
#Simple printable page of links
|
||||
@app.route("/printwithdraw/<urlstr>/", methods=["GET", "POST"])
|
||||
def printwithdraw(urlstr):
|
||||
fauid = request.args.get("id")
|
||||
|
||||
with FauDatabase() as Faudb:
|
||||
user_fau = Faudb.fetchall("SELECT * FROM withdraws WHERE uni = ?", (fauid,))
|
||||
randar = user_fau[0][15].split(",")
|
||||
randar = randar[:-1]
|
||||
lnurlar = []
|
||||
print(len(randar))
|
||||
for d in range(len(randar)):
|
||||
lnurlar.append( encode("https://"+ urlstr +"/v1/lnurlfetch/" + urlstr + "/" + fauid + "/" + randar[d]))
|
||||
|
||||
return render_template(
|
||||
"printwithdraws.html", lnurlar=lnurlar, user_fau=user_fau[0],
|
||||
)
|
||||
return render_template("extensions.html", user_wallets=user_wallets, user=usr, user_ext=user_ext)
|
||||
|
|
|
|||
|
|
@ -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 = hexlify(trim_to_bytes(tagdata)).decode('ascii')
|
||||
invoice.description = hexlify(trim_to_bytes(tagdata)).decode("ascii")
|
||||
elif tag == "p" and data_length == 52:
|
||||
invoice.payment_hash = hexlify(trim_to_bytes(tagdata)).decode('ascii')
|
||||
invoice.payment_hash = hexlify(trim_to_bytes(tagdata)).decode("ascii")
|
||||
|
||||
return invoice
|
||||
|
||||
|
|
|
|||
8
lnbits/core/__init__.py
Normal file
8
lnbits/core/__init__.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from flask import Blueprint
|
||||
|
||||
|
||||
core_app = Blueprint("core", __name__, template_folder="templates")
|
||||
|
||||
|
||||
from .views_api import * # noqa
|
||||
from .views import * # noqa
|
||||
BIN
lnbits/core/static/favicon.ico
Normal file
BIN
lnbits/core/static/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
|
|
@ -13,7 +13,7 @@
|
|||
<section class="content-header">
|
||||
<ol class="breadcrumb">
|
||||
<li>
|
||||
<a href="/"><i class="fa fa-dashboard"></i> Home</a>
|
||||
<a href="{{ url_for('core.home') }}"><i class="fa fa-dashboard"></i> Home</a>
|
||||
</li>
|
||||
</ol>
|
||||
<br /><br />
|
||||
14
lnbits/core/views.py
Normal file
14
lnbits/core/views.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from flask import render_template, send_from_directory
|
||||
from os import path
|
||||
|
||||
from lnbits.core import core_app
|
||||
|
||||
|
||||
@core_app.route("/favicon.ico")
|
||||
def favicon():
|
||||
return send_from_directory(path.join(core_app.root_path, "static"), "favicon.ico")
|
||||
|
||||
|
||||
@core_app.route("/")
|
||||
def home():
|
||||
return render_template("index.html")
|
||||
0
lnbits/core/views_api.py
Normal file
0
lnbits/core/views_api.py
Normal file
71
lnbits/db.py
71
lnbits/db.py
|
|
@ -1,11 +1,13 @@
|
|||
import sqlite3
|
||||
import os
|
||||
from .settings import DATABASE_PATH
|
||||
from .settings import LNBITS_PATH
|
||||
import sqlite3
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from .settings import DATABASE_PATH, LNBITS_PATH
|
||||
|
||||
|
||||
class Database:
|
||||
def __init__(self, db_path: str = DATABASE_PATH):
|
||||
def __init__(self, db_path: str):
|
||||
self.path = db_path
|
||||
self.connection = sqlite3.connect(db_path)
|
||||
self.connection.row_factory = sqlite3.Row
|
||||
|
|
@ -33,60 +35,11 @@ class Database:
|
|||
self.connection.commit()
|
||||
|
||||
|
||||
class ExtDatabase:
|
||||
def __init__(self, db_path: str = os.path.join(LNBITS_PATH, "extensions", "overview.sqlite3")):
|
||||
self.path = db_path
|
||||
self.connection = sqlite3.connect(db_path)
|
||||
self.connection.row_factory = sqlite3.Row
|
||||
self.cursor = self.connection.cursor()
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.cursor.close()
|
||||
self.connection.close()
|
||||
|
||||
def fetchall(self, query: str, values: tuple) -> list:
|
||||
"""Given a query, return cursor.fetchall() rows."""
|
||||
self.cursor.execute(query, values)
|
||||
return self.cursor.fetchall()
|
||||
|
||||
def fetchone(self, query: str, values: tuple):
|
||||
self.cursor.execute(query, values)
|
||||
return self.cursor.fetchone()
|
||||
|
||||
def execute(self, query: str, values: tuple) -> None:
|
||||
"""Given a query, cursor.execute() it."""
|
||||
self.cursor.execute(query, values)
|
||||
self.connection.commit()
|
||||
def open_db(db_path: str = DATABASE_PATH) -> Database:
|
||||
return Database(db_path=db_path)
|
||||
|
||||
|
||||
class FauDatabase:
|
||||
def __init__(self, db_path: str = os.path.join(LNBITS_PATH, "extensions", "faucet", "database.sqlite3")):
|
||||
self.path = db_path
|
||||
self.connection = sqlite3.connect(db_path)
|
||||
self.connection.row_factory = sqlite3.Row
|
||||
self.cursor = self.connection.cursor()
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.cursor.close()
|
||||
self.connection.close()
|
||||
|
||||
def fetchall(self, query: str, values: tuple) -> list:
|
||||
"""Given a query, return cursor.fetchall() rows."""
|
||||
self.cursor.execute(query, values)
|
||||
return self.cursor.fetchall()
|
||||
|
||||
def fetchone(self, query: str, values: tuple):
|
||||
self.cursor.execute(query, values)
|
||||
return self.cursor.fetchone()
|
||||
|
||||
def execute(self, query: str, values: tuple) -> None:
|
||||
"""Given a query, cursor.execute() it."""
|
||||
self.cursor.execute(query, values)
|
||||
self.connection.commit()
|
||||
|
||||
def open_ext_db(extension: Optional[str] = None) -> Database:
|
||||
if extension:
|
||||
return open_db(os.path.join(LNBITS_PATH, "extensions", extension, "database.sqlite3"))
|
||||
return open_db(os.path.join(LNBITS_PATH, "extensions", "overview.sqlite3"))
|
||||
|
|
|
|||
0
lnbits/extensions/events/README.md
Normal file
0
lnbits/extensions/events/README.md
Normal file
0
lnbits/extensions/joust/README.md
Normal file
0
lnbits/extensions/joust/README.md
Normal file
|
|
@ -1,73 +0,0 @@
|
|||
|
||||

|
||||
# LNbits
|
||||
Simple free and open-source Python lightning-network wallet/accounts system. Use https://lnbits.com, or run your own LNbits server!
|
||||
|
||||
LNbits is a very simple server that sits on top of a funding source, and can be used as:
|
||||
* Accounts system to mitigate the risk of exposing applications to your full balance, via unique API keys for each wallet!
|
||||
* Fallback wallet for the LNURL scheme
|
||||
* Instant wallet for LN demonstrations
|
||||
|
||||
The wallet can run on top of any lightning-network funding source such as LND, lntxbot, paywall, opennode, etc. This first BETA release runs on top of lntxbot, other releases coming soon, although if you are impatient, it could be ported to other funding sources relatively easily. Contributors very welcome :)
|
||||
|
||||
LNbits is still in BETA. Please report any vulnerabilities responsibly
|
||||
## LNbits as an account system
|
||||
LNbits is packaged with tools to help manage funds, such as a table of transactions, line chart of spending, export to csv + more to come..
|
||||
|
||||
|
||||

|
||||
|
||||
Each wallet also comes with its own API keys, to help partition the exposure of your funding source.
|
||||
|
||||
(LNbits M5StackSats available here https://github.com/arcbtc/M5StackSats)
|
||||
|
||||

|
||||
|
||||
## LNbits as an LNURL-withdraw fallback
|
||||
LNURL has a fallback scheme, so if scanned by a regular QR code reader it can default to a URL. LNbits exploits this to generate an instant wallet using the LNURL-withdraw.
|
||||
|
||||

|
||||
https://github.com/btcontract/lnurl-rfc/blob/master/spec.md
|
||||
|
||||
Adding **/lnurl?lightning="LNURL-WITHDRAW"** will trigger a withdraw that builds an LNbits wallet.
|
||||
Example use would be an ATM, which utilises LNURL, if the user scans the QR with a regular QR code scanner app, they will stilll be able to access the funds.
|
||||
|
||||

|
||||
|
||||
## LNbits as an insta-wallet
|
||||
Wallets can be easily generated and given out to people at events (one click multi-wallet generation to be added soon).
|
||||
"Go to this website", has a lot less friction than "Download this app".
|
||||
|
||||

|
||||
|
||||
# Running LNbits locally
|
||||
Download this repo
|
||||
|
||||
LNbits uses [Flask](http://flask.pocoo.org/).
|
||||
Feel free to contribute to the project.
|
||||
|
||||
Application dependencies
|
||||
------------------------
|
||||
The application uses [Pipenv][pipenv] to manage Python packages.
|
||||
While in development, you will need to install all dependencies:
|
||||
|
||||
$ pipenv shell
|
||||
$ pipenv install --dev
|
||||
|
||||
You will need to set the variables in .env.example, and rename the file to .env
|
||||
|
||||

|
||||
|
||||
Running the server
|
||||
------------------
|
||||
|
||||
$ flask run
|
||||
|
||||
There is an environment variable called `FLASK_ENV` that has to be set to `development`
|
||||
if you want to run Flask in debug mode with autoreload
|
||||
|
||||
[pipenv]: https://docs.pipenv.org/#install-pipenv-today
|
||||
|
||||
# Tip me
|
||||
If you like this project and might even use or extend it, why not send some tip love!
|
||||
https://paywall.link/to/f4e4e
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
|
||||

|
||||
# LNbits
|
||||
Simple free and open-source Python lightning-network wallet/accounts system. Use https://lnbits.com, or run your own LNbits server!
|
||||
|
||||
LNbits is a very simple server that sits on top of a funding source, and can be used as:
|
||||
* Accounts system to mitigate the risk of exposing applications to your full balance, via unique API keys for each wallet!
|
||||
* Fallback wallet for the LNURL scheme
|
||||
* Instant wallet for LN demonstrations
|
||||
|
||||
The wallet can run on top of any lightning-network funding source such as LND, lntxbot, paywall, opennode, etc. This first BETA release runs on top of lntxbot, other releases coming soon, although if you are impatient, it could be ported to other funding sources relatively easily. Contributors very welcome :)
|
||||
|
||||
LNbits is still in BETA. Please report any vulnerabilities responsibly
|
||||
## LNbits as an account system
|
||||
LNbits is packaged with tools to help manage funds, such as a table of transactions, line chart of spending, export to csv + more to come..
|
||||
|
||||
|
||||

|
||||
|
||||
Each wallet also comes with its own API keys, to help partition the exposure of your funding source.
|
||||
|
||||
(LNbits M5StackSats available here https://github.com/arcbtc/M5StackSats)
|
||||
|
||||

|
||||
|
||||
## LNbits as an LNURL-withdraw fallback
|
||||
LNURL has a fallback scheme, so if scanned by a regular QR code reader it can default to a URL. LNbits exploits this to generate an instant wallet using the LNURL-withdraw.
|
||||
|
||||

|
||||
https://github.com/btcontract/lnurl-rfc/blob/master/spec.md
|
||||
|
||||
Adding **/lnurl?lightning="LNURL-WITHDRAW"** will trigger a withdraw that builds an LNbits wallet.
|
||||
Example use would be an ATM, which utilises LNURL, if the user scans the QR with a regular QR code scanner app, they will stilll be able to access the funds.
|
||||
|
||||

|
||||
|
||||
## LNbits as an insta-wallet
|
||||
Wallets can be easily generated and given out to people at events (one click multi-wallet generation to be added soon).
|
||||
"Go to this website", has a lot less friction than "Download this app".
|
||||
|
||||

|
||||
|
||||
# Running LNbits locally
|
||||
Download this repo
|
||||
|
||||
LNbits uses [Flask](http://flask.pocoo.org/).
|
||||
Feel free to contribute to the project.
|
||||
|
||||
Application dependencies
|
||||
------------------------
|
||||
The application uses [Pipenv][pipenv] to manage Python packages.
|
||||
While in development, you will need to install all dependencies:
|
||||
|
||||
$ pipenv shell
|
||||
$ pipenv install --dev
|
||||
|
||||
You will need to set the variables in .env.example, and rename the file to .env
|
||||
|
||||

|
||||
|
||||
Running the server
|
||||
------------------
|
||||
|
||||
$ flask run
|
||||
|
||||
There is an environment variable called `FLASK_ENV` that has to be set to `development`
|
||||
if you want to run Flask in debug mode with autoreload
|
||||
|
||||
[pipenv]: https://docs.pipenv.org/#install-pipenv-today
|
||||
|
||||
# Tip me
|
||||
If you like this project and might even use or extend it, why not send some tip love!
|
||||
https://paywall.link/to/f4e4e
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
|
||||

|
||||
# LNbits
|
||||
Simple free and open-source Python lightning-network wallet/accounts system. Use https://lnbits.com, or run your own LNbits server!
|
||||
|
||||
LNbits is a very simple server that sits on top of a funding source, and can be used as:
|
||||
* Accounts system to mitigate the risk of exposing applications to your full balance, via unique API keys for each wallet!
|
||||
* Fallback wallet for the LNURL scheme
|
||||
* Instant wallet for LN demonstrations
|
||||
|
||||
The wallet can run on top of any lightning-network funding source such as LND, lntxbot, paywall, opennode, etc. This first BETA release runs on top of lntxbot, other releases coming soon, although if you are impatient, it could be ported to other funding sources relatively easily. Contributors very welcome :)
|
||||
|
||||
LNbits is still in BETA. Please report any vulnerabilities responsibly
|
||||
## LNbits as an account system
|
||||
LNbits is packaged with tools to help manage funds, such as a table of transactions, line chart of spending, export to csv + more to come..
|
||||
|
||||
|
||||

|
||||
|
||||
Each wallet also comes with its own API keys, to help partition the exposure of your funding source.
|
||||
|
||||
(LNbits M5StackSats available here https://github.com/arcbtc/M5StackSats)
|
||||
|
||||

|
||||
|
||||
## LNbits as an LNURL-withdraw fallback
|
||||
LNURL has a fallback scheme, so if scanned by a regular QR code reader it can default to a URL. LNbits exploits this to generate an instant wallet using the LNURL-withdraw.
|
||||
|
||||

|
||||
https://github.com/btcontract/lnurl-rfc/blob/master/spec.md
|
||||
|
||||
Adding **/lnurl?lightning="LNURL-WITHDRAW"** will trigger a withdraw that builds an LNbits wallet.
|
||||
Example use would be an ATM, which utilises LNURL, if the user scans the QR with a regular QR code scanner app, they will stilll be able to access the funds.
|
||||
|
||||

|
||||
|
||||
## LNbits as an insta-wallet
|
||||
Wallets can be easily generated and given out to people at events (one click multi-wallet generation to be added soon).
|
||||
"Go to this website", has a lot less friction than "Download this app".
|
||||
|
||||

|
||||
|
||||
# Running LNbits locally
|
||||
Download this repo
|
||||
|
||||
LNbits uses [Flask](http://flask.pocoo.org/).
|
||||
Feel free to contribute to the project.
|
||||
|
||||
Application dependencies
|
||||
------------------------
|
||||
The application uses [Pipenv][pipenv] to manage Python packages.
|
||||
While in development, you will need to install all dependencies:
|
||||
|
||||
$ pipenv shell
|
||||
$ pipenv install --dev
|
||||
|
||||
You will need to set the variables in .env.example, and rename the file to .env
|
||||
|
||||

|
||||
|
||||
Running the server
|
||||
------------------
|
||||
|
||||
$ flask run
|
||||
|
||||
There is an environment variable called `FLASK_ENV` that has to be set to `development`
|
||||
if you want to run Flask in debug mode with autoreload
|
||||
|
||||
[pipenv]: https://docs.pipenv.org/#install-pipenv-today
|
||||
|
||||
# Tip me
|
||||
If you like this project and might even use or extend it, why not send some tip love!
|
||||
https://paywall.link/to/f4e4e
|
||||
8
lnbits/extensions/withdraw/__init__.py
Normal file
8
lnbits/extensions/withdraw/__init__.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from flask import Blueprint
|
||||
|
||||
|
||||
withdraw_ext = Blueprint("withdraw", __name__, static_folder="static", template_folder="templates")
|
||||
|
||||
|
||||
from .views_api import * # noqa
|
||||
from .views import * # noqa
|
||||
0
lnbits/extensions/withdraw/crud.py
Normal file
0
lnbits/extensions/withdraw/crud.py
Normal file
|
|
@ -1,233 +0,0 @@
|
|||
<!-- @format -->
|
||||
|
||||
{% extends "base.html" %} {% block messages %}
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||
<i class="fa fa-bell-o"></i>
|
||||
<span class="label label-danger">!</span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li class="header"><b>Instant wallet, bookmark to save</b></li>
|
||||
<li></li>
|
||||
</ul>
|
||||
{% endblock %} {% block menuitems %}
|
||||
<li class="treeview">
|
||||
<a href="#">
|
||||
<i class="fa fa-bitcoin"></i> <span>Wallets</span>
|
||||
<i class="fa fa-angle-left pull-right"></i>
|
||||
</a>
|
||||
<ul class="treeview-menu">
|
||||
{% for w in user_wallets %}
|
||||
<li>
|
||||
<a href="wallet?wal={{ w.id }}&usr={{ w.user }}"
|
||||
><i class="fa fa-bolt"></i> {{ w.name }}</a
|
||||
>
|
||||
</li>
|
||||
{% endfor %}
|
||||
<li><a onclick="sidebarmake()">Add a wallet +</a></li>
|
||||
<div id="sidebarmake"></div>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="active treeview">
|
||||
<a href="#">
|
||||
<i class="fa fa-th"></i> <span>Extensions</span>
|
||||
</a>
|
||||
<ul class="treeview-menu">
|
||||
|
||||
|
||||
{% if user_ext[0][1] %}
|
||||
<li>
|
||||
<a href="lnevents?usr={{ user_ext[0][0]}}"
|
||||
><i class="fa fa-bolt"></i> LNEvents</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if user_ext[0][2] %}
|
||||
<li>
|
||||
<a href="lnjoust?usr={{ user_ext[0][0]}}"
|
||||
><i class="fa fa-bolt"></i> LNJoust</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if user_ext[0][3] %}
|
||||
<li>
|
||||
<a href="faucet?usr={{ user_ext[0][0]}}"
|
||||
><i class="fa fa-bolt"></i> Faucet</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
{% endblock %} {% block body %}
|
||||
<!-- Right side column. Contains the navbar and content of the page -->
|
||||
<div class="content-wrapper">
|
||||
<!-- Content Header (Page header) -->
|
||||
<section class="content-header">
|
||||
<h1>
|
||||
Wallet
|
||||
<small
|
||||
>Control panel
|
||||
<div id="wonga"></div
|
||||
></small>
|
||||
</h1>
|
||||
<ol class="breadcrumb">
|
||||
<li>
|
||||
<a href="#"><i class="fa fa-dashboard"></i> Home</a>
|
||||
</li>
|
||||
<li class="active">Extensions</li>
|
||||
|
||||
</ol>
|
||||
<br /><br />
|
||||
<div class="alert alert-danger alert-dismissable">
|
||||
<h4>
|
||||
Bookmark to save your wallet. Wallet is in BETA, use with caution.
|
||||
</h4>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Main content -->
|
||||
<section class="content">
|
||||
<!-- Small boxes (Stat box) -->
|
||||
<div class="row">
|
||||
|
||||
{% if not user_ext[0][2] %}
|
||||
<div class="col-lg-3 col-xs-6">
|
||||
<!-- small box -->
|
||||
<div class="small-box bg-green">
|
||||
<div class="inner">
|
||||
<h3>
|
||||
LNJoust
|
||||
</h3>
|
||||
<p>
|
||||
LN powered Joust gamesmaster
|
||||
</p>
|
||||
</div>
|
||||
<div class="icon">
|
||||
<i class="ion ion-wand"></i>
|
||||
</div>
|
||||
|
||||
<a href="extensions?usr={{user}}&lnjoust=1" class="small-box-footer">
|
||||
Activate <i class="fa fa-arrow-circle-right"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div><!-- ./col -->
|
||||
|
||||
{% else %}
|
||||
<div class="col-lg-3 col-xs-6">
|
||||
<!-- small box -->
|
||||
<div class="small-box bg-green">
|
||||
<div class="inner">
|
||||
<h3>
|
||||
LNJoust
|
||||
</h3>
|
||||
<p>
|
||||
LN powered Joust gamesmaster
|
||||
</p>
|
||||
</div>
|
||||
<div class="icon">
|
||||
<i class="ion ion-wand"></i>
|
||||
</div>
|
||||
<a href="extensions?usr={{user}}&lnjoust=0" class="small-box-footer">
|
||||
Deactivate <i class="fa fa-arrow-circle-right"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div><!-- ./col -->
|
||||
{% endif %}
|
||||
{% if not user_ext[0][1] %}
|
||||
<div class="col-lg-3 col-xs-6">
|
||||
<!-- small box -->
|
||||
<div class="small-box bg-yellow">
|
||||
<div class="inner">
|
||||
<h3>
|
||||
LNEvents
|
||||
</h3>
|
||||
<p>
|
||||
Lightning powered tickets
|
||||
</p>
|
||||
</div>
|
||||
<div class="icon">
|
||||
<i class="ion ion-calendar"></i>
|
||||
</div>
|
||||
<a href="extensions?usr={{user}}&lnevents=1" class="small-box-footer">
|
||||
Activate <i class="fa fa-arrow-circle-right"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div><!-- ./col -->
|
||||
|
||||
{% else %}
|
||||
<div class="col-lg-3 col-xs-6">
|
||||
<!-- small box -->
|
||||
<div class="small-box bg-yellow">
|
||||
<div class="inner">
|
||||
<h3>
|
||||
LNEvents
|
||||
</h3>
|
||||
<p>
|
||||
Lightning powered tickets
|
||||
</p>
|
||||
</div>
|
||||
<div class="icon">
|
||||
<i class="ion ion-calendar"></i>
|
||||
</div>
|
||||
<a href="extensions?usr={{user}}&lnevents=0" class="small-box-footer">
|
||||
Deactivate <i class="fa fa-arrow-circle-right"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div><!-- ./col -->
|
||||
{% endif %}
|
||||
{% if not user_ext[0][3] %}
|
||||
<div class="col-lg-3 col-xs-6">
|
||||
<!-- small box -->
|
||||
<div class="small-box bg-red">
|
||||
<div class="inner">
|
||||
<h3>
|
||||
Faucet
|
||||
</h3>
|
||||
<p>
|
||||
Make LNURL faucets
|
||||
</p>
|
||||
</div>
|
||||
<div class="icon">
|
||||
<i class="ion ion-beer"></i>
|
||||
</div>
|
||||
<a href="extensions?usr={{user}}&faucet=1" class="small-box-footer">
|
||||
Activate <i class="fa fa-arrow-circle-right"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div><!-- ./col -->
|
||||
{% else %}
|
||||
<div class="col-lg-3 col-xs-6">
|
||||
<!-- small box -->
|
||||
<div class="small-box bg-red">
|
||||
<div class="inner">
|
||||
<h3>
|
||||
Faucet
|
||||
</h3>
|
||||
<p>
|
||||
Make LNURL faucets
|
||||
</p>
|
||||
</div>
|
||||
<div class="icon">
|
||||
<i class="ion ion-beer"></i>
|
||||
</div>
|
||||
<a href="extensions?usr={{user}}&faucet=0" class="small-box-footer">
|
||||
Deactivate <i class="fa fa-arrow-circle-right"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div><!-- ./col -->
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- /.content -->
|
||||
</section>
|
||||
|
||||
<script>
|
||||
window.user = {{ user | megajson | safe }}
|
||||
window.user_wallets = {{ user_wallets | megajson | safe }}
|
||||
window.user_ext = {{ user_ext | megajson | safe }}
|
||||
|
||||
</script>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
/>
|
||||
<!-- Ionicons 2.0.0 -->
|
||||
<link
|
||||
href="http://code.ionicframework.com/ionicons/2.0.0/css/ionicons.min.css"
|
||||
href="https://code.ionicframework.com/ionicons/2.0.0/css/ionicons.min.css"
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
/>
|
||||
|
|
@ -43,13 +43,6 @@
|
|||
href="{{ url_for('static', filename='dist/css/skins/_all-skins.min.css') }}"
|
||||
/>
|
||||
|
||||
<!-- iCheck -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
media="screen"
|
||||
href="{{ url_for('static', filename='plugins/iCheck/flat/blue.css') }}"
|
||||
/>
|
||||
|
||||
<!-- Morris chart -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
|
|
@ -64,20 +57,6 @@
|
|||
href="{{ url_for('static', filename='plugins/jvectormap/jquery-jvectormap-1.2.2.css') }}"
|
||||
/>
|
||||
|
||||
<!-- Date Picker -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
media="screen"
|
||||
href="{{ url_for('static', filename='plugins/datepicker/datepicker3.css') }}"
|
||||
/>
|
||||
|
||||
<!-- Daterange picker -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
media="screen"
|
||||
href="{{ url_for('static', filename='plugins/daterangepicker/daterangepicker-bs3.css') }}"
|
||||
/>
|
||||
|
||||
<!-- bootstrap wysihtml5 - text editor -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
|
|
@ -129,7 +108,7 @@
|
|||
<script src="{{ url_for('static', filename='plugins/jQuery/jQuery-2.1.3.min.js') }}"></script>
|
||||
<!-- jQuery UI 1.11.2 -->
|
||||
<script
|
||||
src="http://code.jquery.com/ui/1.11.2/jquery-ui.min.js"
|
||||
src="https://code.jquery.com/ui/1.11.2/jquery-ui.min.js"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
|
||||
|
|
@ -142,7 +121,7 @@
|
|||
type="text/javascript"
|
||||
></script>
|
||||
<!-- Morris.js charts -->
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/morris/morris.min.js') }}"
|
||||
type="text/javascript"
|
||||
|
|
@ -166,26 +145,11 @@
|
|||
src="{{ url_for('static', filename='plugins/knob/jquery.knob.js') }}"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- daterangepicker -->
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/daterangepicker/daterangepicker.js') }}"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- datepicker -->
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/datepicker/bootstrap-datepicker.js') }}"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- Bootstrap WYSIHTML5 -->
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js') }}"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- iCheck -->
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/iCheck/icheck.min.js') }}"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- Slimscroll -->
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/slimScroll/jquery.slimscroll.min.js') }}"
|
||||
|
|
@ -441,7 +405,7 @@ background-color:
|
|||
<div class="wrapper">
|
||||
<header class="main-header">
|
||||
<!-- Logo -->
|
||||
<a href="/" class="logo"><b>LN</b>bits</a>
|
||||
<a href="{{ url_for('core.home') }}" class="logo"><b>LN</b>bits</a>
|
||||
<!-- Header Navbar: style can be found in header.less -->
|
||||
<nav class="navbar navbar-static-top" role="navigation">
|
||||
<!-- Sidebar toggle button-->
|
||||
|
|
@ -475,7 +439,7 @@ background-color:
|
|||
<ul class="sidebar-menu">
|
||||
<li><br/><br/><a href="https://where39.com/"><p>Where39 anon locations</p><img src="static/where39.png" style="width:170px"></a></li>
|
||||
<li><br/><a href="https://github.com/arcbtc/Quickening"><p>The Quickening <$8 PoS</p><img src="static/quick.gif" style="width:170px"></a></li>
|
||||
<li><br/><a href="http://jigawatt.co/"><p>Buy BTC stamps + electronics</p><img src="static/stamps.jpg" style="width:170px"></a></li>
|
||||
<li><br/><a href="https://jigawatt.co/"><p>Buy BTC stamps + electronics</p><img src="static/stamps.jpg" style="width:170px"></a></li>
|
||||
<li><br/><a href="mailto:ben@arc.wales"><h3>Advertise here!</h3></a></li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -531,10 +495,10 @@ function drawwithdraw(data) {
|
|||
console.log(data)
|
||||
|
||||
|
||||
getAjax('/v1/lnurlencode/'+ window.location.hostname + "/" + data, "filla", function(datab) {
|
||||
if (JSON.parse(datab).STATUS == 'TRUE') {
|
||||
console.log(JSON.parse(datab).STATUS)
|
||||
lnurlfau = (JSON.parse(datab).LNURL)
|
||||
getAjax('/withdraw/api/v1/lnurlencode/'+ window.location.hostname + "/" + data, "filla", function(datab) {
|
||||
if (JSON.parse(datab).status == 'TRUE') {
|
||||
console.log(JSON.parse(datab).status)
|
||||
lnurlfau = (JSON.parse(datab).lnurl)
|
||||
|
||||
|
||||
new QRCode(document.getElementById('qrcode'), {
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
<ul class="treeview-menu">
|
||||
{% for w in user_wallets %}
|
||||
<li>
|
||||
<a href="wallet?wal={{ w.id }}&usr={{ w.user }}"
|
||||
<a href="{{ url_for('wallet') }}?wal={{ w.id }}&usr={{ w.user }}"
|
||||
><i class="fa fa-bolt"></i> {{ w.name }}</a
|
||||
>
|
||||
</li>
|
||||
|
|
@ -34,28 +34,14 @@
|
|||
<i class="fa fa-angle-left pull-right"></i>
|
||||
</a>
|
||||
<ul class="treeview-menu">
|
||||
{% if user_ext[0][1] %}
|
||||
<li>
|
||||
<a href="lnevents?usr={{ user_ext[0][0]}}"
|
||||
><i class="fa fa-plus"></i> LNEvents</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if user_ext[0][2] %}
|
||||
<li>
|
||||
<a href="lnjoust?usr={{ user_ext[0][0]}}"
|
||||
><i class="fa fa-plus"></i> LNJoust</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if user_ext[0][3] %}
|
||||
<li>
|
||||
<a href="withdraw?usr={{ user_ext[0][0]}}"
|
||||
<a href="{{ url_for('withdraw.index') }}?usr={{ user_ext[0][0]}}"
|
||||
><i class="fa fa-plus"></i> LNURLw</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li>
|
||||
<a href="extensions?usr={{ user }}"
|
||||
<a href="{{ url_for('extensions') }}?usr={{ user }}"
|
||||
>Manager </a>
|
||||
</li>
|
||||
|
||||
|
|
@ -75,10 +61,10 @@
|
|||
</h1>
|
||||
<ol class="breadcrumb">
|
||||
<li>
|
||||
<a href="/wallet?usr={{ user }}"><i class="fa fa-dashboard"></i> Home</a>
|
||||
<a href="{{ url_for('wallet') }}?usr={{ user }}"><i class="fa fa-dashboard"></i> Home</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/extensions?usr={{ user }}"><li class="fa fa-dashboard">Extensions</li></a>
|
||||
<a href="{{ url_for('extensions') }}?usr={{ user }}"><li class="fa fa-dashboard">Extensions</li></a>
|
||||
</li>
|
||||
<li>
|
||||
<i class="active" class="fa fa-dashboard">Withdraw link maker</i>
|
||||
|
|
@ -239,7 +225,7 @@ function drawChart(user_fau) {
|
|||
"<tr><td style='width: 50%'>" +
|
||||
tx.tit +
|
||||
'</td><td >' +
|
||||
"<a href='" + "/displaywithdraw?id=" + tx.uni + "'>" + tx.uni.substring(0, 4) + "...</a>" +
|
||||
"<a href='" + "{{ url_for('withdraw.display') }}?id=" + tx.uni + "'>" + tx.uni.substring(0, 4) + "...</a>" +
|
||||
'</td><td>' +
|
||||
tx.maxamt +
|
||||
'</td><td>' +
|
||||
|
|
@ -247,11 +233,11 @@ function drawChart(user_fau) {
|
|||
'</td><td>' +
|
||||
tx.tme +
|
||||
'</td><td>' +
|
||||
"<a href='/wallet?usr="+ user +"'>" + tx.uni.substring(0, 4) + "...</a>" +
|
||||
"<a href='{{ url_for('wallet') }}?usr="+ user +"'>" + tx.uni.substring(0, 4) + "...</a>" +
|
||||
'</td><td>' +
|
||||
"<i onclick='editlink("+ i +")'' class='fa fa-edit'></i>" +
|
||||
'</td><td>' +
|
||||
"<b><a style='color:red;' href='" + "/withdraw?del=" + tx.uni + "&usr=" + user +"'>" + "<i class='fa fa-trash'></i>" + "</a></b>" +
|
||||
"<b><a style='color:red;' href='" + "{{ url_for('withdraw.index') }}?del=" + tx.uni + "&usr=" + user +"'>" + "<i class='fa fa-trash'></i>" + "</a></b>" +
|
||||
'</td></tr>' +
|
||||
transactionsHTML
|
||||
document.getElementById('transactions').innerHTML = transactionsHTML
|
||||
|
|
@ -273,7 +259,7 @@ function drawwithdraw() {
|
|||
thewithdraw = walname.split("-");
|
||||
console.log(window.location.hostname + "-" + thewithdraw[1])
|
||||
|
||||
getAjax('/v1/lnurlencode/'+ window.location.hostname + "/" + thewithdraw[1], "filla", function(datab) {
|
||||
getAjax("/withdraw/api/v1/lnurlencode/"+ window.location.hostname + "/" + thewithdraw[1], "filla", function(datab) {
|
||||
if (JSON.parse(datab).STATUS == 'TRUE') {
|
||||
console.log(JSON.parse(datab).STATUS)
|
||||
lnurlfau = (JSON.parse(datab).LNURL)
|
||||
|
|
@ -291,8 +277,8 @@ function drawwithdraw() {
|
|||
if (thewithdraw[2] > 0){
|
||||
document.getElementById('qrcodetxt').innerHTML = lnurlfau
|
||||
+
|
||||
"<a target='_blank' href='/displaywithdraw?id=" + thewithdraw[1] + "'><h4>Shareable link</h4></a>" +
|
||||
"<a target='_blank' href='/printwithdraw/" + window.location.hostname + "/?id=" + thewithdraw[1] + "'><h4>Print all withdraws</h4></a>"
|
||||
"<a target='_blank' href='{{ url_for('withdraw.display') }}?id=" + thewithdraw[1] + "'><h4>Shareable link</h4></a>" +
|
||||
"<a target='_blank' href='/withdraw/printwithdraw/" + window.location.hostname + "/?id=" + thewithdraw[1] + "'><h4>Print all withdraws</h4></a>"
|
||||
document.getElementById("qrcode").style.backgroundColor = "white";
|
||||
document.getElementById("qrcode").style.padding = "20px";
|
||||
}
|
||||
|
|
@ -354,11 +340,11 @@ function postfau(){
|
|||
|
||||
|
||||
postAjax(
|
||||
'/withdrawmaker',
|
||||
"{{ url_for('withdraw.create') }}",
|
||||
JSON.stringify({"tit": tit, "amt": amt, "maxamt": maxamt, "minamt": minamt, "tme": tme, "wal": wal, "usr": user, "uniq": uniq}),
|
||||
"filla",
|
||||
|
||||
function(data) { location.replace("/withdraw?usr=" + user)
|
||||
function(data) { location.replace("{{ url_for('withdraw.index') }}?usr=" + user)
|
||||
})
|
||||
|
||||
|
||||
|
|
@ -496,11 +482,11 @@ function editlinkcont(){
|
|||
|
||||
|
||||
postAjax(
|
||||
'/withdrawmaker',
|
||||
"{{ url_for('withdraw.create') }}",
|
||||
JSON.stringify({"id": unid, "tit": tit, "amt": amt, "maxamt": maxamt, "minamt": minamt, "tme": tme, "wal": wal, "usr": user, "uniq": uniq}),
|
||||
"filla",
|
||||
|
||||
function(data) { location.replace("/withdraw?usr=" + user)
|
||||
function(data) { location.replace("{{ url_for('withdraw.index') }}?usr=" + user)
|
||||
})
|
||||
|
||||
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
/>
|
||||
<!-- Ionicons 2.0.0 -->
|
||||
<link
|
||||
href="http://code.ionicframework.com/ionicons/2.0.0/css/ionicons.min.css"
|
||||
href="https://code.ionicframework.com/ionicons/2.0.0/css/ionicons.min.css"
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
/>
|
||||
|
|
@ -41,13 +41,6 @@
|
|||
href="{{ url_for('static', filename='dist/css/skins/_all-skins.min.css') }}"
|
||||
/>
|
||||
|
||||
<!-- iCheck -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
media="screen"
|
||||
href="{{ url_for('static', filename='plugins/iCheck/flat/blue.css') }}"
|
||||
/>
|
||||
|
||||
<!-- Morris chart -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
|
|
@ -62,20 +55,6 @@
|
|||
href="{{ url_for('static', filename='plugins/jvectormap/jquery-jvectormap-1.2.2.css') }}"
|
||||
/>
|
||||
|
||||
<!-- Date Picker -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
media="screen"
|
||||
href="{{ url_for('static', filename='plugins/datepicker/datepicker3.css') }}"
|
||||
/>
|
||||
|
||||
<!-- Daterange picker -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
media="screen"
|
||||
href="{{ url_for('static', filename='plugins/daterangepicker/daterangepicker-bs3.css') }}"
|
||||
/>
|
||||
|
||||
<!-- bootstrap wysihtml5 - text editor -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
|
|
@ -130,7 +109,7 @@
|
|||
<script src="{{ url_for('static', filename='plugins/jQuery/jQuery-2.1.3.min.js') }}"></script>
|
||||
<!-- jQuery UI 1.11.2 -->
|
||||
<script
|
||||
src="http://code.jquery.com/ui/1.11.2/jquery-ui.min.js"
|
||||
src="https://code.jquery.com/ui/1.11.2/jquery-ui.min.js"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
|
||||
|
|
@ -143,7 +122,7 @@
|
|||
type="text/javascript"
|
||||
></script>
|
||||
<!-- Morris.js charts -->
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/morris/morris.min.js') }}"
|
||||
type="text/javascript"
|
||||
|
|
@ -167,26 +146,11 @@
|
|||
src="{{ url_for('static', filename='plugins/knob/jquery.knob.js') }}"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- daterangepicker -->
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/daterangepicker/daterangepicker.js') }}"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- datepicker -->
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/datepicker/bootstrap-datepicker.js') }}"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- Bootstrap WYSIHTML5 -->
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js') }}"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- iCheck -->
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/iCheck/icheck.min.js') }}"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- Slimscroll -->
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/slimScroll/jquery.slimscroll.min.js') }}"
|
||||
160
lnbits/extensions/withdraw/views.py
Normal file
160
lnbits/extensions/withdraw/views.py
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
import uuid
|
||||
|
||||
from flask import jsonify, render_template, request, redirect, url_for
|
||||
from lnurl import encode as lnurl_encode
|
||||
from datetime import datetime
|
||||
|
||||
from lnbits.db import open_db, open_ext_db
|
||||
from lnbits.extensions.withdraw import withdraw_ext
|
||||
|
||||
|
||||
@withdraw_ext.route("/")
|
||||
def index():
|
||||
"""Main withdraw link page."""
|
||||
|
||||
usr = request.args.get("usr")
|
||||
|
||||
if usr:
|
||||
if not len(usr) > 20:
|
||||
return redirect(url_for("home"))
|
||||
|
||||
# Get all the data
|
||||
with open_db() as db:
|
||||
user_wallets = db.fetchall("SELECT * FROM wallets WHERE user = ?", (usr,))
|
||||
|
||||
with open_ext_db() as ext_db:
|
||||
user_ext = ext_db.fetchall("SELECT * FROM overview WHERE user = ?", (usr,))
|
||||
|
||||
with open_ext_db("withdraw") as withdraw_ext_db:
|
||||
user_fau = withdraw_ext_db.fetchall("SELECT * FROM withdraws WHERE usr = ?", (usr,))
|
||||
|
||||
# If del is selected by user from withdraw page, the withdraw link is to be deleted
|
||||
faudel = request.args.get("del")
|
||||
if faudel:
|
||||
withdraw_ext_db.execute("DELETE FROM withdraws WHERE uni = ?", (faudel,))
|
||||
user_fau = withdraw_ext_db.fetchall("SELECT * FROM withdraws WHERE usr = ?", (usr,))
|
||||
|
||||
return render_template(
|
||||
"withdraw/index.html", user_wallets=user_wallets, user=usr, user_ext=user_ext, user_fau=user_fau
|
||||
)
|
||||
|
||||
|
||||
@withdraw_ext.route("/create", methods=["GET", "POST"])
|
||||
def create():
|
||||
"""."""
|
||||
|
||||
data = request.json
|
||||
amt = data["amt"]
|
||||
tit = data["tit"]
|
||||
wal = data["wal"]
|
||||
minamt = data["minamt"]
|
||||
maxamt = data["maxamt"]
|
||||
tme = data["tme"]
|
||||
uniq = data["uniq"]
|
||||
usr = data["usr"]
|
||||
wall = wal.split("-")
|
||||
|
||||
# Form validation
|
||||
if (
|
||||
int(amt) < 0
|
||||
or not tit.replace(" ", "").isalnum()
|
||||
or wal == ""
|
||||
or int(minamt) < 0
|
||||
or int(maxamt) < 0
|
||||
or int(minamt) > int(maxamt)
|
||||
or int(tme) < 0
|
||||
):
|
||||
return jsonify({"ERROR": "FORM ERROR"}), 401
|
||||
|
||||
# If id that means its a link being edited, delet the record first
|
||||
if "id" in data:
|
||||
unid = data["id"].split("-")
|
||||
uni = unid[1]
|
||||
with open_ext_db("withdraw") as withdraw_ext_db:
|
||||
withdraw_ext_db.execute("DELETE FROM withdraws WHERE uni = ?", (unid[1],))
|
||||
else:
|
||||
uni = uuid.uuid4().hex
|
||||
|
||||
# Randomiser for random QR option
|
||||
rand = ""
|
||||
if uniq > 0:
|
||||
for x in range(0, int(amt)):
|
||||
rand += uuid.uuid4().hex[0:5] + ","
|
||||
else:
|
||||
rand = uuid.uuid4().hex[0:5] + ","
|
||||
|
||||
with open_db() as dbb:
|
||||
user_wallets = dbb.fetchall("SELECT * FROM wallets WHERE user = ? AND id = ?", (usr, wall[1],))
|
||||
if not user_wallets:
|
||||
return jsonify({"ERROR": "NO WALLET USER"}), 401
|
||||
|
||||
# Get time
|
||||
dt = datetime.now()
|
||||
seconds = dt.timestamp()
|
||||
|
||||
# Add to DB
|
||||
with open_ext_db("withdraw") as db:
|
||||
db.execute(
|
||||
"INSERT OR IGNORE INTO withdraws (usr, wal, walnme, adm, uni, tit, maxamt, minamt, spent, inc, tme, uniq, withdrawals, tmestmp, rand) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(
|
||||
usr,
|
||||
wall[1],
|
||||
user_wallets[0][1],
|
||||
user_wallets[0][3],
|
||||
uni,
|
||||
tit,
|
||||
maxamt,
|
||||
minamt,
|
||||
0,
|
||||
amt,
|
||||
tme,
|
||||
uniq,
|
||||
0,
|
||||
seconds,
|
||||
rand,
|
||||
),
|
||||
)
|
||||
|
||||
# Get updated records
|
||||
with open_ext_db() as ext_db:
|
||||
user_ext = ext_db.fetchall("SELECT * FROM overview WHERE user = ?", (usr,))
|
||||
if not user_ext:
|
||||
return jsonify({"ERROR": "NO WALLET USER"}), 401
|
||||
|
||||
with open_ext_db("withdraw") as withdraw_ext_db:
|
||||
user_fau = withdraw_ext_db.fetchall("SELECT * FROM withdraws WHERE usr = ?", (usr,))
|
||||
if not user_fau:
|
||||
return jsonify({"ERROR": "NO WALLET USER"}), 401
|
||||
|
||||
return render_template(
|
||||
"withdraw/index.html", user_wallets=user_wallets, user=usr, user_ext=user_ext, user_fau=user_fau
|
||||
)
|
||||
|
||||
|
||||
@withdraw_ext.route("/display", methods=["GET", "POST"])
|
||||
def display():
|
||||
"""Simple shareable link."""
|
||||
fauid = request.args.get("id")
|
||||
|
||||
with open_ext_db("withdraw") as withdraw_ext_db:
|
||||
user_fau = withdraw_ext_db.fetchall("SELECT * FROM withdraws WHERE uni = ?", (fauid,))
|
||||
|
||||
return render_template("withdraw/display.html", user_fau=user_fau,)
|
||||
|
||||
|
||||
@withdraw_ext.route("/print/<urlstr>/", methods=["GET", "POST"])
|
||||
def print_qr(urlstr):
|
||||
"""Simple printable page of links."""
|
||||
fauid = request.args.get("id")
|
||||
|
||||
with open_ext_db("withdraw") as withdraw_ext_db:
|
||||
user_fau = withdraw_ext_db.fetchall("SELECT * FROM withdraws WHERE uni = ?", (fauid,))
|
||||
randar = user_fau[0][15].split(",")
|
||||
randar = randar[:-1]
|
||||
lnurlar = []
|
||||
|
||||
for d in range(len(randar)):
|
||||
url = url_for("withdraw.api_lnurlfetch", _external=True, urlstr=urlstr, parstr=fauid, rand=randar[d])
|
||||
lnurlar.append(lnurl_encode(url.replace("http", "https")))
|
||||
|
||||
return render_template("withdraw/print.html", lnurlar=lnurlar, user_fau=user_fau[0],)
|
||||
116
lnbits/extensions/withdraw/views_api.py
Normal file
116
lnbits/extensions/withdraw/views_api.py
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
import uuid
|
||||
import json
|
||||
import requests
|
||||
|
||||
from flask import jsonify, request, url_for
|
||||
from lnurl import LnurlWithdrawResponse, encode as lnurl_encode
|
||||
from datetime import datetime
|
||||
|
||||
from lnbits.db import open_ext_db
|
||||
from lnbits.extensions.withdraw import withdraw_ext
|
||||
|
||||
|
||||
@withdraw_ext.route("/api/v1/lnurlencode/<urlstr>/<parstr>", methods=["GET"])
|
||||
def api_lnurlencode(urlstr, parstr):
|
||||
"""Returns encoded LNURL if web url and parameter gieven."""
|
||||
|
||||
if not urlstr:
|
||||
return jsonify({"status": "FALSE"}), 200
|
||||
|
||||
with open_ext_db("withdraw") as withdraw_ext_db:
|
||||
user_fau = withdraw_ext_db.fetchall("SELECT * FROM withdraws WHERE uni = ?", (parstr,))
|
||||
randar = user_fau[0][15].split(",")
|
||||
# randar = randar[:-1]
|
||||
# If "Unique links" selected get correct rand, if not there is only one rand
|
||||
if user_fau[0][12] > 0:
|
||||
rand = randar[user_fau[0][10] - 2]
|
||||
else:
|
||||
rand = randar[0]
|
||||
|
||||
url = url_for("withdraw.api_lnurlfetch", _external=True, urlstr=urlstr, parstr=parstr, rand=rand)
|
||||
|
||||
return jsonify({"status": "TRUE", "lnurl": lnurl_encode(url.replace("http", "https"))}), 200
|
||||
|
||||
|
||||
@withdraw_ext.route("/api/v1/lnurlfetch/<urlstr>/<parstr>/<rand>", methods=["GET"])
|
||||
def api_lnurlfetch(parstr, urlstr, rand):
|
||||
"""Returns LNURL json."""
|
||||
|
||||
if not parstr:
|
||||
return jsonify({"status": "FALSE", "ERROR": "NO WALL ID"}), 200
|
||||
|
||||
if not urlstr:
|
||||
|
||||
return jsonify({"status": "FALSE", "ERROR": "NO URL"}), 200
|
||||
|
||||
with open_ext_db("withdraw") as withdraw_ext_db:
|
||||
user_fau = withdraw_ext_db.fetchall("SELECT * FROM withdraws WHERE uni = ?", (parstr,))
|
||||
k1str = uuid.uuid4().hex
|
||||
withdraw_ext_db.execute("UPDATE withdraws SET withdrawals = ? WHERE uni = ?", (k1str, parstr,))
|
||||
|
||||
res = LnurlWithdrawResponse(
|
||||
callback=url_for("withdraw.api_lnurlwithdraw", _external=True, rand=rand).replace("http", "https"),
|
||||
k1=k1str,
|
||||
min_withdrawable=user_fau[0][8] * 1000,
|
||||
max_withdrawable=user_fau[0][7] * 1000,
|
||||
default_description="LNbits LNURL withdraw",
|
||||
)
|
||||
|
||||
return res.json(), 200
|
||||
|
||||
|
||||
@withdraw_ext.route("/api/v1/lnurlwithdraw/<rand>/", methods=["GET"])
|
||||
def api_lnurlwithdraw(rand):
|
||||
"""Pays invoice if passed k1 invoice and rand."""
|
||||
|
||||
k1 = request.args.get("k1")
|
||||
pr = request.args.get("pr")
|
||||
|
||||
if not k1:
|
||||
return jsonify({"status": "FALSE", "ERROR": "NO k1"}), 200
|
||||
|
||||
if not pr:
|
||||
return jsonify({"status": "FALSE", "ERROR": "NO PR"}), 200
|
||||
|
||||
with open_ext_db("withdraw") as withdraw_ext_db:
|
||||
user_fau = withdraw_ext_db.fetchall("SELECT * FROM withdraws WHERE withdrawals = ?", (k1,))
|
||||
|
||||
if not user_fau:
|
||||
return jsonify({"status": "ERROR", "reason": "NO AUTH"}), 400
|
||||
|
||||
if user_fau[0][10] < 1:
|
||||
return jsonify({"status": "ERROR", "reason": "withdraw SPENT"}), 400
|
||||
|
||||
# Check withdraw time
|
||||
dt = datetime.now()
|
||||
seconds = dt.timestamp()
|
||||
secspast = seconds - user_fau[0][14]
|
||||
|
||||
if secspast < user_fau[0][11]:
|
||||
return jsonify({"status": "ERROR", "reason": "WAIT " + str(int(user_fau[0][11] - secspast)) + "s"}), 400
|
||||
|
||||
randar = user_fau[0][15].split(",")
|
||||
if rand not in randar:
|
||||
return jsonify({"status": "ERROR", "reason": "BAD AUTH"}), 400
|
||||
if len(randar) > 2:
|
||||
randar.remove(rand)
|
||||
randstr = ",".join(randar)
|
||||
|
||||
# Update time and increments
|
||||
upinc = int(user_fau[0][10]) - 1
|
||||
withdraw_ext_db.execute(
|
||||
"UPDATE withdraws SET inc = ?, rand = ?, tmestmp = ? WHERE withdrawals = ?", (upinc, randstr, seconds, k1,)
|
||||
)
|
||||
|
||||
header = {"Content-Type": "application/json", "Grpc-Metadata-macaroon": str(user_fau[0][4])}
|
||||
data = {"payment_request": pr}
|
||||
r = requests.post(url=url_for("api_transactions", _external=True), headers=header, data=json.dumps(data))
|
||||
r_json = r.json()
|
||||
|
||||
if "ERROR" in r_json:
|
||||
return jsonify({"status": "ERROR", "reason": r_json["ERROR"]}), 400
|
||||
|
||||
with open_ext_db("withdraw") as withdraw_ext_db:
|
||||
user_fau = withdraw_ext_db.fetchall("SELECT * FROM withdraws WHERE withdrawals = ?", (k1,))
|
||||
|
||||
return jsonify({"status": "OK"}), 200
|
||||
|
|
@ -3,14 +3,11 @@ import sqlite3
|
|||
|
||||
|
||||
class MegaEncoder(json.JSONEncoder):
|
||||
def default(self, o):
|
||||
if type(o) == sqlite3.Row:
|
||||
val = {}
|
||||
for k in o.keys():
|
||||
val[k] = o[k]
|
||||
return val
|
||||
return o
|
||||
def default(self, obj):
|
||||
if isinstance(obj, sqlite3.Row):
|
||||
return {k: obj[k] for k in obj.keys()}
|
||||
return obj
|
||||
|
||||
|
||||
def megajson(o):
|
||||
return json.dumps(o, cls=MegaEncoder)
|
||||
def megajson(obj):
|
||||
return json.dumps(obj, cls=MegaEncoder)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ WALLET = OpenNodeWallet(endpoint=os.getenv("OPENNODE_API_ENDPOINT"),admin_key=os
|
|||
|
||||
|
||||
LNBITS_PATH = os.path.dirname(os.path.realpath(__file__))
|
||||
DATABASE_PATH = os.getenv("DATABASE_PATH") or os.path.join(LNBITS_PATH, "data", "database.sqlite3")
|
||||
DEFAULT_USER_WALLET_NAME = os.getenv("DEFAULT_USER_WALLET_NAME") or "Bitcoin LN Wallet"
|
||||
DATABASE_PATH = os.getenv("DATABASE_PATH", os.path.join(LNBITS_PATH, "data", "database.sqlite3"))
|
||||
|
||||
FEE_RESERVE = float(os.getenv("FEE_RESERVE") or 0)
|
||||
DEFAULT_USER_WALLET_NAME = os.getenv("DEFAULT_USER_WALLET_NAME", "Bitcoin LN Wallet")
|
||||
FEE_RESERVE = float(os.getenv("FEE_RESERVE", 0))
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ function received() {
|
|||
memo = document.getElementById('memo').value
|
||||
amount = document.getElementById('amount').value
|
||||
postAjax(
|
||||
'/v1/invoices',
|
||||
'/api/v1/invoices',
|
||||
JSON.stringify({value: amount, memo: memo}),
|
||||
wallet.inkey,
|
||||
function(data) {
|
||||
|
|
@ -148,7 +148,7 @@ function received() {
|
|||
|
||||
|
||||
setInterval(function(){
|
||||
getAjax('/v1/invoice/' + thehash, wallet.inkey, function(datab) {
|
||||
getAjax('/api/v1/invoice/' + thehash, wallet.inkey, function(datab) {
|
||||
console.log(JSON.parse(datab).PAID)
|
||||
if (JSON.parse(datab).PAID == 'TRUE') {
|
||||
window.location.href = 'wallet?wal=' + wallet.id + '&usr=' + user
|
||||
|
|
@ -195,7 +195,7 @@ function sendfunds(invoice) {
|
|||
'<h3><b>Processing...</b></h3><</br/></br/></br/></div> ';
|
||||
|
||||
postAjax(
|
||||
'/v1/channels/transactions',
|
||||
'/api/v1/channels/transactions',
|
||||
JSON.stringify({payment_request: invoice}),
|
||||
wallet.adminkey,
|
||||
|
||||
|
|
@ -203,7 +203,7 @@ function sendfunds(invoice) {
|
|||
thehash = JSON.parse(data).payment_hash
|
||||
|
||||
setInterval(function(){
|
||||
getAjax('/v1/payment/' + thehash, wallet.adminkey, function(datab) {
|
||||
getAjax('/api/v1/payment/' + thehash, wallet.adminkey, function(datab) {
|
||||
console.log(JSON.parse(datab).PAID)
|
||||
if (JSON.parse(datab).PAID == 'TRUE') {
|
||||
window.location.href = 'wallet?wal=' + wallet.id + '&usr=' + user
|
||||
|
|
@ -414,7 +414,7 @@ if (transactions.length) {
|
|||
}
|
||||
|
||||
if (wallet) {
|
||||
postAjax('/v1/checkpending', '', wallet.adminkey, function(data) {})
|
||||
postAjax('/api/v1/checkpending', '', wallet.adminkey, function(data) {})
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
7
lnbits/static/dist/js/pages/dashboard.js
vendored
7
lnbits/static/dist/js/pages/dashboard.js
vendored
|
|
@ -9,10 +9,10 @@
|
|||
$(function () {
|
||||
|
||||
//Activate the iCheck Plugin
|
||||
$('input[type="checkbox"]').iCheck({
|
||||
/*$('input[type="checkbox"]').iCheck({
|
||||
checkboxClass: 'icheckbox_flat-blue',
|
||||
radioClass: 'iradio_flat-blue'
|
||||
});
|
||||
});*/
|
||||
//Make the dashboard widgets sortable Using jquery UI
|
||||
$(".connectedSortable").sortable({
|
||||
placeholder: "sort-highlight",
|
||||
|
|
@ -33,6 +33,7 @@ $(function () {
|
|||
//bootstrap WYSIHTML5 - text editor
|
||||
$(".textarea").wysihtml5();
|
||||
|
||||
/*
|
||||
$('.daterange').daterangepicker(
|
||||
{
|
||||
ranges: {
|
||||
|
|
@ -48,7 +49,7 @@ $(function () {
|
|||
},
|
||||
function (start, end) {
|
||||
alert("You chose: " + start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
|
||||
});
|
||||
});*/
|
||||
|
||||
/* jQueryKnob */
|
||||
$(".knob").knob();
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
/>
|
||||
<!-- Ionicons 2.0.0 -->
|
||||
<link
|
||||
href="http://code.ionicframework.com/ionicons/2.0.0/css/ionicons.min.css"
|
||||
href="https://code.ionicframework.com/ionicons/2.0.0/css/ionicons.min.css"
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
/>
|
||||
|
|
@ -43,13 +43,6 @@
|
|||
href="{{ url_for('static', filename='dist/css/skins/_all-skins.min.css') }}"
|
||||
/>
|
||||
|
||||
<!-- iCheck -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
media="screen"
|
||||
href="{{ url_for('static', filename='plugins/iCheck/flat/blue.css') }}"
|
||||
/>
|
||||
|
||||
<!-- Morris chart -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
|
|
@ -64,20 +57,6 @@
|
|||
href="{{ url_for('static', filename='plugins/jvectormap/jquery-jvectormap-1.2.2.css') }}"
|
||||
/>
|
||||
|
||||
<!-- Date Picker -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
media="screen"
|
||||
href="{{ url_for('static', filename='plugins/datepicker/datepicker3.css') }}"
|
||||
/>
|
||||
|
||||
<!-- Daterange picker -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
media="screen"
|
||||
href="{{ url_for('static', filename='plugins/daterangepicker/daterangepicker-bs3.css') }}"
|
||||
/>
|
||||
|
||||
<!-- bootstrap wysihtml5 - text editor -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
|
|
@ -129,7 +108,7 @@
|
|||
<script src="{{ url_for('static', filename='plugins/jQuery/jQuery-2.1.3.min.js') }}"></script>
|
||||
<!-- jQuery UI 1.11.2 -->
|
||||
<script
|
||||
src="http://code.jquery.com/ui/1.11.2/jquery-ui.min.js"
|
||||
src="https://code.jquery.com/ui/1.11.2/jquery-ui.min.js"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
|
||||
|
|
@ -142,7 +121,7 @@
|
|||
type="text/javascript"
|
||||
></script>
|
||||
<!-- Morris.js charts -->
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/morris/morris.min.js') }}"
|
||||
type="text/javascript"
|
||||
|
|
@ -166,26 +145,11 @@
|
|||
src="{{ url_for('static', filename='plugins/knob/jquery.knob.js') }}"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- daterangepicker -->
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/daterangepicker/daterangepicker.js') }}"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- datepicker -->
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/datepicker/bootstrap-datepicker.js') }}"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- Bootstrap WYSIHTML5 -->
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js') }}"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- iCheck -->
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/iCheck/icheck.min.js') }}"
|
||||
type="text/javascript"
|
||||
></script>
|
||||
<!-- Slimscroll -->
|
||||
<script
|
||||
src="{{ url_for('static', filename='plugins/slimScroll/jquery.slimscroll.min.js') }}"
|
||||
|
|
@ -438,7 +402,7 @@ body {
|
|||
<div class="wrapper">
|
||||
<header class="main-header">
|
||||
<!-- Logo -->
|
||||
<a href="/" class="logo"><b style="color: #8964a9;">LN</b>bits</a>
|
||||
<a href="{{ url_for('core.home') }}" class="logo"><b style="color: #8964a9;">LN</b>bits</a>
|
||||
<!-- Header Navbar: style can be found in header.less -->
|
||||
<nav class="navbar navbar-static-top" role="navigation">
|
||||
<!-- Sidebar toggle button-->
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@
|
|||
<div class="box-body" style="word-wrap: break-word;">
|
||||
<b>Admin key: </b><i>{{ wallet.adminkey }}</i><br />
|
||||
<b>Invoice/Read key: </b><i>{{ wallet.inkey }}</i><br />
|
||||
Generate an invoice:<br /><code>POST /v1/invoices</code
|
||||
Generate an invoice:<br /><code>POST /api/v1/invoices</code
|
||||
><br />Header
|
||||
<code
|
||||
>{"Grpc-Metadata-macaroon": "<i>{{ wallet.inkey }}</i
|
||||
|
|
@ -187,7 +187,7 @@
|
|||
|
||||
Check invoice:<br />
|
||||
Check an invoice:<br /><code
|
||||
>GET /v1/invoice/*payment_hash*</code
|
||||
>GET /api/v1/invoice/*payment_hash*</code
|
||||
><br />Header
|
||||
<code
|
||||
>{"Grpc-Metadata-macaroon": "<i>{{ wallet.inkey }}</i
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class LndWallet(Wallet):
|
|||
r = post(
|
||||
url=f"{self.endpoint}/v1/invoices",
|
||||
headers=self.auth_admin,
|
||||
json={"value": "100", "memo": memo, "private": True}, # , "private": True},
|
||||
json={"value": "100", "memo": memo, "private": True},
|
||||
)
|
||||
|
||||
if r.ok:
|
||||
|
|
|
|||
|
|
@ -13,17 +13,15 @@ class LNPayWallet(Wallet):
|
|||
self.auth_read = read_key
|
||||
self.auth_api = {"X-Api-Key": api_key}
|
||||
|
||||
|
||||
def create_invoice(self, amount: int, memo: str = "") -> InvoiceResponse:
|
||||
payment_hash, payment_request = None, None
|
||||
print(f"{self.endpoint}/user/wallet/{self.auth_invoice}/invoice")
|
||||
|
||||
r = post(
|
||||
url=f"{self.endpoint}/user/wallet/{self.auth_invoice}/invoice",
|
||||
headers=self.auth_api,
|
||||
json={"num_satoshis": f"{amount}", "memo": memo},
|
||||
)
|
||||
print(r.json())
|
||||
|
||||
if r.ok:
|
||||
data = r.json()
|
||||
payment_hash, payment_request = data["id"], data["payment_request"]
|
||||
|
|
@ -34,7 +32,8 @@ class LNPayWallet(Wallet):
|
|||
r = post(
|
||||
url=f"{self.endpoint}/user/wallet/{self.auth_admin}/withdraw",
|
||||
headers=self.auth_api,
|
||||
json={"payment_request": bolt11})
|
||||
json={"payment_request": bolt11},
|
||||
)
|
||||
|
||||
return PaymentResponse(r, not r.ok)
|
||||
|
||||
|
|
@ -45,8 +44,8 @@ class LNPayWallet(Wallet):
|
|||
return TxStatus(r, None)
|
||||
|
||||
statuses = {0: None, 1: True, -1: False}
|
||||
return TxStatus(r, statuses[r.json()["settled"]])
|
||||
|
||||
return TxStatus(r, statuses[r.json()["settled"]])
|
||||
|
||||
def get_payment_status(self, payment_hash: str) -> TxStatus:
|
||||
r = get(url=f"{self.endpoint}/user/lntx/{payment_hash}", headers=self.auth_api)
|
||||
|
|
@ -55,4 +54,5 @@ class LNPayWallet(Wallet):
|
|||
return TxStatus(r, None)
|
||||
|
||||
statuses = {0: None, 1: True, -1: False}
|
||||
|
||||
return TxStatus(r, statuses[r.json()["settled"]])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue