2023-01-26 10:43:12 +01:00
|
|
|
# Python script to create a fake admin user for sqlite3,
|
|
|
|
# for regtest setup as LNbits funding source
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sqlite3
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
from uuid import uuid4
|
|
|
|
|
|
|
|
import shortuuid
|
|
|
|
|
|
|
|
adminkey = "d08a3313322a4514af75d488bcc27eee"
|
|
|
|
sqfolder = "./data"
|
|
|
|
|
|
|
|
if not sqfolder or not os.path.isdir(sqfolder):
|
|
|
|
print("missing LNBITS_DATA_FOLDER")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
file = os.path.join(sqfolder, "database.sqlite3")
|
|
|
|
conn = sqlite3.connect(file)
|
|
|
|
cursor = conn.cursor()
|
|
|
|
|
|
|
|
old_account = cursor.execute(
|
2024-10-01 11:36:22 +02:00
|
|
|
"SELECT * FROM accounts WHERE id = :id", {"id": adminkey}
|
2023-01-26 10:43:12 +01:00
|
|
|
).fetchone()
|
|
|
|
if old_account:
|
|
|
|
print("fake admin does already exist")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
2024-10-01 11:36:22 +02:00
|
|
|
cursor.execute("INSERT INTO accounts (id) VALUES (:adminkey)", {"adminkey": adminkey})
|
2023-01-26 10:43:12 +01:00
|
|
|
|
|
|
|
wallet_id = uuid4().hex
|
|
|
|
cursor.execute(
|
|
|
|
"""
|
|
|
|
INSERT INTO wallets (id, name, "user", adminkey, inkey)
|
2024-10-01 11:36:22 +02:00
|
|
|
VALUES (:wallet_id, :name, :user, :adminkey, :inkey)
|
2023-01-26 10:43:12 +01:00
|
|
|
""",
|
2024-10-01 11:36:22 +02:00
|
|
|
{
|
|
|
|
"wallet_id": wallet_id,
|
|
|
|
"name": "TEST WALLET",
|
|
|
|
"user": adminkey,
|
|
|
|
"adminkey": adminkey,
|
|
|
|
"inkey": uuid4().hex, # invoice key is not important
|
|
|
|
},
|
2023-01-26 10:43:12 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
expiration_date = time.time() + 420
|
|
|
|
|
|
|
|
# 1 btc in sats
|
|
|
|
amount = 100_000_000
|
2024-10-01 11:36:22 +02:00
|
|
|
payment_hash = shortuuid.uuid()
|
|
|
|
internal_id = f"internal_{payment_hash}"
|
2023-01-26 10:43:12 +01:00
|
|
|
|
|
|
|
cursor.execute(
|
|
|
|
"""
|
|
|
|
INSERT INTO apipayments
|
2024-10-29 09:58:22 +01:00
|
|
|
(wallet_id, checking_id, payment_hash, amount, status, memo, fee, expiry)
|
2024-10-01 11:36:22 +02:00
|
|
|
VALUES
|
|
|
|
(:wallet_id, :checking_id, :payment_hash, :amount,
|
2024-10-29 09:58:22 +01:00
|
|
|
:status, :memo, :fee, :expiry)
|
2023-01-26 10:43:12 +01:00
|
|
|
""",
|
2024-10-01 11:36:22 +02:00
|
|
|
{
|
|
|
|
"wallet_id": wallet_id,
|
|
|
|
"checking_id": internal_id,
|
|
|
|
"payment_hash": payment_hash,
|
|
|
|
"amount": amount * 1000,
|
|
|
|
"status": "success",
|
|
|
|
"memo": "fake admin",
|
|
|
|
"fee": 0,
|
|
|
|
"expiry": expiration_date,
|
|
|
|
"pending": False,
|
|
|
|
},
|
2023-01-26 10:43:12 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
print(f"created test admin: {adminkey} with {amount} sats")
|
|
|
|
|
|
|
|
conn.commit()
|
|
|
|
cursor.close()
|