global: adding support for safe lengths

This commit is contained in:
nym21
2026-05-06 15:33:07 +02:00
parent da7671744f
commit 086bfd9938
177 changed files with 2445 additions and 2049 deletions
+1 -1
View File
@@ -191,7 +191,7 @@ impl BlockRoutes for ApiRouter<AppState> {
"/api/blocks/tip/height",
get_with(
async |uri: Uri, headers: HeaderMap, _: Empty, State(state): State<AppState>| {
state.respond_text(&headers, CacheStrategy::Tip, &uri, |q| Ok(q.indexed_height().to_string())).await
state.respond_text(&headers, CacheStrategy::Tip, &uri, |q| Ok(q.height().to_string())).await
},
|op| {
op.id("get_block_tip_height")
+1 -2
View File
@@ -42,8 +42,7 @@ pub async fn handler(
Query(params): Query<SeriesSelection>,
State(state): State<AppState>,
) -> Result<Response> {
let mut response =
super::series::serve(state, uri, headers, params, legacy_bytes).await?;
let mut response = super::series::serve(state, uri, headers, params, legacy_bytes).await?;
if response.status() == StatusCode::OK {
response.headers_mut().insert_deprecation(SUNSET);
}
+1 -1
View File
@@ -33,7 +33,7 @@ impl ServerRoutes for ApiRouter<AppState> {
let tip_height = q
.client()
.get_last_height()
.unwrap_or(q.indexed_height());
.unwrap_or(q.height());
q.sync_status(tip_height)
})
.await
+9 -4
View File
@@ -67,8 +67,7 @@ const REQUEST_TIMEOUT: Duration = Duration::from_secs(5);
/// like `; charset=utf-8`. Used to skip JSON-error rewriting for already-JSON bodies.
fn is_json_content_type(s: &str) -> bool {
let mime = s.split(';').next().unwrap_or("").trim();
mime == "application/json"
|| (mime.starts_with("application/") && mime.ends_with("+json"))
mime == "application/json" || (mime.starts_with("application/") && mime.ends_with("+json"))
}
pub struct Server(AppState);
@@ -300,7 +299,11 @@ impl Server {
// NormalizePath must wrap the router (not be a layer) to run before route matching
let app = NormalizePathLayer::trim_trailing_slash().layer(router);
serve(listener, ServiceExt::<Request<Body>>::into_make_service(app)).await?;
serve(
listener,
ServiceExt::<Request<Body>>::into_make_service(app),
)
.await?;
Ok(())
}
@@ -336,7 +339,9 @@ mod tests {
assert!(is_json_content_type("application/json; charset=utf-8"));
assert!(is_json_content_type(" application/json "));
assert!(is_json_content_type("application/problem+json"));
assert!(is_json_content_type("application/vnd.api+json; charset=utf-8"));
assert!(is_json_content_type(
"application/vnd.api+json; charset=utf-8"
));
}
#[test]
+7 -1
View File
@@ -85,7 +85,13 @@ mod tests {
#[test]
fn parses_single_and_multi() {
assert_eq!(TxidsParam::from_query(&format!("txId[]={T1}")).unwrap().txids.len(), 1);
assert_eq!(
TxidsParam::from_query(&format!("txId[]={T1}"))
.unwrap()
.txids
.len(),
1
);
assert_eq!(
TxidsParam::from_query(&format!("txId%5B%5D={T1}&txId[]={T2}"))
.unwrap()
+2 -4
View File
@@ -53,7 +53,7 @@ impl AppState {
/// date's day, then settle once the tip crosses the day boundary.
pub fn date_strategy(&self, version: Version, date: Date) -> CacheStrategy {
self.sync(|q| {
let height = q.indexed_height();
let height = q.height();
q.indexer()
.vecs
.blocks
@@ -76,9 +76,7 @@ impl AppState {
/// - Unknown address → `Tip`
pub fn addr_strategy(&self, version: Version, addr: &Addr, chain_only: bool) -> CacheStrategy {
self.sync(|q| {
if !chain_only
&& let Some(mempool_hash) = q.addr_mempool_hash(addr)
{
if !chain_only && let Some(mempool_hash) = q.addr_mempool_hash(addr) {
return CacheStrategy::MempoolHash(mempool_hash);
}
q.addr_last_activity_height(addr)