Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ tokio = { version = "1", features = ["process"] }

[build-dependencies]
vergen = { version = "8.3.1", default-features = false, features = ["cargo"] }

serde = "1.0"
serde_json = "1.0"
68 changes: 68 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,75 @@
use std::str::FromStr;

use serde::{Deserialize, Deserializer};

#[derive(Deserialize)]
struct VersionMetadata {
#[serde(rename(deserialize = "packages"))]
#[serde(deserialize_with = "deserialize_data")]
versions: Vec<Data>,
}

#[derive(Deserialize)]
struct Data {
name: String,
version: String,
}

#[derive(PartialEq, Debug)]
enum ExplorerMetadata {
ExplorerVersion,
IrohaCompatibility,
Unknown,
}

impl FromStr for ExplorerMetadata {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"iroha_explorer" => Ok(Self::ExplorerVersion),
"iroha_data_model" => Ok(Self::IrohaCompatibility),
_ => Ok(Self::Unknown),
}
}
}

fn deserialize_data<'de, D>(deserializer: D) -> Result<Vec<Data>, D::Error>
where
D: Deserializer<'de>,
{
let metadata = Vec::<Data>::deserialize(deserializer)?;
Ok(metadata
.into_iter()
.filter(|data| data.name.starts_with("iroha"))
.collect::<Vec<_>>())
}

fn main() {
vergen::EmitBuilder::builder()
.git_sha(true)
.cargo_features()
.emit()
.unwrap();
let output = std::process::Command::new("cargo")
.arg("metadata")
.output()
.unwrap();

let metadata = std::str::from_utf8(&output.stdout).unwrap();
let metadata = serde_json::from_str::<VersionMetadata>(metadata).unwrap();

for Data { version, name } in &metadata.versions {
match name.parse::<ExplorerMetadata>() {
Ok(ExplorerMetadata::ExplorerVersion) => {
println!("cargo:rustc-env=VERGEN_EXPLORER_VERSION={version}")
}
Ok(ExplorerMetadata::IrohaCompatibility) => {
println!("cargo:rustc-env=VERGEN_IROHA_COMPAT=v{version}")
}
Ok(ExplorerMetadata::Unknown) => {
// skip everthing else
}
Err(_) => unreachable!(),
}
}
}
32 changes: 29 additions & 3 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use axum::{
};
use futures_util::Stream;
use futures_util::StreamExt;
use serde::Deserialize;
use utoipa::{IntoParams, OpenApi};
use serde::{Deserialize, Serialize};
use utoipa::{IntoParams, OpenApi, ToSchema};

use crate::schema::{Page, PaginationQueryParams, TelemetryStreamMessage, TransactionStatus};
use crate::telemetry::Telemetry;
Expand Down Expand Up @@ -551,6 +551,29 @@ pub async fn telemetry_peers_info(
Ok(Json(data))
}

#[derive(Serialize, ToSchema)]
pub struct ExplorerInfo {
explorer_version: &'static str,
iroha_compatibility: &'static str,
}

#[utoipa::path(
get,
path = "/info",
tags = ["Explorer information"],
responses(
(status = 200, description = "OK", body = ExplorerInfo)
)
)]
pub async fn explorer_info() -> Json<ExplorerInfo> {
let explorer_version = env!("VERGEN_EXPLORER_VERSION");
let iroha_compatibility = env!("VERGEN_IROHA_COMPAT");
Json(ExplorerInfo {
explorer_version,
iroha_compatibility,
})
}

pub fn router(repo: Repo, telemetry: Telemetry) -> Router {
Router::new()
.route("/domains", get(domains_index))
Expand All @@ -576,6 +599,7 @@ pub fn router(repo: Repo, telemetry: Telemetry) -> Router {
.route("/telemetry/peers", get(telemetry_peers))
.route("/telemetry/peers-info", get(telemetry_peers_info))
.route("/telemetry/live", get(telemetry_live))
.route("/info", get(explorer_info))
.with_state(AppState { repo, telemetry })
}

Expand All @@ -598,6 +622,7 @@ pub fn router(repo: Repo, telemetry: Telemetry) -> Router {
transactions_index,
transactions_show,
instructions_index,
explorer_info,
),
nest((path = "/telemetry", api = TelemetryApi)),
tags(
Expand All @@ -612,6 +637,7 @@ pub struct Api;
telemetry_network,
telemetry_peers,
telemetry_peers_info,
telemetry_live
telemetry_live,
telemetry_network_status_live
))]
struct TelemetryApi;
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ mod tests {
)
.await;
ensure_status(&client, path("/api/v1/telemetry/live"), StatusCode::OK).await;
ensure_status(&client, path("/api/v1/info"), StatusCode::OK).await;

Ok(())
}
Expand Down