Allow to start wallet API by cashu --daemon (#243)

* Allow to start wallet API by cashu --daemon

* Provide access to wallet name via settings

* Make format

* Use flag is_eager for daemon option

* add setting api_host

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
This commit is contained in:
sihamon
2023-06-08 14:42:37 +02:00
committed by GitHub
parent 5c820f9469
commit 786fbf2856
6 changed files with 37 additions and 13 deletions

View File

@@ -20,6 +20,7 @@ from ...nostr.nostr.client.client import NostrClient
from ...tor.tor import TorProxy
from ...wallet.crud import get_lightning_invoices, get_reserved_proofs, get_unused_locks
from ...wallet.wallet import Wallet as Wallet
from ..api.api_server import start_api_server
from ..cli.cli_helpers import get_mint_wallet, print_mint_balances, verify_mint
from ..helpers import deserialize_token_from_string, init_wallet, receive, send
from ..nostr import receive_nostr, send_nostr
@@ -32,6 +33,13 @@ class NaturalOrderGroup(click.Group):
return self.commands.keys()
def run_api_server(ctx, param, daemon):
if not daemon:
return
start_api_server()
ctx.exit()
@click.group(cls=NaturalOrderGroup)
@click.option(
"--host",
@@ -43,8 +51,17 @@ class NaturalOrderGroup(click.Group):
"--wallet",
"-w",
"walletname",
default="wallet",
help="Wallet name (default: wallet).",
default=settings.wallet_name,
help=f"Wallet name (default: {settings.wallet_name}).",
)
@click.option(
"--daemon",
"-d",
is_flag=True,
is_eager=True,
expose_value=False,
callback=run_api_server,
help="Start server for wallet REST API",
)
@click.pass_context
def cli(ctx: Context, host: str, walletname: str):