mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-16 21:48:10 -07:00
global: snapshot
This commit is contained in:
@@ -62,6 +62,28 @@ impl MempoolRoutes for ApiRouter<AppState> {
|
||||
},
|
||||
),
|
||||
)
|
||||
.api_route(
|
||||
"/api/mempool/price",
|
||||
get_with(
|
||||
async |headers: HeaderMap, State(state): State<AppState>| {
|
||||
state
|
||||
.cached_json(&headers, CacheStrategy::MaxAge(5), |q| q.live_price())
|
||||
.await
|
||||
},
|
||||
|op| {
|
||||
op.id("get_live_price")
|
||||
.mempool_tag()
|
||||
.summary("Live BTC/USD price")
|
||||
.description(
|
||||
"Returns the current BTC/USD price in cents, derived from \
|
||||
on-chain round-dollar output patterns in the last 12 blocks \
|
||||
plus mempool.",
|
||||
)
|
||||
.ok_response::<u64>()
|
||||
.server_error()
|
||||
},
|
||||
),
|
||||
)
|
||||
.api_route(
|
||||
"/api/v1/fees/mempool-blocks",
|
||||
get_with(
|
||||
|
||||
@@ -71,7 +71,18 @@ impl Server {
|
||||
mut request: Request<Body>,
|
||||
next: Next|
|
||||
-> Response<Body> {
|
||||
request.extensions_mut().insert(connect_info.0);
|
||||
let mut addr = connect_info.0;
|
||||
|
||||
// When behind a reverse proxy (e.g. cloudflared), the direct
|
||||
// connection comes from loopback but the request is external.
|
||||
// Mark it as non-loopback so it gets the stricter limit.
|
||||
if addr.ip().is_loopback()
|
||||
&& request.headers().contains_key("CF-Connecting-IP")
|
||||
{
|
||||
addr.set_ip(std::net::Ipv4Addr::UNSPECIFIED.into());
|
||||
}
|
||||
|
||||
request.extensions_mut().insert(addr);
|
||||
next.run(request).await
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user