|
@ -160,129 +160,58 @@ def lnurlwallet(): |
|
|
|
|
|
|
|
|
@app.route("/wallet") |
|
|
@app.route("/wallet") |
|
|
def wallet(): |
|
|
def wallet(): |
|
|
|
|
|
|
|
|
theid = request.args.get("usr") |
|
|
theid = request.args.get("usr") |
|
|
thewal = request.args.get("wal") |
|
|
thewal = request.args.get("wal") |
|
|
theamt = request.args.get("amt") |
|
|
|
|
|
thenme = request.args.get("nme") |
|
|
thenme = request.args.get("nme") |
|
|
|
|
|
|
|
|
if not thewal: |
|
|
if not thewal: |
|
|
return render_template("index.html") |
|
|
return render_template("index.html") |
|
|
else: |
|
|
|
|
|
# Checks if the user exists in "accounts" |
|
|
|
|
|
con = db_connect() |
|
|
|
|
|
cur = con.cursor() |
|
|
|
|
|
print(thewal) |
|
|
|
|
|
cur.execute("select * from accounts WHERE userhash = '" + str(theid) + "'") |
|
|
|
|
|
rows = cur.fetchall() |
|
|
|
|
|
|
|
|
|
|
|
if len(rows) > 0: |
|
|
with Database() as db: |
|
|
cur.close() |
|
|
user_exists = len(db.fetchall("SELECT * FROM accounts WHERE userhash = ?", (theid,))) > 0 |
|
|
|
|
|
|
|
|
# Yes, check the user has a wallet |
|
|
# user exists |
|
|
con = db_connect() |
|
|
# ----------- |
|
|
cur = con.cursor() |
|
|
|
|
|
print(thewal) |
|
|
|
|
|
cur.execute("select * from wallets WHERE user = '" + str(theid) + "'") |
|
|
|
|
|
rowss = cur.fetchall() |
|
|
|
|
|
|
|
|
|
|
|
if len(rowss) > 0: |
|
|
if user_exists: |
|
|
cur.close() |
|
|
user_wallets = db.fetchall("SELECT * FROM wallets WHERE user = ?", (theid,)) |
|
|
|
|
|
|
|
|
# Checks if the current wallet exists |
|
|
# user has wallets |
|
|
con = db_connect() |
|
|
# ---------------- |
|
|
cur = con.cursor() |
|
|
|
|
|
print(thewal) |
|
|
|
|
|
cur.execute("select * from wallets WHERE hash = '" + str(thewal) + "'") |
|
|
|
|
|
rowsss = cur.fetchall() |
|
|
|
|
|
|
|
|
|
|
|
if len(rowsss) > 0: |
|
|
if len(user_wallets) > 0: |
|
|
cur.close() |
|
|
wallet = db.fetchall("SELECT * FROM wallets WHERE hash = ?", (thewal,)) |
|
|
walb = rowsss[0][1].split(",")[-1] |
|
|
|
|
|
|
|
|
if len(wallet) > 0: |
|
|
|
|
|
walb = wallet[0][1].split(",")[-1] |
|
|
return render_template( |
|
|
return render_template( |
|
|
"wallet.html", |
|
|
"wallet.html", |
|
|
thearr=rowss, |
|
|
thearr=user_wallets, |
|
|
len=len(rowss), |
|
|
len=len(user_wallets), |
|
|
walnme=rowsss[0][3], |
|
|
walnme=wallet[0][3], |
|
|
user=theid, |
|
|
user=theid, |
|
|
walbal=walb, |
|
|
walbal=walb, |
|
|
theid=theid, |
|
|
theid=theid, |
|
|
thewal=thewal, |
|
|
thewal=thewal, |
|
|
transactions=rowsss[0][2], |
|
|
transactions=wallet[0][2], |
|
|
adminkey=rowsss[0][5], |
|
|
adminkey=wallet[0][5], |
|
|
inkey=rowsss[0][6], |
|
|
inkey=wallet[0][6], |
|
|
) |
|
|
) |
|
|
else: |
|
|
|
|
|
cur.close() |
|
|
|
|
|
|
|
|
|
|
|
con = db_connect() |
|
|
|
|
|
cur = con.cursor() |
|
|
|
|
|
|
|
|
|
|
|
adminkey = encrypt(thewal) |
|
|
|
|
|
inkey = encrypt(adminkey) |
|
|
|
|
|
|
|
|
|
|
|
cur.execute( |
|
|
|
|
|
"INSERT INTO wallets (hash, balance, transactions, name, user, adminkey, inkey) VALUES ('" |
|
|
|
|
|
+ thewal |
|
|
|
|
|
+ "',',0','0','" |
|
|
|
|
|
+ thenme |
|
|
|
|
|
+ "','" |
|
|
|
|
|
+ theid |
|
|
|
|
|
+ "','" |
|
|
|
|
|
+ adminkey |
|
|
|
|
|
+ "','" |
|
|
|
|
|
+ inkey |
|
|
|
|
|
+ "')" |
|
|
|
|
|
) |
|
|
|
|
|
con.commit() |
|
|
|
|
|
cur.close() |
|
|
|
|
|
|
|
|
|
|
|
con = db_connect() |
|
|
|
|
|
cur = con.cursor() |
|
|
|
|
|
print(thewal) |
|
|
|
|
|
cur.execute("select * from wallets WHERE user = '" + str(theid) + "'") |
|
|
|
|
|
rowss = cur.fetchall() |
|
|
|
|
|
cur.close() |
|
|
|
|
|
|
|
|
|
|
|
return render_template( |
|
|
|
|
|
"wallet.html", |
|
|
|
|
|
thearr=rowss, |
|
|
|
|
|
len=len(rowss), |
|
|
|
|
|
walnme=thenme, |
|
|
|
|
|
walbal="0", |
|
|
|
|
|
theid=theid, |
|
|
|
|
|
thewal=thewal, |
|
|
|
|
|
adminkey=adminkey, |
|
|
|
|
|
inkey=inkey, |
|
|
|
|
|
) |
|
|
|
|
|
else: |
|
|
|
|
|
cur.close() |
|
|
|
|
|
|
|
|
|
|
|
con = db_connect() |
|
|
adminkey = encrypt(thewal) |
|
|
cur = con.cursor() |
|
|
|
|
|
|
|
|
|
|
|
adminkey = encrypt(theid) |
|
|
|
|
|
inkey = encrypt(adminkey) |
|
|
inkey = encrypt(adminkey) |
|
|
|
|
|
|
|
|
cur.execute( |
|
|
db.execute( |
|
|
"INSERT INTO wallets (hash, balance, transactions, name, user, adminkey, inkey) VALUES ('" |
|
|
"INSERT INTO wallets (hash, balance, transactions, name, user, adminkey, inkey) " |
|
|
+ thewal |
|
|
"VALUES (?, 0, 0, ?, ?, ?, ?)", |
|
|
+ "',',0','0','" |
|
|
(thewal, thenme, theid, adminkey, inkey), |
|
|
+ thenme |
|
|
|
|
|
+ "','" |
|
|
|
|
|
+ theid |
|
|
|
|
|
+ "','" |
|
|
|
|
|
+ adminkey |
|
|
|
|
|
+ "','" |
|
|
|
|
|
+ inkey |
|
|
|
|
|
+ "')" |
|
|
|
|
|
) |
|
|
) |
|
|
con.commit() |
|
|
rows = db.fetchall("SELECT * FROM wallets WHERE user = ?", (theid,)) |
|
|
cur.close() |
|
|
|
|
|
|
|
|
|
|
|
return render_template( |
|
|
return render_template( |
|
|
"wallet.html", |
|
|
"wallet.html", |
|
|
len=len("1"), |
|
|
thearr=rows, |
|
|
|
|
|
len=len(rows), |
|
|
walnme=thenme, |
|
|
walnme=thenme, |
|
|
walbal="0", |
|
|
walbal="0", |
|
|
theid=theid, |
|
|
theid=theid, |
|
@ -291,44 +220,17 @@ def wallet(): |
|
|
inkey=inkey, |
|
|
inkey=inkey, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
else: |
|
|
# user has no wallets |
|
|
cur.close() |
|
|
# ------------------- |
|
|
con = db_connect() |
|
|
|
|
|
cur = con.cursor() |
|
|
|
|
|
|
|
|
|
|
|
cur.execute("INSERT INTO accounts (userhash) VALUES ('" + theid + "')") |
|
|
|
|
|
con.commit() |
|
|
|
|
|
cur.close() |
|
|
|
|
|
|
|
|
|
|
|
con = db_connect() |
|
|
|
|
|
cur = con.cursor() |
|
|
|
|
|
|
|
|
|
|
|
adminkey = encrypt(theid) |
|
|
adminkey = encrypt(theid) |
|
|
inkey = encrypt(adminkey) |
|
|
inkey = encrypt(adminkey) |
|
|
|
|
|
|
|
|
cur.execute( |
|
|
db.execute( |
|
|
"INSERT INTO wallets (hash, balance, transactions, name, user, adminkey, inkey) VALUES ('" |
|
|
"INSERT INTO wallets (hash, balance, transactions, name, user, adminkey, inkey) " |
|
|
+ thewal |
|
|
"VALUES (?, 0, 0, ?, ?, ?, ?)", |
|
|
+ "',',0','0','" |
|
|
(thewal, thenme, theid, adminkey, inkey), |
|
|
+ thenme |
|
|
|
|
|
+ "','" |
|
|
|
|
|
+ theid |
|
|
|
|
|
+ "','" |
|
|
|
|
|
+ adminkey |
|
|
|
|
|
+ "','" |
|
|
|
|
|
+ inkey |
|
|
|
|
|
+ "')" |
|
|
|
|
|
) |
|
|
) |
|
|
con.commit() |
|
|
|
|
|
cur.close() |
|
|
|
|
|
|
|
|
|
|
|
con = db_connect() |
|
|
|
|
|
cur = con.cursor() |
|
|
|
|
|
print(thewal) |
|
|
|
|
|
cur.execute("select * from wallets WHERE user = '" + str(theid) + "'") |
|
|
|
|
|
rows = cur.fetchall() |
|
|
|
|
|
con.commit() |
|
|
|
|
|
cur.close() |
|
|
|
|
|
|
|
|
|
|
|
return render_template( |
|
|
return render_template( |
|
|
"wallet.html", |
|
|
"wallet.html", |
|
@ -341,6 +243,31 @@ def wallet(): |
|
|
inkey=inkey, |
|
|
inkey=inkey, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
# user does not exist: create an account |
|
|
|
|
|
# -------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
db.execute("INSERT INTO accounts (userhash) VALUES (?)", (theid,)) |
|
|
|
|
|
|
|
|
|
|
|
adminkey = encrypt(theid) |
|
|
|
|
|
inkey = encrypt(adminkey) |
|
|
|
|
|
|
|
|
|
|
|
db.execute( |
|
|
|
|
|
"INSERT INTO wallets (hash, balance, transactions, name, user, adminkey, inkey) " |
|
|
|
|
|
"VALUES (?, 0, 0, ?, ?, ?, ?)", |
|
|
|
|
|
(thewal, thenme, theid, adminkey, inkey), |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return render_template( |
|
|
|
|
|
"wallet.html", |
|
|
|
|
|
len=len("1"), |
|
|
|
|
|
walnme=thenme, |
|
|
|
|
|
walbal="0", |
|
|
|
|
|
theid=theid, |
|
|
|
|
|
thewal=thewal, |
|
|
|
|
|
adminkey=adminkey, |
|
|
|
|
|
inkey=inkey, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# API requests |
|
|
# API requests |
|
|
@app.route("/v1/invoices", methods=["GET", "POST"]) |
|
|
@app.route("/v1/invoices", methods=["GET", "POST"]) |
|
|