From 872169478518f350a7d712356825d70f7defc6e3 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Wed, 12 Oct 2022 20:52:35 +0200 Subject: [PATCH] can import, migration dont work yet --- cashu/mint/__init__.py | 1 + cashu/mint/main.py | 3 ++- cashu/mint/router.py | 5 +++-- cashu/mint/startup.py | 18 ++++++++++++------ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/cashu/mint/__init__.py b/cashu/mint/__init__.py index e69de29..8b13789 100644 --- a/cashu/mint/__init__.py +++ b/cashu/mint/__init__.py @@ -0,0 +1 @@ + diff --git a/cashu/mint/main.py b/cashu/mint/main.py index 50c4a6a..5cce3a1 100644 --- a/cashu/mint/main.py +++ b/cashu/mint/main.py @@ -22,7 +22,8 @@ def main( ssl_keyfile: str = None, ssl_certfile: str = None, ): - """Launched with `poetry run mint` at root level""" + """This routine starts the uvicorn server if the Cashu mint is + launched with `poetry run mint` at root level""" # this beautiful beast parses all command line arguments and passes them to the uvicorn server d = dict() for a in ctx.args: diff --git a/cashu/mint/router.py b/cashu/mint/router.py index 2dfe345..ced5c74 100644 --- a/cashu/mint/router.py +++ b/cashu/mint/router.py @@ -16,7 +16,8 @@ from cashu.core.base import ( SplitRequest, ) from cashu.core.errors import CashuError -from cashu.mint import ledger + +from cashu.mint.startup import ledger router: APIRouter = APIRouter() @@ -24,7 +25,7 @@ router: APIRouter = APIRouter() @router.get("/keys") async def keys() -> dict[int, str]: """Get the public keys of the mint""" - return await ledger.get_keyset() + return ledger.get_keyset() @router.get("/keysets") diff --git a/cashu/mint/startup.py b/cashu/mint/startup.py index 852c521..8321417 100644 --- a/cashu/mint/startup.py +++ b/cashu/mint/startup.py @@ -1,3 +1,6 @@ +# startup routine of the standalone app. These are the steps that need +# to be taken by external apps importing the cashu mint. + import asyncio from loguru import logger @@ -7,17 +10,20 @@ from cashu.core.settings import CASHU_DIR, LIGHTNING from cashu.lightning import WALLET from cashu.mint import migrations -from cashu.core.settings import MINT_PRIVATE_KEY from cashu.mint.ledger import Ledger +from cashu.core.settings import MINT_PRIVATE_KEY from cashu.core.db import Database +ledger = Ledger( + db=Database("mint", "data/mint"), + seed=MINT_PRIVATE_KEY, + # seed="asd", + derivation_path="0/0/0/0", +) + async def start_mint_init(): - ledger = Ledger( - db=Database("mint", "data/mint"), - seed=MINT_PRIVATE_KEY, - derivation_path="0/0/0/0", - ) + await migrate_databases(ledger.db, migrations) await ledger.load_used_proofs() await ledger.init_keysets()