refactor: improve startup procedure
During startup the API will try to connect to Bitcoin Core and the
Lightning Node. If it can't connect it will check every "n" seconds
(currently 2s) and connect when available. A new SSE event
called "system_startup_info" is introduced. This event contains
all startup status information during the startup procedure.
The old wallet_locked event is obsolete.
Sample:
--------------------------
event: system_startup_info
data: {"bitcoin": "offline", "bitcoin_msg": "", "lightning": "offline", "lightning_msg": "Unable to connect to LND daemon, waiting..."}
--------------------------
event: system_startup_info
data: {"bitcoin": "done", "bitcoin_msg": "", "lightning": "offline", "lightning_msg": "Unable to connect to LND daemon, waiting..."}
--------------------------
event: system_startup_info
data: {"bitcoin": "done", "bitcoin_msg": "", "lightning": "locked", "lightning_msg": "Wallet locked, unlock it to enable full RPC access"}
--------------------------
event: system_startup_info
data: {"bitcoin": "done", "bitcoin_msg": "", "lightning": "done", "lightning_msg": ""}
--------------------------
event: system_startup_info
data: {"bitcoin": "done", "bitcoin_msg": "", "lightning": "bootstraping", "lightning_msg": "RPC not yet available"}
--------------------------
refs #97
2022-06-06 19:29:21 +02:00
|
|
|
from enum import Enum
|
2022-12-01 19:14:01 +01:00
|
|
|
from typing import Optional
|
refactor: improve startup procedure
During startup the API will try to connect to Bitcoin Core and the
Lightning Node. If it can't connect it will check every "n" seconds
(currently 2s) and connect when available. A new SSE event
called "system_startup_info" is introduced. This event contains
all startup status information during the startup procedure.
The old wallet_locked event is obsolete.
Sample:
--------------------------
event: system_startup_info
data: {"bitcoin": "offline", "bitcoin_msg": "", "lightning": "offline", "lightning_msg": "Unable to connect to LND daemon, waiting..."}
--------------------------
event: system_startup_info
data: {"bitcoin": "done", "bitcoin_msg": "", "lightning": "offline", "lightning_msg": "Unable to connect to LND daemon, waiting..."}
--------------------------
event: system_startup_info
data: {"bitcoin": "done", "bitcoin_msg": "", "lightning": "locked", "lightning_msg": "Wallet locked, unlock it to enable full RPC access"}
--------------------------
event: system_startup_info
data: {"bitcoin": "done", "bitcoin_msg": "", "lightning": "done", "lightning_msg": ""}
--------------------------
event: system_startup_info
data: {"bitcoin": "done", "bitcoin_msg": "", "lightning": "bootstraping", "lightning_msg": "RPC not yet available"}
--------------------------
refs #97
2022-06-06 19:29:21 +02:00
|
|
|
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StartupState(str, Enum):
|
|
|
|
|
OFFLINE = "offline"
|
|
|
|
|
BOOTSTRAPPING = "bootstrapping"
|
|
|
|
|
LOCKED = "locked"
|
|
|
|
|
DONE = "done"
|
|
|
|
|
DISABLED = "disabled"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ApiStartupStatus(BaseModel):
|
|
|
|
|
def __init__(
|
|
|
|
|
__pydantic_self__,
|
|
|
|
|
bitcoin: StartupState = StartupState.OFFLINE,
|
|
|
|
|
bitcoin_msg: Optional[str] = "",
|
|
|
|
|
lightning: StartupState = StartupState.OFFLINE,
|
|
|
|
|
lightning_msg: Optional[str] = "",
|
|
|
|
|
) -> "ApiStartupStatus":
|
|
|
|
|
super().__init__(
|
|
|
|
|
bitcoin=bitcoin,
|
|
|
|
|
bitcoin_msg=bitcoin_msg,
|
|
|
|
|
lightning=lightning,
|
|
|
|
|
lightning_msg=lightning_msg,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
bitcoin: StartupState
|
|
|
|
|
bitcoin_msg: Optional[str]
|
|
|
|
|
lightning: StartupState
|
|
|
|
|
lightning_msg: Optional[str]
|
2022-06-10 19:45:55 +02:00
|
|
|
|
|
|
|
|
def is_fully_initialized(self):
|
|
|
|
|
return self.bitcoin == StartupState.DONE and (
|
|
|
|
|
self.lightning == StartupState.DONE
|
|
|
|
|
or self.lightning == StartupState.DISABLED
|
|
|
|
|
)
|