mempool: snapshot 5 + query: new tools + server: endpoints

This commit is contained in:
nym21
2025-12-14 02:06:14 +01:00
parent db5d784ff7
commit b491b1f41f
79 changed files with 1588 additions and 129 deletions
@@ -47,6 +47,7 @@ pub trait HeaderMapExtended {
fn insert_content_type_text_html(&mut self);
fn insert_content_type_text_plain(&mut self);
fn insert_content_type_font_woff2(&mut self);
fn insert_content_type_octet_stream(&mut self);
}
impl HeaderMapExtended for HeaderMap {
@@ -203,4 +204,11 @@ impl HeaderMapExtended for HeaderMap {
fn insert_content_type_font_woff2(&mut self) {
self.insert(header::CONTENT_TYPE, "font/woff2".parse().unwrap());
}
fn insert_content_type_octet_stream(&mut self) {
self.insert(
header::CONTENT_TYPE,
"application/octet-stream".parse().unwrap(),
);
}
}
@@ -20,6 +20,8 @@ where
T: Serialize;
fn new_text(value: &str, etag: &str) -> Self;
fn new_text_with(status: StatusCode, value: &str, etag: &str) -> Self;
fn new_bytes(value: Vec<u8>, etag: &str) -> Self;
fn new_bytes_with(status: StatusCode, value: Vec<u8>, etag: &str) -> Self;
}
impl ResponseExtended for Response<Body> {
@@ -68,4 +70,19 @@ impl ResponseExtended for Response<Body> {
headers.insert_etag(etag);
response
}
fn new_bytes(value: Vec<u8>, etag: &str) -> Self {
Self::new_bytes_with(StatusCode::default(), value, etag)
}
fn new_bytes_with(status: StatusCode, value: Vec<u8>, etag: &str) -> Self {
let mut response = Response::builder().body(value.into()).unwrap();
*response.status_mut() = status;
let headers = response.headers_mut();
headers.insert_cors();
headers.insert_content_type_octet_stream();
headers.insert_cache_control_must_revalidate();
headers.insert_etag(etag);
response
}
}
+28
View File
@@ -1,3 +1,5 @@
use std::fmt::Display;
use axum::{http::StatusCode, response::Response};
use brk_error::{Error, Result};
use serde::Serialize;
@@ -12,6 +14,12 @@ pub trait ResultExtended<T> {
fn to_text_response(self, etag: &str) -> Response
where
T: AsRef<str>;
fn to_display_response(self, etag: &str) -> Response
where
T: Display;
fn to_bytes_response(self, etag: &str) -> Response
where
T: Into<Vec<u8>>;
}
impl<T> ResultExtended<T> for Result<T> {
@@ -50,4 +58,24 @@ impl<T> ResultExtended<T> for Result<T> {
Err((status, message)) => Response::new_text_with(status, &message, etag),
}
}
fn to_display_response(self, etag: &str) -> Response
where
T: Display,
{
match self.with_status() {
Ok(value) => Response::new_text(&value.to_string(), etag),
Err((status, message)) => Response::new_text_with(status, &message, etag),
}
}
fn to_bytes_response(self, etag: &str) -> Response
where
T: Into<Vec<u8>>,
{
match self.with_status() {
Ok(value) => Response::new_bytes(value.into(), etag),
Err((status, message)) => Response::new_bytes_with(status, message.into_bytes(), etag),
}
}
}