mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 10:34:20 +01:00
* init flake8 * exclude nostr client, and add ds_store to gitignore * fix flake8 F811 issue, redefinition of unused variables * add flake8 to workflow * F401 unused imports * F541 f-string is missing placeholders * E501 line too long > 150 characters * E722 no bare except * E402 module level import not at top of file * F405 no star imports * E712 comparison to False should be 'if cond is False:' * F841 local variable is assigned to but never used * E266 too many leading '#' for block comment * E265, E261 * E713 test for membership should be 'not in' * E711, E741 E741 ambiguous variable name 'l' E711 comparison to None should be 'if cond is None:' * flake config * isort * refactor makefile flake8 usage * reflaking the rebase * black * fix tests? * black * fix line lenght it test_cli * sort out makefile * fix strings * reintroduce black-check * reflake and mypy * isort * Update cashu/wallet/wallet.py Co-authored-by: Angus Pearson <angus@toaster.cc> * Update cashu/mint/ledger.py Co-authored-by: Angus Pearson <angus@toaster.cc> --------- Co-authored-by: Angus Pearson <angus@toaster.cc>
64 lines
2.0 KiB
Python
64 lines
2.0 KiB
Python
# startup routine of the standalone app. These are the steps that need
|
|
# to be taken by external apps importing the cashu mint.
|
|
|
|
import asyncio
|
|
import importlib
|
|
|
|
from loguru import logger
|
|
|
|
from ..core.db import Database
|
|
from ..core.migrations import migrate_databases
|
|
from ..core.settings import settings
|
|
from ..mint import migrations
|
|
from ..mint.ledger import Ledger
|
|
|
|
logger.debug("Enviroment Settings:")
|
|
for key, value in settings.dict().items():
|
|
logger.debug(f"{key}: {value}")
|
|
|
|
wallets_module = importlib.import_module("cashu.lightning")
|
|
lightning_backend = getattr(wallets_module, settings.mint_lightning_backend)()
|
|
|
|
assert settings.mint_private_key is not None, "No mint private key set."
|
|
|
|
ledger = Ledger(
|
|
db=Database("mint", settings.mint_database),
|
|
seed=settings.mint_private_key,
|
|
derivation_path=settings.mint_derivation_path,
|
|
lightning=lightning_backend,
|
|
)
|
|
|
|
|
|
async def rotate_keys(n_seconds=10):
|
|
"""Rotate keyset epoch every n_seconds.
|
|
Note: This is just a helper function for testing purposes.
|
|
"""
|
|
i = 0
|
|
while True:
|
|
i += 1
|
|
logger.info("Rotating keys.")
|
|
ledger.derivation_path = f"0/0/0/{i}"
|
|
await ledger.init_keysets()
|
|
logger.info(f"Current keyset: {ledger.keyset.id}")
|
|
await asyncio.sleep(n_seconds)
|
|
|
|
|
|
async def start_mint_init():
|
|
await migrate_databases(ledger.db, migrations)
|
|
await ledger.load_used_proofs()
|
|
await ledger.init_keysets()
|
|
|
|
if settings.lightning:
|
|
logger.info(f"Using backend: {settings.mint_lightning_backend}")
|
|
error_message, balance = await ledger.lightning.status()
|
|
if error_message:
|
|
logger.warning(
|
|
f"The backend for {ledger.lightning.__class__.__name__} isn't working properly: '{error_message}'",
|
|
RuntimeWarning,
|
|
)
|
|
logger.info(f"Lightning balance: {balance} msat")
|
|
|
|
logger.info(f"Data dir: {settings.cashu_dir}")
|
|
logger.info("Mint started.")
|
|
# asyncio.create_task(rotate_keys())
|