2024-05-09 11:01:53 -07:00
|
|
|
use axum::extract::Path;
|
|
|
|
|
use axum::extract::State;
|
|
|
|
|
use axum::response::IntoResponse;
|
|
|
|
|
use axum::response::Json;
|
2024-12-18 12:15:38 +08:00
|
|
|
use neptune_cash::prelude::twenty_first::math::digest::Digest;
|
2024-05-09 11:01:53 -07:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
use tarpc::context;
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
|
http_util::{not_found_err, rpc_err},
|
|
|
|
|
model::app_state::AppState,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[axum::debug_handler]
|
|
|
|
|
pub async fn utxo_digest(
|
|
|
|
|
Path(index): Path<u64>,
|
|
|
|
|
State(state): State<Arc<AppState>>,
|
|
|
|
|
) -> Result<Json<Digest>, impl IntoResponse> {
|
|
|
|
|
match state
|
2024-05-27 17:24:01 -07:00
|
|
|
.load()
|
2024-05-09 11:01:53 -07:00
|
|
|
.rpc_client
|
|
|
|
|
.utxo_digest(context::current(), index)
|
|
|
|
|
.await
|
|
|
|
|
.map_err(rpc_err)?
|
|
|
|
|
{
|
|
|
|
|
Some(digest) => Ok(Json(digest)),
|
|
|
|
|
None => Err(not_found_err()),
|
|
|
|
|
}
|
|
|
|
|
}
|