ee5b55fab6
* Feature/ephemera compile (#3437) * Include ephemera node code in repo * Upgrade deps * Bump minor version of cosmwasm-std * Include ephemera in nym-api dep and downgrade rusqlite * Fix clippy and ephemera docs code * More clippy on ephemera --------- Co-authored-by: Andrus Salumets <andrus@nymtech.net> * Start ephemera components in nym-api (#3475) * Start ephemera components in nym-api * Pass nyxd client and use common metric structures * Swap url endpoint with contract for sending rewarding messages * Fix build after rebase * Perform ephemera rewards computation before normal nym-api ones * Remove contract mock from ephemera * Take raw rewards from network monitor * Remove ephemera old reward version * Use nym shutdown procedure in ephemera * Temporary fix for some warnings * Umock contract membership of ephemera (#3574) * Pass nyxd client to members provider * Basic ephemera contract * Add register peer tx * Add query all peers * Nyxd ephemera client * Add registration of ephemera peer * Replace epoch http api with actual contract * Merge ephemera config into nym-api config * Load cluster from contract * Guard nym-outfox out of cosmwasm builds (#3650) * Feature/fixes while testing (#3668) * Commit local peer before querying contract * Default to anyonline * Remove string from template * Fix avg computing * Use updated qa env * Fix clippy * Add unit tests for ephemera contract * Upload ephemera contract in CI * Add group check for peer signup * Peer registration unit test * Start ephemera only on monitoring * Remove old MixnodeToReward struct * Move all ephemera config to its file * Skip with serde ephemera config * Fix default value in args * Feature/add ephemera flag (#3727) * Replace unwrap with error handling * Add ephemera enable flag * Fix template * Add json schema to ephemera contract (#3735) * Update lock files * Update changelog --------- Co-authored-by: Andrus Salumets <andrus@nymtech.net>
89 lines
2.9 KiB
Rust
89 lines
2.9 KiB
Rust
use actix_web::{dev::Server, http::KeepAlive, web::Data, App, HttpServer};
|
|
use log::info;
|
|
use utoipa::OpenApi;
|
|
use utoipa_swagger_ui::SwaggerUi;
|
|
|
|
use crate::api::CommandExecutor;
|
|
use crate::core::builder::NodeInfo;
|
|
|
|
pub(crate) mod client;
|
|
pub(crate) mod query;
|
|
pub(crate) mod submit;
|
|
|
|
/// Starts the HTTP server.
|
|
pub(crate) fn init(node_info: &NodeInfo, api: CommandExecutor) -> anyhow::Result<Server> {
|
|
print_startup_messages(node_info);
|
|
|
|
let server = HttpServer::new(move || {
|
|
App::new()
|
|
.app_data(Data::new(api.clone()))
|
|
.service(query::health)
|
|
.service(query::block_by_hash)
|
|
.service(query::block_certificates)
|
|
.service(query::block_by_height)
|
|
.service(query::block_broadcast_group)
|
|
.service(query::last_block)
|
|
.service(query::node_config)
|
|
.service(query::query_dht)
|
|
.service(query::broadcast_info)
|
|
.service(submit::submit_message)
|
|
.service(submit::store_in_dht)
|
|
.service(submit::verify_message_in_block)
|
|
.service(swagger_ui())
|
|
})
|
|
.keep_alive(KeepAlive::Os)
|
|
.bind((node_info.ip.as_str(), node_info.initial_config.http.port))?
|
|
.run();
|
|
Ok(server)
|
|
}
|
|
|
|
/// Builds the Swagger UI.
|
|
///
|
|
/// Note that all routes you want Swagger docs for must be in the `paths` annotation.
|
|
fn swagger_ui() -> SwaggerUi {
|
|
use crate::api::types;
|
|
#[derive(OpenApi)]
|
|
#[openapi(
|
|
paths(
|
|
query::health,
|
|
query::block_by_hash,
|
|
query::block_certificates,
|
|
query::block_by_height,
|
|
query::last_block,
|
|
query::block_broadcast_group,
|
|
query::node_config,
|
|
query::query_dht,
|
|
query::broadcast_info,
|
|
submit::submit_message,
|
|
submit::store_in_dht,
|
|
submit::verify_message_in_block
|
|
),
|
|
components(schemas(
|
|
types::ApiBlock,
|
|
types::ApiEphemeraMessage,
|
|
types::ApiCertificate,
|
|
types::ApiSignature,
|
|
types::ApiPublicKey,
|
|
types::ApiHealth,
|
|
types::HealthStatus,
|
|
types::ApiEphemeraConfig,
|
|
types::ApiDhtStoreRequest,
|
|
types::ApiDhtQueryRequest,
|
|
types::ApiDhtQueryResponse,
|
|
types::ApiBroadcastInfo,
|
|
types::ApiVerifyMessageInBlock,
|
|
))
|
|
)]
|
|
struct ApiDoc;
|
|
SwaggerUi::new("/swagger-ui/{_:.*}").url("/api-doc/openapi.json", ApiDoc::openapi())
|
|
}
|
|
|
|
/// Prints messages saying which ports HTTP is running on, and some helpful pointers
|
|
/// `OpenAPI` and `Swagger UI` endpoints.
|
|
fn print_startup_messages(info: &NodeInfo) {
|
|
let http_root = info.api_address_http();
|
|
info!("Server running on {}", http_root);
|
|
info!("Swagger UI: {}/swagger-ui/", http_root);
|
|
info!("OpenAPI spec is at: {}/api-doc/openapi.json", http_root);
|
|
}
|