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;
|
2025-01-22 21:00:11 -08:00
|
|
|
use crate::http_util::rpc_method_err;
|
2024-05-09 11:01:53 -07:00
|
|
|
use crate::model::app_state::AppState;
|
2025-08-13 19:34:02 +02:00
|
|
|
use crate::model::transparent_utxo_tuple::TransparentUtxoTuple;
|
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;
|
2025-08-13 19:34:02 +02:00
|
|
|
use neptune_cash::api::export::Tip5;
|
2025-01-22 21:00:11 -08:00
|
|
|
use neptune_cash::prelude::tasm_lib::prelude::Digest;
|
2024-05-09 11:01:53 -07:00
|
|
|
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,
|
2025-08-13 19:34:02 +02:00
|
|
|
transparent_utxo_info: Option<TransparentUtxoTuple>,
|
2024-05-09 11:01:53 -07:00
|
|
|
}
|
|
|
|
|
|
2024-05-27 17:24:01 -07:00
|
|
|
let state = &state_rw.load();
|
2025-08-13 19:34:02 +02:00
|
|
|
let cache = state.transparent_utxos_cache.clone();
|
2024-05-25 19:16:36 -07:00
|
|
|
|
|
|
|
|
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
|
2025-08-13 19:34:02 +02:00
|
|
|
.utxo_digest(context::current(), state.token(), index, cache)
|
2024-05-09 11:01:53 -07:00
|
|
|
.await
|
2024-05-25 19:16:36 -07:00
|
|
|
.map_err(|e| not_found_html_response(state, Some(e.to_string())))?
|
2025-01-22 21:00:11 -08:00
|
|
|
.map_err(rpc_method_err)?
|
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
|
|
|
|
2025-08-13 19:34:02 +02:00
|
|
|
let transparent_utxo_info = state
|
|
|
|
|
.transparent_utxos_cache
|
|
|
|
|
.lock()
|
|
|
|
|
.await
|
|
|
|
|
.iter()
|
|
|
|
|
.find(|tu| tu.aocl_leaf_index().is_some_and(|li| li == index))
|
|
|
|
|
.cloned();
|
|
|
|
|
|
2024-05-09 11:01:53 -07:00
|
|
|
let utxo_page = UtxoHtmlPage {
|
|
|
|
|
index,
|
|
|
|
|
header,
|
|
|
|
|
digest,
|
2025-08-13 19:34:02 +02:00
|
|
|
transparent_utxo_info,
|
2024-05-09 11:01:53 -07:00
|
|
|
};
|
|
|
|
|
Ok(Html(utxo_page.to_string()))
|
|
|
|
|
}
|