Skip to content

Commit

Permalink
Add Json serialization into blocking task
Browse files Browse the repository at this point in the history
  • Loading branch information
raychu86 committed Jul 17, 2024
1 parent 87f3bbd commit 0388e68
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions node/rest/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,26 +263,24 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {
let height = rest.ledger.latest_height();

// Retrieve all the mapping values from the mapping.
let mapping_values = match tokio::task::spawn_blocking(move || {
rest.ledger.vm().finalize_store().get_mapping_confirmed(id, name)
})
.await
match tokio::task::spawn_blocking(move || rest.ledger.vm().finalize_store().get_mapping_confirmed(id, name))
.await
{
Ok(Ok(mapping_values)) => mapping_values,
Ok(Err(err)) => return Err(RestError(format!("Unable to read mapping - {err}"))),
Err(err) => return Err(RestError(format!("Unable to read mapping - {err}"))),
};
Ok(Ok(mapping_values)) => {
// Check if metadata is requested and return the mapping with metadata if so.
if metadata.metadata.unwrap_or(false) {
return Ok(ErasedJson::pretty(json!({
"data": mapping_values,
"height": height,
})));
}

// Check if metadata is requested and return the mapping with metadata if so.
if metadata.metadata.unwrap_or(false) {
return Ok(ErasedJson::pretty(json!({
"data": mapping_values,
"height": height,
})));
// Return the full mapping without metadata.
Ok(ErasedJson::pretty(mapping_values))
}
Ok(Err(err)) => Err(RestError(format!("Unable to read mapping - {err}"))),
Err(err) => Err(RestError(format!("Unable to read mapping - {err}"))),
}

// Return the full mapping without metadata.
Ok(ErasedJson::pretty(mapping_values))
}

// GET /<network>/statePath/{commitment}
Expand Down

0 comments on commit 0388e68

Please sign in to comment.