lnbits-legend/lnbits/extensions/cashu/__init__.py

49 lines
1.1 KiB
Python
Raw Normal View History

2022-09-16 13:20:42 +01:00
import asyncio
2022-11-07 14:00:05 +01:00
from environs import Env # type: ignore
2022-09-16 13:20:42 +01:00
from fastapi import APIRouter
2022-10-10 12:42:34 +03:00
from fastapi.staticfiles import StaticFiles
2022-09-16 13:20:42 +01:00
from lnbits.db import Database
from lnbits.helpers import template_renderer
from lnbits.tasks import catch_everything_and_restart
2022-09-30 12:25:48 +01:00
db = Database("ext_cashu")
2022-09-16 13:20:42 +01:00
2022-10-12 23:16:39 +02:00
import sys
2022-10-14 01:01:43 +02:00
cashu_static_files = [
{
"path": "/cashu/static",
"app": StaticFiles(directory="lnbits/extensions/cashu/static"),
"name": "cashu_static",
}
]
2022-10-12 23:16:39 +02:00
from cashu.mint.ledger import Ledger
2022-11-07 14:00:05 +01:00
env = Env()
env.read_env()
2022-10-12 23:16:39 +02:00
ledger = Ledger(
db=db,
2022-11-07 14:00:05 +01:00
seed=env.str("CASHU_PRIVATE_KEY", default="SuperSecretPrivateKey"),
derivation_path="0/0/0/0",
2022-10-12 23:16:39 +02:00
)
2022-10-17 11:03:39 +02:00
cashu_ext: APIRouter = APIRouter(prefix="/cashu", tags=["cashu"])
2022-10-10 12:42:34 +03:00
2022-10-07 11:17:02 +03:00
2022-09-16 13:20:42 +01:00
def cashu_renderer():
return template_renderer(["lnbits/extensions/cashu/templates"])
2022-10-07 11:17:02 +03:00
2022-10-21 15:31:24 +02:00
from .tasks import startup_cashu_mint, wait_for_paid_invoices
2022-09-16 13:20:42 +01:00
from .views import * # noqa
from .views_api import * # noqa
2022-10-07 11:17:02 +03:00
2022-09-16 13:20:42 +01:00
def cashu_start():
loop = asyncio.get_event_loop()
2022-10-12 23:16:39 +02:00
loop.create_task(catch_everything_and_restart(startup_cashu_mint))
2022-09-16 13:20:42 +01:00
loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))