Skip to content

Commit

Permalink
api: fetch addresses from config.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwnfoo committed Dec 17, 2024
1 parent 2376183 commit 6f4f7c0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 92 deletions.
4 changes: 3 additions & 1 deletion nyx-chain-watcher/src/http/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use utoipa_swagger_ui::SwaggerUi;
use crate::http::{api_docs, server::HttpServer, state::AppState};

pub(crate) mod price;
pub(crate) mod watcher;

pub(crate) struct RouterBuilder {
unfinished_router: Router<AppState>,
Expand All @@ -24,7 +25,8 @@ impl RouterBuilder {
"/",
axum::routing::get(|| async { Redirect::permanent("/swagger") }),
)
.nest("/v1", Router::new().nest("/price", price::routes()));
.nest("/v1", Router::new().nest("/price", price::routes()))
.nest("/v1", Router::new().nest("/watcher", watcher::routes()));

Self {
unfinished_router: router,
Expand Down
91 changes: 0 additions & 91 deletions nyx-chain-watcher/src/http/api/server.rs

This file was deleted.

44 changes: 44 additions & 0 deletions nyx-chain-watcher/src/http/api/watcher.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use crate::config::Config;
use crate::http::error::Error;
use crate::http::error::HttpResult;
use crate::http::state::AppState;
use axum::{Json, Router};

pub(crate) fn routes() -> Router<AppState> {
Router::new().route("/addresses", axum::routing::get(get_addresses))
}

#[utoipa::path(
tag = "Watcher Configuration",
get,
path = "/v1/watcher/addresses",
responses(
(status = 200, body = Vec<String>)
)
)]

/// 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<_>>()
})
})
})
.unwrap_or_default();

Ok(Json(addresses))
}

0 comments on commit 6f4f7c0

Please sign in to comment.