mirror of
https://github.com/lnbits/lnbits.git
synced 2025-04-06 19:08:12 +02:00
Less broken refactor
This commit is contained in:
parent
4c7c792390
commit
7d44fa1c2d
@ -23,6 +23,16 @@ from binascii import unhexlify, hexlify, a2b_base64, b2a_base64
|
||||
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####################
|
||||
|
||||
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),
|
||||
)
|
||||
# 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)
|
||||
|
||||
|
||||
@ -69,9 +79,10 @@ async def delete_watch_wallet(wallet_id: str) -> None:
|
||||
|
||||
###############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()
|
||||
await db.execute(
|
||||
"""
|
||||
@ -87,7 +98,7 @@ async def create_charge(*, walletid: str, user: str, title: str, time: str, amou
|
||||
)
|
||||
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)
|
||||
|
||||
|
@ -23,8 +23,8 @@ async def m001_initial(db):
|
||||
title TEXT,
|
||||
wallet TEXT NOT NULL,
|
||||
address TEXT NOT NULL,
|
||||
time_to_pay INTEGER NOT NULL,
|
||||
amount INTEGER NOT NULL,
|
||||
time_to_pay INTEGER,
|
||||
amount INTEGER,
|
||||
balance INTEGER DEFAULT 0,
|
||||
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user