From 8d7a1c4337af570c691c3c16527b724ae57ed80f Mon Sep 17 00:00:00 2001 From: necrashter Date: Sat, 23 Apr 2022 16:07:55 +0300 Subject: GET /config endpoint --- src/handlers.rs | 6 ++++++ src/routes.rs | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/handlers.rs b/src/handlers.rs index d2a834f..44c5299 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -352,6 +352,12 @@ pub async fn authenticate_user( Ok(warp::reply::with_status(res_json, StatusCode::CREATED)) } +/// GET /config +/// Returns the configuration settings of this network in JSON. +pub async fn get_config(db: Db) -> Result { + Ok(reply::with_status(reply::json(&db.config), StatusCode::OK)) +} + /// GET /transaction /// Returns JSON array of transactions pub async fn list_transactions(db: Db) -> Result { diff --git a/src/routes.rs b/src/routes.rs index 9eadbea..651626a 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -19,6 +19,7 @@ pub fn network(db: Db) -> BoxedFilter<(impl Reply,)> { }; root.and( transaction_list(db.clone()) + .or(get_config_route(db.clone())) .or(register_user(db.clone())) .or(auth_transaction_propose(db.clone())) .or(auth_block_propose(db.clone())) @@ -28,6 +29,14 @@ pub fn network(db: Db) -> BoxedFilter<(impl Reply,)> { .boxed() } +/// GET /config warp route +pub fn get_config_route(db: Db) -> impl Filter + Clone { + warp::path!("config") + .and(warp::get()) + .and(custom_filters::with_db(db)) + .and_then(handlers::get_config) +} + /// GET /user warp route pub fn list_users(db: Db) -> impl Filter + Clone { warp::path!("user") -- cgit v1.2.3-70-g09d2