mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-27 20:36:16 +02:00
Broke, started added private/public key
This commit is contained in:
@@ -5,13 +5,20 @@ from lnbits.helpers import urlsafe_short_hash
|
|||||||
from . import db
|
from . import db
|
||||||
from .models import Cashu, Pegs
|
from .models import Cashu, Pegs
|
||||||
|
|
||||||
|
from embit import script
|
||||||
|
from embit import ec
|
||||||
|
from embit.networks import NETWORKS
|
||||||
|
from binascii import unhexlify, hexlify
|
||||||
|
|
||||||
async def create_cashu(wallet_id: str, data: Cashu) -> Cashu:
|
async def create_cashu(wallet_id: str, data: Cashu) -> Cashu:
|
||||||
cashu_id = urlsafe_short_hash()
|
cashu_id = urlsafe_short_hash()
|
||||||
|
prv = ec.PrivateKey.from_wif(urlsafe_short_hash())
|
||||||
|
pub = prv.get_public_key()
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO cashu.cashu (id, wallet, name, tickershort, fraction, maxsats, coins)
|
INSERT INTO cashu.cashu (id, wallet, name, tickershort, fraction, maxsats, coins, prvkey, pubkey)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
cashu_id,
|
cashu_id,
|
||||||
@@ -20,7 +27,9 @@ async def create_cashu(wallet_id: str, data: Cashu) -> Cashu:
|
|||||||
data.tickershort,
|
data.tickershort,
|
||||||
data.fraction,
|
data.fraction,
|
||||||
data.maxsats,
|
data.maxsats,
|
||||||
data.coins
|
data.coins,
|
||||||
|
prv,
|
||||||
|
pub
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,6 +38,17 @@ async def create_cashu(wallet_id: str, data: Cashu) -> Cashu:
|
|||||||
return cashu
|
return cashu
|
||||||
|
|
||||||
|
|
||||||
|
async def update_cashu_keys(cashu_id, wif: str = None) -> Optional[Cashu]:
|
||||||
|
if not wif:
|
||||||
|
prv = ec.PrivateKey.from_wif(urlsafe_short_hash())
|
||||||
|
else:
|
||||||
|
prv = ec.PrivateKey.from_wif(wif)
|
||||||
|
pub = prv.get_public_key()
|
||||||
|
await db.execute("UPDATE cashu.cashu SET prv = ?, pub = ? WHERE id = ?", (hexlify(prv.serialize()), hexlify(pub.serialize()), cashu_id))
|
||||||
|
row = await db.fetchone("SELECT * FROM cashu.cashu WHERE id = ?", (cashu_id,))
|
||||||
|
return Cashu(**row) if row else None
|
||||||
|
|
||||||
|
|
||||||
async def get_cashu(cashu_id: str) -> Optional[Cashu]:
|
async def get_cashu(cashu_id: str) -> Optional[Cashu]:
|
||||||
row = await db.fetchone("SELECT * FROM cashu.cashu WHERE id = ?", (cashu_id,))
|
row = await db.fetchone("SELECT * FROM cashu.cashu WHERE id = ?", (cashu_id,))
|
||||||
return Cashu(**row) if row else None
|
return Cashu(**row) if row else None
|
||||||
|
@@ -11,8 +11,9 @@ async def m001_initial(db):
|
|||||||
tickershort TEXT NOT NULL,
|
tickershort TEXT NOT NULL,
|
||||||
fraction BOOL,
|
fraction BOOL,
|
||||||
maxsats INT,
|
maxsats INT,
|
||||||
coins INT
|
coins INT,
|
||||||
|
prvkey TEXT NOT NULL,
|
||||||
|
pubkey TEXT NOT NULL
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
@@ -13,7 +13,8 @@ class Cashu(BaseModel):
|
|||||||
fraction: bool = Query(None)
|
fraction: bool = Query(None)
|
||||||
maxsats: int = Query(0)
|
maxsats: int = Query(0)
|
||||||
coins: int = Query(0)
|
coins: int = Query(0)
|
||||||
|
prvkey: str = Query(None)
|
||||||
|
pubkey: str = Query(None)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_row(cls, row: Row) -> "TPoS":
|
def from_row(cls, row: Row) -> "TPoS":
|
||||||
|
@@ -13,7 +13,7 @@ from lnbits.core.views.api import api_payment
|
|||||||
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
|
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
|
||||||
|
|
||||||
from . import cashu_ext
|
from . import cashu_ext
|
||||||
from .crud import create_cashu, delete_cashu, get_cashu, get_cashus
|
from .crud import create_cashu, delete_cashu, get_cashu, get_cashus, update_cashu_keys
|
||||||
from .models import Cashu, Pegs, PayLnurlWData
|
from .models import Cashu, Pegs, PayLnurlWData
|
||||||
|
|
||||||
|
|
||||||
@@ -36,6 +36,16 @@ async def api_cashu_create(
|
|||||||
logger.debug(cashu)
|
logger.debug(cashu)
|
||||||
return cashu.dict()
|
return cashu.dict()
|
||||||
|
|
||||||
|
@cashu_ext.post("/api/v1/cashus/upodatekeys", status_code=HTTPStatus.CREATED)
|
||||||
|
async def api_cashu_update_keys(
|
||||||
|
data: Cashu, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||||
|
):
|
||||||
|
cashu = await get_cashu(data.id)
|
||||||
|
|
||||||
|
cashu = await create_cashu(wallet_id=wallet.wallet.id, data=data)
|
||||||
|
logger.debug(cashu)
|
||||||
|
return cashu.dict()
|
||||||
|
|
||||||
|
|
||||||
@cashu_ext.delete("/api/v1/cashus/{cashu_id}")
|
@cashu_ext.delete("/api/v1/cashus/{cashu_id}")
|
||||||
async def api_cashu_delete(
|
async def api_cashu_delete(
|
||||||
|
Reference in New Issue
Block a user