mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-18 22:48:10 -07:00
global: snap
This commit is contained in:
@@ -12,7 +12,7 @@ use crate::{
|
||||
AppState, CacheStrategy,
|
||||
cache::CacheParams,
|
||||
extended::{ResponseExtended, TransformResponseExtended},
|
||||
params::{TxidParam, TxidVout, TxidsParam},
|
||||
params::{TxIndexParam, TxidParam, TxidVout, TxidsParam},
|
||||
};
|
||||
|
||||
pub trait TxRoutes {
|
||||
@@ -23,6 +23,24 @@ impl TxRoutes for ApiRouter<AppState> {
|
||||
fn add_tx_routes(self) -> Self {
|
||||
self
|
||||
.api_route(
|
||||
"/api/tx-index/{index}",
|
||||
get_with(
|
||||
async |uri: Uri, headers: HeaderMap, Path(param): Path<TxIndexParam>, State(state): State<AppState>| {
|
||||
state.cached_text(&headers, CacheStrategy::Immutable(Version::ONE), &uri, move |q| q.txid_by_index(param.index).map(|t| t.to_string())).await
|
||||
},
|
||||
|op| op
|
||||
.id("get_tx_by_index")
|
||||
.transactions_tag()
|
||||
.summary("Txid by index")
|
||||
.description("Retrieve the transaction ID (txid) at a given global transaction index. Returns the txid as plain text.")
|
||||
.text_response()
|
||||
.not_modified()
|
||||
.bad_request()
|
||||
.not_found()
|
||||
.server_error(),
|
||||
),
|
||||
)
|
||||
.api_route(
|
||||
"/api/v1/cpfp/{txid}",
|
||||
get_with(
|
||||
async |uri: Uri, headers: HeaderMap, Path(param): Path<TxidParam>, State(state): State<AppState>| {
|
||||
|
||||
@@ -197,7 +197,6 @@ impl Server {
|
||||
let router = router
|
||||
.with_state(state)
|
||||
.merge(website_router)
|
||||
.layer(compression_layer)
|
||||
.layer(response_time_layer)
|
||||
.layer(trace_layer)
|
||||
.layer(CatchPanicLayer::custom(|panic: Box<dyn Any + Send>| {
|
||||
@@ -213,6 +212,7 @@ impl Server {
|
||||
Duration::from_secs(5),
|
||||
))
|
||||
.layer(json_error_layer)
|
||||
.layer(compression_layer)
|
||||
.layer(CorsLayer::permissive())
|
||||
.layer(axum::middleware::from_fn(
|
||||
async |request: Request<Body>, next: Next| -> Response<Body> {
|
||||
|
||||
@@ -11,6 +11,7 @@ mod pool_slug_param;
|
||||
mod series_param;
|
||||
mod time_period_param;
|
||||
mod timestamp_param;
|
||||
mod tx_index_param;
|
||||
mod txid_param;
|
||||
mod txid_vout;
|
||||
mod txids_param;
|
||||
@@ -29,6 +30,7 @@ pub use pool_slug_param::*;
|
||||
pub use series_param::*;
|
||||
pub use time_period_param::*;
|
||||
pub use timestamp_param::*;
|
||||
pub use tx_index_param::*;
|
||||
pub use txid_param::*;
|
||||
pub use txid_vout::*;
|
||||
pub use txids_param::*;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
||||
use brk_types::TxIndex;
|
||||
|
||||
/// Transaction index path parameter
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
pub struct TxIndexParam {
|
||||
pub index: TxIndex,
|
||||
}
|
||||
Reference in New Issue
Block a user