nyx-chain-watcher: fallback to env variable when reading config
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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<AppState> {
|
||||
Router::new().route("/addresses", axum::routing::get(get_addresses))
|
||||
@@ -19,26 +20,29 @@ pub(crate) fn routes() -> Router<AppState> {
|
||||
|
||||
/// Fetch the addresses being watched by the chain watcher
|
||||
async fn get_addresses() -> HttpResult<Json<Vec<String>>> {
|
||||
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::<Vec<_>>()
|
||||
})
|
||||
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::<Vec<_>>()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
.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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user