From 0375550b7264e1f03e891436198edfd07a2d8f7c Mon Sep 17 00:00:00 2001 From: Arik Sosman Date: Fri, 25 Oct 2024 12:15:47 -0700 Subject: [PATCH] Proxy recursive satoshi endpoint --- src/subcommand/server.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 6d661ce281..b2d0279fdf 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -2215,18 +2215,26 @@ impl Server { async fn sat_inscription_at_index( Extension(index): Extension>, + Extension(server_config): Extension>, Path((DeserializeFromStr(sat), inscription_index)): Path<(DeserializeFromStr, isize)>, - ) -> ServerResult> { + ) -> ServerResult { task::block_in_place(|| { if !index.has_sat_index() { - return Err(ServerError::NotFound( - "this server has no sat index".to_string(), - )); + return if let Some(proxy) = server_config.proxy.as_ref() { + Self::proxy(proxy, &format!("r/sat/{}/at/{}", sat, inscription_index)) + } else { + Err(ServerError::NotFound( + "this server has no sat index".to_string(), + )) + }; } let id = index.get_inscription_id_by_sat_indexed(sat, inscription_index)?; + if let (Some(proxy), None) = (server_config.proxy.as_ref(), id) { + return Self::proxy(proxy, &format!("r/sat/{}/at/{}", sat, inscription_index)); + } - Ok(Json(api::SatInscription { id })) + Ok(Json(api::SatInscription { id }).into_response()) }) }