diff --git a/Cargo.lock b/Cargo.lock index 75476b512..a854c5665 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -832,6 +832,13 @@ version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" +[[package]] +name = "api_types" +version = "0.1.0" +dependencies = [ + "serde", +] + [[package]] name = "arbitrary" version = "1.4.1" @@ -3710,12 +3717,15 @@ dependencies = [ name = "http_api" version = "0.1.0" dependencies = [ + "api_types", "axum", "serde", + "serde_json", "slot_clock", "task_executor", "tokio", "tracing", + "version", ] [[package]] @@ -7233,9 +7243,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.138" +version = "1.0.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" dependencies = [ "itoa", "memchr", diff --git a/Cargo.toml b/Cargo.toml index 78c26dd07..e7b106ee6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ members = [ "anchor", "anchor/client", + "anchor/common/api_types", "anchor/common/bls_lagrange", "anchor/common/qbft", "anchor/common/ssv_network_config", @@ -31,6 +32,7 @@ edition = "2021" # This table has three subsections: first the internal dependencies, then the lighthouse dependencies, then all other. [workspace.dependencies] anchor_validator_store = { path = "anchor/validator_store" } +api_types = { path = "anchor/common/api_types" } bls_lagrange = { path = "anchor/common/bls_lagrange" } client = { path = "anchor/client" } database = { path = "anchor/database" } @@ -111,7 +113,7 @@ rand = "0.8.5" reqwest = "0.12.12" rusqlite = "0.28.0" serde = { version = "1.0.208", features = ["derive"] } -serde_json = "1.0.138" +serde_json = "1.0.140" serde_yaml = "0.9" sha2 = "0.10.8" strum = { version = "0.26.3", features = ["derive"] } diff --git a/anchor/common/api_types/Cargo.toml b/anchor/common/api_types/Cargo.toml new file mode 100644 index 000000000..ac580555b --- /dev/null +++ b/anchor/common/api_types/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "api_types" +version = "0.1.0" +edition = { workspace = true } + +[dependencies] +serde = { workspace = true } diff --git a/anchor/common/api_types/src/lib.rs b/anchor/common/api_types/src/lib.rs new file mode 100644 index 000000000..347591724 --- /dev/null +++ b/anchor/common/api_types/src/lib.rs @@ -0,0 +1,16 @@ +use serde::Serialize; + +#[derive(Serialize)] +pub struct VersionData { + pub version: String, +} +#[derive(Serialize)] +pub struct GenericResponse { + pub data: T, +} + +impl From for GenericResponse { + fn from(data: T) -> Self { + Self { data } + } +} diff --git a/anchor/common/version/src/lib.rs b/anchor/common/version/src/lib.rs index 225e6b7ad..faf5646b6 100644 --- a/anchor/common/version/src/lib.rs +++ b/anchor/common/version/src/lib.rs @@ -45,7 +45,6 @@ pub const COMMIT_PREFIX: &str = git_version!( /// ## Example /// /// `Anchor/v0.1.0-67da032+/x86_64-linux` -#[allow(dead_code)] pub fn version_with_platform() -> String { format!("{}/{}-{}", VERSION, Target::arch(), Target::os()) } diff --git a/anchor/http_api/Cargo.toml b/anchor/http_api/Cargo.toml index 15975bac1..5058835fc 100644 --- a/anchor/http_api/Cargo.toml +++ b/anchor/http_api/Cargo.toml @@ -9,9 +9,12 @@ name = "http_api" path = "src/lib.rs" [dependencies] +api_types = { workspace = true } axum = { workspace = true } serde = { workspace = true } +serde_json = { workspace = true } slot_clock = { workspace = true } task_executor = { workspace = true } tokio = { workspace = true } tracing = { workspace = true } +version = { workspace = true } diff --git a/anchor/http_api/src/router.rs b/anchor/http_api/src/router.rs index a6a5fb5b1..95b410fbc 100644 --- a/anchor/http_api/src/router.rs +++ b/anchor/http_api/src/router.rs @@ -1,14 +1,23 @@ //! The routes for the HTTP API -use axum::{routing::get, Router}; - +use api_types::{GenericResponse, VersionData}; +use axum::{routing::get, Json, Router}; +use version::version_with_platform; /// Creates all the routes for HTTP API pub fn new() -> Router { // Default route - Router::new().route("/", get(root)) + Router::new() + .route("/", get(root)) + .route("/anchor/version", get(get_version)) } // Temporary return value. async fn root() -> &'static str { "Anchor client" } + +async fn get_version() -> Json> { + Json(GenericResponse::from(VersionData { + version: version_with_platform(), + })) +}