Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
d0cd committed Jun 10, 2024
1 parent b530cbd commit 696407c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
8 changes: 3 additions & 5 deletions node/rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {
};

let router = {
let mut routes = axum::Router::new()
let routes = axum::Router::new()

// All the endpoints before the call to `route_layer` are protected with JWT auth.
.route(&format!("/{network}/node/address"), get(Self::get_node_address))
Expand Down Expand Up @@ -200,10 +200,8 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {

// If the `history` feature is enabled, enable the additional endpoint.
#[cfg(feature = "history")]
{
routes =
routes.route(&format!("/{network}/block/:blockHeight/history/:mapping"), get(Self::get_history));
}
let routes =
routes.route(&format!("/{network}/block/:blockHeight/history/:mapping"), get(Self::get_history));

routes
// Pass in `Rest` to make things convenient.
Expand Down
12 changes: 6 additions & 6 deletions node/rest/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ use snarkvm::{
prelude::{block::Transaction, Address, Identifier, LimitedWriter, Plaintext, ToBytes},
};

use axum::response::IntoResponse;
use indexmap::IndexMap;
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use serde_json::json;
use snarkvm::prelude::{History, MappingName};

/// The `get_blocks` query object.
#[derive(Deserialize, Serialize)]
Expand Down Expand Up @@ -451,11 +449,13 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {
#[cfg(feature = "history")]
pub(crate) async fn get_history(
State(rest): State<Self>,
Path((height, variant)): Path<(u32, MappingName)>,
) -> Result<impl IntoResponse, RestError> {
Path((height, mapping)): Path<(u32, snarkvm::prelude::MappingName)>,
) -> Result<impl axum::response::IntoResponse, RestError> {
// Retrieve the history for the given block height and variant.
let history = History::new(N::ID, rest.ledger.vm().finalize_store().storage_mode().clone());
let result = history.load_entry(height, variant)?;
let history = snarkvm::prelude::History::new(N::ID, rest.ledger.vm().finalize_store().storage_mode().clone());
let result = history
.load_mapping(height, mapping)
.map_err(|err| RestError(format!("Could not load mapping '{mapping}' from block '{height}'")))?;

Ok((StatusCode::OK, [(CONTENT_TYPE, "application/json")], result))
}
Expand Down

0 comments on commit 696407c

Please sign in to comment.