Files
nym/nym-api/src/nym_contract_cache/mod.rs
T
Dinko Zdravac a0fea6edb4 Add axum server to nym-api (#4803)
* Migrate nym-api HTTP server from rocket to axum (#4698)

Migrate endpoints to Axum

* Squashed after PR review

Initial WIP
- bootstrap axum server with same data as rocket
- start axum server alongside rocket
- add routes for circulating-supply, contract-cache, network
- write simple bash validation that migrated APIs return 200
- mark rocket parts of code as deprecated
- start more complicated routes: WIP

Init storage always

Add coconut routes

Add api-status routes

Expand tests

WIP

Migrate unstable APIs with query params

Update bash tests

Add node-status routes

Redirect / to /swagger

Update API tests

Implement graceful shutdown

rustfmt

Fix clippy

* Add ecash routes after rebase

* PR feedback
- add CORS layer
- move logger to common crate
- remove global log filters for nym-api and axum

* Serve OpenAPI for all endpoints (#4761)

* Playing around with swagger

* Generate OpenAPI for /status routes

* Phase out static_routes as strings
- also nest routers in a clearer way

* Generate OpenAPI for /network routes

* Generate OpenAPI for /api-status routes

* Generate OpenAPI for "nym nodes" routes

* Fix some network-monitor routes

* Generate OpenAPI for /ecash routes

* Add utoipa feature to /common mods

* Add OpenAPI for unstable routes

* Fix MixNodeDetails field in models

* Introduce axum feature flag (#4775)

* Add Axum bind_address to config

* Introduce axum feature flag

* Add comment to template.rs

* Add Github action to build wtih `axum` feature

* Refactor server start & shutdown (#4777)

* Clippy: don't forget axum feature

* Refactor router so it's safer

* Implement graceful shutdown

* Nicer pattern matching

* Better Result syntax
2024-08-29 15:31:01 +02:00

52 lines
1.7 KiB
Rust

// Copyright 2021-2023 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: GPL-3.0-only
use crate::nym_contract_cache::cache::NymContractCache;
use crate::support::{self, config, nyxd};
use nym_task::TaskManager;
use okapi::openapi3::OpenApi;
use rocket::Route;
use rocket_okapi::openapi_get_routes_spec;
use rocket_okapi::settings::OpenApiSettings;
use self::cache::refresher::NymContractCacheRefresher;
pub(crate) mod cache;
#[cfg(feature = "axum")]
pub(crate) mod handlers;
pub(crate) mod routes;
pub(crate) fn nym_contract_cache_routes(settings: &OpenApiSettings) -> (Vec<Route>, OpenApi) {
openapi_get_routes_spec![
settings: routes::get_mixnodes,
routes::get_mixnodes_detailed,
routes::get_gateways,
routes::get_active_set,
routes::get_active_set_detailed,
routes::get_rewarded_set,
routes::get_rewarded_set_detailed,
routes::get_blacklisted_mixnodes,
routes::get_blacklisted_gateways,
routes::get_interval_reward_params,
routes::get_current_epoch,
]
}
pub(crate) fn start_refresher(
config: &config::NodeStatusAPI,
nym_contract_cache_state: &NymContractCache,
nyxd_client: nyxd::Client,
shutdown: &TaskManager,
) -> tokio::sync::watch::Receiver<support::caching::CacheNotification> {
let nym_contract_cache_refresher = NymContractCacheRefresher::new(
nyxd_client,
config.debug.caching_interval,
nym_contract_cache_state.to_owned(),
);
let nym_contract_cache_listener = nym_contract_cache_refresher.subscribe();
let shutdown_listener = shutdown.subscribe();
tokio::spawn(async move { nym_contract_cache_refresher.run(shutdown_listener).await });
nym_contract_cache_listener
}