2024-05-09 11:01:53 -07:00
|
|
|
use crate::html::component::header::HeaderHtml;
|
2024-05-10 14:20:43 -07:00
|
|
|
use crate::html::page::not_found::not_found_html_response;
|
2024-05-09 11:01:53 -07:00
|
|
|
use crate::model::app_state::AppState;
|
2024-05-10 14:20:43 -07:00
|
|
|
use axum::extract::rejection::PathRejection;
|
2024-05-09 11:01:53 -07:00
|
|
|
use axum::extract::Path;
|
|
|
|
|
use axum::extract::State;
|
|
|
|
|
use axum::response::Html;
|
|
|
|
|
use axum::response::Response;
|
|
|
|
|
use html_escaper::Escape;
|
|
|
|
|
use html_escaper::Trusted;
|
|
|
|
|
use neptune_core::prelude::tasm_lib::Digest;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
use tarpc::context;
|
|
|
|
|
|
|
|
|
|
#[axum::debug_handler]
|
|
|
|
|
pub async fn utxo_page(
|
2024-05-10 14:20:43 -07:00
|
|
|
index_maybe: Result<Path<u64>, PathRejection>,
|
2024-05-25 19:16:36 -07:00
|
|
|
State(state_rw): State<Arc<AppState>>,
|
2024-05-09 11:01:53 -07:00
|
|
|
) -> Result<Html<String>, Response> {
|
|
|
|
|
#[derive(boilerplate::Boilerplate)]
|
|
|
|
|
#[boilerplate(filename = "web/html/page/utxo.html")]
|
2024-05-25 19:16:36 -07:00
|
|
|
pub struct UtxoHtmlPage<'a> {
|
|
|
|
|
header: HeaderHtml<'a>,
|
2024-05-09 11:01:53 -07:00
|
|
|
index: u64,
|
|
|
|
|
digest: Digest,
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 19:16:36 -07:00
|
|
|
let state = &*state_rw.read().await;
|
|
|
|
|
|
|
|
|
|
let Path(index) =
|
|
|
|
|
index_maybe.map_err(|e| not_found_html_response(state, Some(e.to_string())))?;
|
2024-05-10 14:20:43 -07:00
|
|
|
|
2024-05-09 11:01:53 -07:00
|
|
|
let digest = match state
|
|
|
|
|
.rpc_client
|
|
|
|
|
.utxo_digest(context::current(), index)
|
|
|
|
|
.await
|
2024-05-25 19:16:36 -07:00
|
|
|
.map_err(|e| not_found_html_response(state, Some(e.to_string())))?
|
2024-05-09 11:01:53 -07:00
|
|
|
{
|
|
|
|
|
Some(digest) => digest,
|
2024-05-10 14:20:43 -07:00
|
|
|
None => {
|
|
|
|
|
return Err(not_found_html_response(
|
2024-05-25 19:16:36 -07:00
|
|
|
state,
|
2024-05-10 14:20:43 -07:00
|
|
|
Some("The requested UTXO does not exist".to_string()),
|
|
|
|
|
))
|
|
|
|
|
}
|
2024-05-09 11:01:53 -07:00
|
|
|
};
|
|
|
|
|
|
2024-05-25 19:16:36 -07:00
|
|
|
let header = HeaderHtml { state };
|
2024-05-09 11:01:53 -07:00
|
|
|
|
|
|
|
|
let utxo_page = UtxoHtmlPage {
|
|
|
|
|
index,
|
|
|
|
|
header,
|
|
|
|
|
digest,
|
|
|
|
|
};
|
|
|
|
|
Ok(Html(utxo_page.to_string()))
|
|
|
|
|
}
|