Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
Feat: Add extras to index route
Browse files Browse the repository at this point in the history
  • Loading branch information
guscalonico committed Aug 16, 2022
1 parent ce4c242 commit 85e6ad0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use routes::index::index;

use crate::{
database::queries::QueryContext, key_manager, server::routes::sign::sign_route,
state::ValidatorStateAccess,
state::ValidatorStateAccess, context::{BundlerAccess, ValidatorAddressAccess},
};

#[cfg(feature = "test-routes")]
Expand All @@ -34,6 +34,8 @@ where
Context: RuntimeContext
+ routes::sign::Config<KeyManager>
+ ValidatorStateAccess
+ BundlerAccess
+ ValidatorAddressAccess
+ QueryContext
+ Clone
+ Send
Expand All @@ -51,13 +53,13 @@ where
let app = App::new()
.app_data(Data::new(runtime_context.clone()))
.wrap(Logger::default())
.route("/", web::get().to(index))
.route("/", web::get().to(index::<Context, KeyManager>))
.route("/tx/{tx_id}", web::get().to(get_tx::<Context>))
.service(
web::scope("/cosigner")
.route("/sign", web::post().to(sign_route::<Context, KeyManager>)),
)
.service(web::scope("/idle").route("/", web::get().to(index)));
.service(web::scope("/idle").route("/", web::get().to(index::<Context, KeyManager>)));

#[cfg(feature = "test-routes")]
let app = app
Expand Down
28 changes: 24 additions & 4 deletions src/server/routes/index.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
use actix_web::HttpResponse;
use actix_web::{
web::Data,
HttpResponse,
};
use serde::Serialize;

use crate::{server::error::ValidatorServerError, key_manager};
use crate::server::routes::sign::Config;

#[derive(Serialize)]
struct IndexBody {
struct IndexBody<'a> {
version: &'static str,
address: &'a str,
bundler_address: &'a str,
block_height: u128,
epoch: u128,
}

pub async fn index() -> actix_web::Result<HttpResponse> {
pub async fn index<Context, KeyManager>(
ctx: Data<Context>,
) -> actix_web::Result<HttpResponse, ValidatorServerError>
where
Context: self::Config<KeyManager>,
KeyManager: key_manager::KeyManager,
{
let body = IndexBody {
version: env!("CARGO_PKG_VERSION"),
address: &ctx.validator_address(),
bundler_address: ctx.bundler_address(),
block_height: ctx.current_block(),
epoch: ctx.current_epoch(),
};

Ok(HttpResponse::Ok().json(body))
}

0 comments on commit 85e6ad0

Please sign in to comment.