mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 18:44:20 +01:00
poetry commands, docker, click
This commit is contained in:
53
mint/app.py
53
mint/app.py
@@ -3,13 +3,15 @@ import logging
|
||||
import sys
|
||||
from typing import Union
|
||||
|
||||
import click
|
||||
import uvicorn
|
||||
from ecc.curve import Point, secp256k1
|
||||
from fastapi import FastAPI
|
||||
from loguru import logger
|
||||
|
||||
import core.settings as settings
|
||||
from core.base import MintPayloads, SplitPayload
|
||||
from core.settings import MINT_PRIVATE_KEY
|
||||
from core.settings import MINT_PRIVATE_KEY, MINT_SERVER_HOST, MINT_SERVER_PORT
|
||||
from lightning import WALLET
|
||||
from mint.ledger import Ledger
|
||||
from mint.migrations import m001_initial
|
||||
@@ -148,5 +150,50 @@ async def split(payload: SplitPayload):
|
||||
return {"error": str(exc)}
|
||||
|
||||
|
||||
# if __name__ == "__main__":
|
||||
# uvicorn.run(app, host="127.0.0.1", port=5049)
|
||||
@click.command(
|
||||
context_settings=dict(
|
||||
ignore_unknown_options=True,
|
||||
allow_extra_args=True,
|
||||
)
|
||||
)
|
||||
@click.option("--port", default=MINT_SERVER_PORT, help="Port to listen on")
|
||||
@click.option("--host", default=MINT_SERVER_HOST, help="Host to run mint on")
|
||||
@click.option("--ssl-keyfile", default=None, help="Path to SSL keyfile")
|
||||
@click.option("--ssl-certfile", default=None, help="Path to SSL certificate")
|
||||
@click.pass_context
|
||||
def main(
|
||||
ctx,
|
||||
port: int = MINT_SERVER_PORT,
|
||||
host: str = MINT_SERVER_HOST,
|
||||
ssl_keyfile: str = None,
|
||||
ssl_certfile: str = None,
|
||||
):
|
||||
"""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:
|
||||
item = a.split("=")
|
||||
if len(item) > 1: # argument like --key=value
|
||||
print(a, item)
|
||||
d[item[0].strip("--").replace("-", "_")] = (
|
||||
int(item[1]) # need to convert to int if it's a number
|
||||
if item[1].isdigit()
|
||||
else item[1]
|
||||
)
|
||||
else:
|
||||
d[a.strip("--")] = True # argument like --key
|
||||
|
||||
config = uvicorn.Config(
|
||||
"mint.app:app",
|
||||
port=port,
|
||||
host=host,
|
||||
ssl_keyfile=ssl_keyfile,
|
||||
ssl_certfile=ssl_certfile,
|
||||
**d,
|
||||
)
|
||||
server = uvicorn.Server(config)
|
||||
server.run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user