diff --git a/nyx-chain-watcher/src/chain_scraper/mod.rs b/nyx-chain-watcher/src/chain_scraper/mod.rs index 2835a8d105..93f768a236 100644 --- a/nyx-chain-watcher/src/chain_scraper/mod.rs +++ b/nyx-chain-watcher/src/chain_scraper/mod.rs @@ -47,10 +47,6 @@ pub(crate) async fn run_chain_scraper( fs::remove_file(config.chain_scraper_database_path())?; } - if config.payment_watcher_config.is_none() { - anyhow::bail!("No payment watcher config found, not running chain scraper"); - } - let scraper = NyxdScraper::builder(nyxd_scraper::Config { websocket_url, rpc_url, diff --git a/nyx-chain-watcher/src/http/api/watcher.rs b/nyx-chain-watcher/src/http/api/watcher.rs index 07c2d9c422..68e6f4f91c 100644 --- a/nyx-chain-watcher/src/http/api/watcher.rs +++ b/nyx-chain-watcher/src/http/api/watcher.rs @@ -1,8 +1,9 @@ use crate::config::Config; -use crate::http::error::Error; +use crate::env; use crate::http::error::HttpResult; use crate::http::state::AppState; use axum::{Json, Router}; +use std::env::var; pub(crate) fn routes() -> Router { Router::new().route("/addresses", axum::routing::get(get_addresses)) @@ -19,26 +20,29 @@ pub(crate) fn routes() -> Router { /// Fetch the addresses being watched by the chain watcher async fn get_addresses() -> HttpResult>> { - let config = - Config::read_from_toml_file_in_default_location().map_err(|_| Error::internal())?; - - let addresses = config - .payment_watcher_config - .as_ref() - .and_then(|config| { - config.watchers.iter().find_map(|watcher| { - watcher - .watch_for_transfer_recipient_accounts - .as_ref() - .map(|accounts| { - accounts - .iter() - .map(|account| account.to_string()) - .collect::>() - }) + let addresses = match Config::read_from_toml_file_in_default_location() { + Ok(config) => config + .payment_watcher_config + .as_ref() + .and_then(|config| { + config.watchers.iter().find_map(|watcher| { + watcher + .watch_for_transfer_recipient_accounts + .as_ref() + .map(|accounts| { + accounts + .iter() + .map(|account| account.to_string()) + .collect::>() + }) + }) }) - }) - .unwrap_or_default(); + .unwrap_or_default(), + // If the config file doesn't exist, fall back to env variable + Err(_) => var(env::vars::NYX_CHAIN_WATCHER_WATCH_ACCOUNTS) + .map(|accounts| accounts.split(',').map(String::from).collect()) + .unwrap_or_default(), + }; Ok(Json(addresses)) }