Skip to content

Commit

Permalink
rusk: add info HTTP endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Oct 26, 2023
1 parent 7c6423f commit b2a5c00
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions rusk/src/lib/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ use crate::Rusk;

#[derive(Clone)]
pub struct RuskNode(pub node::Node<Kadcast<255>, Backend, Rusk>);

impl RuskNode {
pub fn db(&self) -> Arc<tokio::sync::RwLock<Backend>> {
self.0.database() as Arc<tokio::sync::RwLock<Backend>>
}

pub fn network(&self) -> Arc<tokio::sync::RwLock<Kadcast<255>>> {
self.0.network() as Arc<tokio::sync::RwLock<Kadcast<255>>>
}
}
15 changes: 15 additions & 0 deletions rusk/src/lib/http/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use super::event::{
Event, MessageRequest, MessageResponse, RequestData, ResponseData, Target,
};
use crate::http::RuskNode;
use crate::{VERSION, VERSION_BUILD};

const GQL_VAR_PREFIX: &str = "rusk-gqlvar-";

Expand Down Expand Up @@ -61,6 +62,7 @@ impl RuskNode {
let amount = request.event.data.as_string().trim().parse()?;
self.alive_nodes(amount).await
}
(Target::Host(_), "Chain", "info") => self.get_info().await,
_ => anyhow::bail!("Unsupported"),
}
}
Expand Down Expand Up @@ -110,4 +112,17 @@ impl RuskNode {
let nodes: Vec<_> = nodes.iter().map(|n| n.to_string()).collect();
Ok(serde_json::to_value(nodes)?.into())
}

async fn get_info(&self) -> anyhow::Result<ResponseData> {
let mut info: HashMap<&str, serde_json::Value> = HashMap::new();
info.insert("version", VERSION.as_str().into());
info.insert("version_build", VERSION_BUILD.as_str().into());

let n_conf = self.network().read().await.conf().clone();
info.insert("bootstrapping_nodes", n_conf.bootstrapping_nodes.into());
info.insert("chain_id", n_conf.kadcast_id.into());
info.insert("kadcast_address", n_conf.public_address.into());

Ok(serde_json::to_value(&info)?.into())
}
}

0 comments on commit b2a5c00

Please sign in to comment.