ensure wallet loaded - wip
This commit is contained in:
@@ -28,6 +28,28 @@ if not API_TOKEN:
|
||||
print(f"[web-wallet] API token: {API_TOKEN}")
|
||||
|
||||
|
||||
def create_base_rpc_client() -> AuthServiceProxy:
|
||||
url = f"http://{RIN_RPC_USER}:{RIN_RPC_PASSWORD}@{RIN_RPC_HOST}:{RIN_RPC_PORT}"
|
||||
return AuthServiceProxy(url, timeout=15)
|
||||
|
||||
|
||||
def ensure_wallet_loaded():
|
||||
"""Ensure the wallet is loaded at startup."""
|
||||
try:
|
||||
base_rpc = create_base_rpc_client()
|
||||
base_rpc.loadwallet(RIN_WALLET_NAME)
|
||||
print(f"[web-wallet] Loaded wallet: {RIN_WALLET_NAME}")
|
||||
except Exception as exc:
|
||||
print(f"[web-wallet] Warning: Could not load wallet {RIN_WALLET_NAME}: {exc}")
|
||||
# Try to create if loading failed
|
||||
try:
|
||||
base_rpc = create_base_rpc_client()
|
||||
base_rpc.createwallet(RIN_WALLET_NAME, False, True, "", False, True, True)
|
||||
print(f"[web-wallet] Created and loaded wallet: {RIN_WALLET_NAME}")
|
||||
except Exception as create_exc:
|
||||
print(f"[web-wallet] Warning: Could not create wallet {RIN_WALLET_NAME}: {create_exc}")
|
||||
|
||||
|
||||
def create_rpc_client() -> AuthServiceProxy:
|
||||
url = f"http://{RIN_RPC_USER}:{RIN_RPC_PASSWORD}@{RIN_RPC_HOST}:{RIN_RPC_PORT}/wallet/{RIN_WALLET_NAME}"
|
||||
return AuthServiceProxy(url, timeout=15)
|
||||
@@ -211,10 +233,10 @@ def static_proxy(path):
|
||||
|
||||
|
||||
def main():
|
||||
ensure_wallet_loaded()
|
||||
port = int(os.environ.get("RIN_WEB_WALLET_PORT", "8787"))
|
||||
app.run(host="127.0.0.1", port=port, debug=False)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ set -euo pipefail
|
||||
SCRIPT_DIR=$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
CONTAINER="rincoin-node2"
|
||||
|
||||
if ! sudo docker ps --format '{{.Names}}' | grep -q "^${CONTAINER}$"; then
|
||||
echo "Error: ${CONTAINER} container is not running. Start it with 'sudo docker start ${CONTAINER}'."
|
||||
if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER}$"; then
|
||||
echo "Error: ${CONTAINER} container is not running. Start it with 'docker start ${CONTAINER}'."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -43,4 +43,3 @@ export PYTHONPATH="${SCRIPT_DIR}"
|
||||
flask run --host 127.0.0.1 --port 8787
|
||||
|
||||
# Note: To clean up the virtual environment, run: rm -rf "${SCRIPT_DIR}/venv"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user