mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-22 15:57:28 +02:00
Less broken refactor
This commit is contained in:
@@ -23,6 +23,16 @@ from binascii import unhexlify, hexlify, a2b_base64, b2a_base64
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
async def get_derive_address(wallet_id: str, num: int):
|
||||||
|
|
||||||
|
wallet = await get_watch_wallet(wallet_id)
|
||||||
|
k = bip32.HDKey.from_base58(str(wallet[2]))
|
||||||
|
child = k.derive([0, num])
|
||||||
|
address = script.p2wpkh(child).address()
|
||||||
|
|
||||||
|
return address
|
||||||
|
|
||||||
|
|
||||||
##########################WALLETS####################
|
##########################WALLETS####################
|
||||||
|
|
||||||
async def create_watch_wallet(*, user: str, masterpub: str, title: str) -> Wallets:
|
async def create_watch_wallet(*, user: str, masterpub: str, title: str) -> Wallets:
|
||||||
@@ -42,7 +52,7 @@ async def create_watch_wallet(*, user: str, masterpub: str, title: str) -> Walle
|
|||||||
(wallet_id, user, masterpub, title, 0, 0),
|
(wallet_id, user, masterpub, title, 0, 0),
|
||||||
)
|
)
|
||||||
# weallet_id = db.cursor.lastrowid
|
# weallet_id = db.cursor.lastrowid
|
||||||
address = await get_fresh_address(wallet_id)
|
address = await create_charge(wallet_id, user)
|
||||||
return await get_watch_wallet(wallet_id)
|
return await get_watch_wallet(wallet_id)
|
||||||
|
|
||||||
|
|
||||||
@@ -69,9 +79,10 @@ async def delete_watch_wallet(wallet_id: str) -> None:
|
|||||||
|
|
||||||
###############CHARGES##########################
|
###############CHARGES##########################
|
||||||
|
|
||||||
async def create_charge(*, walletid: str, user: str, title: str, time: str, amount: int) -> Charges:
|
async def create_charge(*, walletid: str, user: str, title: Optional[str] = None, time: Optional[int] = None, amount: Optional[int] = None) -> Charges:
|
||||||
|
wallet = await get_watch_wallet(walletid)
|
||||||
|
address = await get_derive_address(wallet_id, wallet[4] + 1)
|
||||||
|
|
||||||
address = await get_fresh_address(walletid)
|
|
||||||
charge_id = urlsafe_short_hash()
|
charge_id = urlsafe_short_hash()
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
@@ -87,7 +98,7 @@ async def create_charge(*, walletid: str, user: str, title: str, time: str, amou
|
|||||||
)
|
)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(charge_id, user, title, walletid, address.address, time, amount, 0),
|
(charge_id, user, title, walletid, address, time, amount, 0),
|
||||||
)
|
)
|
||||||
return await get_charge(charge_id)
|
return await get_charge(charge_id)
|
||||||
|
|
||||||
|
@@ -23,8 +23,8 @@ async def m001_initial(db):
|
|||||||
title TEXT,
|
title TEXT,
|
||||||
wallet TEXT NOT NULL,
|
wallet TEXT NOT NULL,
|
||||||
address TEXT NOT NULL,
|
address TEXT NOT NULL,
|
||||||
time_to_pay INTEGER NOT NULL,
|
time_to_pay INTEGER,
|
||||||
amount INTEGER NOT NULL,
|
amount INTEGER,
|
||||||
balance INTEGER DEFAULT 0,
|
balance INTEGER DEFAULT 0,
|
||||||
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
|
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user