server: reorg

This commit is contained in:
nym21
2026-04-02 13:19:56 +02:00
parent 099699872e
commit d92cf43c57
13 changed files with 56 additions and 52 deletions

View File

@@ -153,6 +153,6 @@ impl<T> Loss<T> {
.into_iter() .into_iter()
.rev() .rev()
.enumerate() .enumerate()
.map(move |(n, threshold)| (threshold, &ranges[len - 1 - n..])) .map(move |(n, threshold)| (threshold, &ranges[len - 2 - n..]))
} }
} }

View File

@@ -208,6 +208,6 @@ impl<T> Profit<T> {
.into_iter() .into_iter()
.rev() .rev()
.enumerate() .enumerate()
.map(move |(n, threshold)| (threshold, &ranges[..n + 1])) .map(move |(n, threshold)| (threshold, &ranges[..n + 2]))
} }
} }

View File

@@ -273,7 +273,7 @@ impl ProfitabilityMetrics {
ProfitabilityBucket::forced_import(db, name, version, indexes, cached_starts) ProfitabilityBucket::forced_import(db, name, version, indexes, cached_starts)
})?; })?;
let aggregate_version = version + Version::ONE; let aggregate_version = version + Version::TWO;
let profit = Profit::try_new(|name| { let profit = Profit::try_new(|name| {
ProfitabilityBucket::forced_import(db, name, aggregate_version, indexes, cached_starts) ProfitabilityBucket::forced_import(db, name, aggregate_version, indexes, cached_starts)

View File

@@ -10,9 +10,7 @@ use brk_types::{
ValidateAddrParam, ValidateAddrParam,
}; };
use crate::{CacheStrategy, extended::TransformResponseExtended}; use crate::{AppState, CacheStrategy, extended::TransformResponseExtended};
use super::AppState;
pub trait AddrRoutes { pub trait AddrRoutes {
fn add_addr_routes(self) -> Self; fn add_addr_routes(self) -> Self;

View File

@@ -9,9 +9,7 @@ use brk_types::{
BlockTimestamp, HeightParam, TimestampParam, Transaction, TxIndex, Txid, BlockTimestamp, HeightParam, TimestampParam, Transaction, TxIndex, Txid,
}; };
use crate::{CacheStrategy, extended::TransformResponseExtended}; use crate::{AppState, CacheStrategy, extended::TransformResponseExtended};
use super::AppState;
pub trait BlockRoutes { pub trait BlockRoutes {
fn add_block_routes(self) -> Self; fn add_block_routes(self) -> Self;

View File

@@ -5,9 +5,7 @@ use axum::{
}; };
use brk_types::{MempoolBlock, RecommendedFees}; use brk_types::{MempoolBlock, RecommendedFees};
use crate::extended::TransformResponseExtended; use crate::{AppState, extended::TransformResponseExtended};
use super::AppState;
pub trait FeesRoutes { pub trait FeesRoutes {
fn add_fees_routes(self) -> Self; fn add_fees_routes(self) -> Self;

View File

@@ -3,13 +3,9 @@ use axum::{
extract::{Query, State}, extract::{Query, State},
http::{HeaderMap, Uri}, http::{HeaderMap, Uri},
}; };
use brk_types::{ use brk_types::{DifficultyAdjustment, HistoricalPrice, OptionalTimestampParam, Prices, Timestamp};
DifficultyAdjustment, HistoricalPrice, OptionalTimestampParam, Prices, Timestamp,
};
use crate::{CacheStrategy, extended::TransformResponseExtended}; use crate::{AppState, CacheStrategy, extended::TransformResponseExtended};
use super::AppState;
pub trait GeneralRoutes { pub trait GeneralRoutes {
fn add_general_routes(self) -> Self; fn add_general_routes(self) -> Self;

View File

@@ -5,9 +5,7 @@ use axum::{
}; };
use brk_types::{Dollars, MempoolInfo, MempoolRecentTx, Txid}; use brk_types::{Dollars, MempoolInfo, MempoolRecentTx, Txid};
use crate::extended::TransformResponseExtended; use crate::{AppState, extended::TransformResponseExtended};
use super::AppState;
pub trait MempoolRoutes { pub trait MempoolRoutes {
fn add_mempool_routes(self) -> Self; fn add_mempool_routes(self) -> Self;

View File

@@ -7,14 +7,11 @@ use axum::{
}; };
use brk_types::{ use brk_types::{
BlockCountParam, BlockFeesEntry, BlockInfoV1, BlockRewardsEntry, BlockSizesWeights, BlockCountParam, BlockFeesEntry, BlockInfoV1, BlockRewardsEntry, BlockSizesWeights,
DifficultyAdjustmentEntry, HashrateSummary, PoolDetail, DifficultyAdjustmentEntry, HashrateSummary, PoolDetail, PoolHashrateEntry, PoolInfo,
PoolHashrateEntry, PoolInfo, PoolSlugAndHeightParam, PoolSlugParam, PoolsSummary, PoolSlugAndHeightParam, PoolSlugParam, PoolsSummary, RewardStats, TimePeriodParam,
RewardStats, TimePeriodParam,
}; };
use crate::{CacheStrategy, Error, extended::TransformResponseExtended}; use crate::{AppState, CacheStrategy, Error, extended::TransformResponseExtended};
use super::AppState;
pub trait MiningRoutes { pub trait MiningRoutes {
fn add_mining_routes(self) -> Self; fn add_mining_routes(self) -> Self;

View File

@@ -0,0 +1,35 @@
use aide::axum::ApiRouter;
use crate::AppState;
mod addrs;
mod blocks;
mod fees;
mod general;
mod mempool;
mod mining;
mod transactions;
use addrs::AddrRoutes;
use blocks::BlockRoutes;
use fees::FeesRoutes;
use general::GeneralRoutes;
use mempool::MempoolRoutes;
use mining::MiningRoutes;
use transactions::TxRoutes;
pub trait MempoolSpaceRoutes {
fn add_mempool_space_routes(self) -> Self;
}
impl MempoolSpaceRoutes for ApiRouter<AppState> {
fn add_mempool_space_routes(self) -> Self {
self.add_general_routes()
.add_addr_routes()
.add_block_routes()
.add_mining_routes()
.add_fees_routes()
.add_mempool_routes()
.add_tx_routes()
}
}

View File

@@ -7,13 +7,10 @@ use axum::{
http::{HeaderMap, Uri}, http::{HeaderMap, Uri},
}; };
use brk_types::{ use brk_types::{
CpfpInfo, MerkleProof, Transaction, TxOutspend, TxStatus, Txid, TxidParam, TxidVout, CpfpInfo, MerkleProof, Transaction, TxOutspend, TxStatus, Txid, TxidParam, TxidVout, TxidsParam,
TxidsParam,
}; };
use crate::{CacheStrategy, extended::TransformResponseExtended}; use crate::{AppState, CacheStrategy, extended::TransformResponseExtended};
use super::AppState;
pub trait TxRoutes { pub trait TxRoutes {
fn add_tx_routes(self) -> Self; fn add_tx_routes(self) -> Self;
@@ -26,7 +23,7 @@ impl TxRoutes for ApiRouter<AppState> {
"/api/v1/cpfp/{txid}", "/api/v1/cpfp/{txid}",
get_with( get_with(
async |uri: Uri, headers: HeaderMap, Path(txid): Path<TxidParam>, State(state): State<AppState>| { async |uri: Uri, headers: HeaderMap, Path(txid): Path<TxidParam>, State(state): State<AppState>| {
state.cached_json(&headers, CacheStrategy::MempoolHash(0), &uri, move |q| q.cpfp(txid)).await state.cached_json(&headers, state.mempool_cache(), &uri, move |q| q.cpfp(txid)).await
}, },
|op| op |op| op
.id("get_cpfp") .id("get_cpfp")
@@ -223,7 +220,7 @@ impl TxRoutes for ApiRouter<AppState> {
get_with( get_with(
async |uri: Uri, headers: HeaderMap, State(state): State<AppState>| { async |uri: Uri, headers: HeaderMap, State(state): State<AppState>| {
let params = TxidsParam::from_query(uri.query().unwrap_or("")); let params = TxidsParam::from_query(uri.query().unwrap_or(""));
state.cached_json(&headers, CacheStrategy::MempoolHash(0), &uri, move |q| q.transaction_times(&params.txids)).await state.cached_json(&headers, state.mempool_cache(), &uri, move |q| q.transaction_times(&params.txids)).await
}, },
|op| op |op| op
.id("get_transaction_times") .id("get_transaction_times")

View File

@@ -14,26 +14,19 @@ use axum::{
use crate::{ use crate::{
Error, Error,
api::{ api::{
addrs::AddrRoutes, blocks::BlockRoutes, fees::FeesRoutes, general::GeneralRoutes, mempool_space::MempoolSpaceRoutes, metrics::ApiMetricsLegacyRoutes,
mempool::MempoolRoutes, metrics_legacy::ApiMetricsLegacyRoutes, mining::MiningRoutes, series::ApiSeriesRoutes, server::ServerRoutes,
series::ApiSeriesRoutes, server::ServerRoutes, transactions::TxRoutes,
}, },
extended::{ResponseExtended, TransformResponseExtended}, extended::{ResponseExtended, TransformResponseExtended},
}; };
use super::AppState; use super::AppState;
mod addrs; mod mempool_space;
mod blocks; mod metrics;
mod fees;
mod general;
mod mempool;
mod metrics_legacy;
mod mining;
mod openapi; mod openapi;
mod series; mod series;
mod server; mod server;
mod transactions;
pub use openapi::*; pub use openapi::*;
@@ -46,13 +39,7 @@ impl ApiRoutes for ApiRouter<AppState> {
self.add_server_routes() self.add_server_routes()
.add_series_routes() .add_series_routes()
.add_metrics_legacy_routes() .add_metrics_legacy_routes()
.add_general_routes() .add_mempool_space_routes()
.add_addr_routes()
.add_block_routes()
.add_mining_routes()
.add_fees_routes()
.add_mempool_routes()
.add_tx_routes()
.route("/api/server", get(Redirect::temporary("/api#tag/server"))) .route("/api/server", get(Redirect::temporary("/api#tag/server")))
.api_route( .api_route(
"/openapi.json", "/openapi.json",