Files
nutshell/cashu/mint/startup.py
calle 3333102327 lightning: add fakewallet (#134)
* lightning: add fakewallet

* make format

* fix mypy

* make backend configurable

* weird mypy
2023-03-07 17:49:27 +01:00

51 lines
1.5 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 importlib
from loguru import logger
from cashu.core.db import Database
from cashu.core.migrations import migrate_databases
from cashu.core.settings import (
CASHU_DIR,
LIGHTNING,
MINT_DATABASE,
MINT_LIGHTNING_BACKEND,
MINT_PRIVATE_KEY,
)
from cashu.lightning.fake import FakeWallet # type: ignore
from cashu.lightning.lnbits import LNbitsWallet # type: ignore
from cashu.mint import migrations
from cashu.mint.ledger import Ledger
wallets_module = importlib.import_module("cashu.lightning")
LIGHTNING_BACKEND = getattr(wallets_module, MINT_LIGHTNING_BACKEND)()
ledger = Ledger(
db=Database("mint", MINT_DATABASE),
seed=MINT_PRIVATE_KEY,
derivation_path="0/0/0/0",
lightning=LIGHTNING_BACKEND,
)
async def start_mint_init():
await migrate_databases(ledger.db, migrations)
await ledger.load_used_proofs()
await ledger.init_keysets()
if LIGHTNING:
logger.info(f"Using backend: {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: {CASHU_DIR}")
logger.info("Mint started.")