server: moved params from brk_types

This commit is contained in:
nym21
2026-04-02 23:49:01 +02:00
parent 744dce932c
commit 4840e564f4
34 changed files with 315 additions and 197 deletions
@@ -5,12 +5,13 @@ use axum::{
response::Redirect,
routing::get,
};
use brk_types::{
AddrParam, AddrStats, AddrTxidsParam, AddrValidation, Transaction, Txid, Utxo,
ValidateAddrParam, Version,
};
use brk_types::{AddrStats, AddrValidation, Transaction, Txid, Utxo, Version};
use crate::{AppState, CacheStrategy, extended::TransformResponseExtended};
use crate::{
AppState, CacheStrategy,
extended::TransformResponseExtended,
params::{AddrParam, AddrTxidsParam, ValidateAddrParam},
};
pub trait AddrRoutes {
fn add_addr_routes(self) -> Self;
@@ -4,12 +4,13 @@ use axum::{
http::{HeaderMap, Uri},
};
use brk_query::BLOCK_TXS_PAGE_SIZE;
use brk_types::{
BlockHashParam, BlockHashStartIndex, BlockHashTxIndex, BlockInfo, BlockInfoV1, BlockStatus,
BlockTimestamp, HeightParam, TimestampParam, Transaction, TxIndex, Txid, Version,
};
use brk_types::{BlockInfo, BlockInfoV1, BlockStatus, BlockTimestamp, Transaction, TxIndex, Txid, Version};
use crate::{AppState, CacheStrategy, extended::TransformResponseExtended};
use crate::{
AppState, CacheStrategy,
extended::TransformResponseExtended,
params::{BlockHashParam, BlockHashStartIndex, BlockHashTxIndex, HeightParam, TimestampParam},
};
pub trait BlockRoutes {
fn add_block_routes(self) -> Self;
@@ -3,9 +3,13 @@ use axum::{
extract::{Query, State},
http::{HeaderMap, Uri},
};
use brk_types::{DifficultyAdjustment, HistoricalPrice, OptionalTimestampParam, Prices, Timestamp};
use brk_types::{DifficultyAdjustment, HistoricalPrice, Prices, Timestamp};
use crate::{AppState, CacheStrategy, extended::TransformResponseExtended};
use crate::{
AppState, CacheStrategy,
extended::TransformResponseExtended,
params::OptionalTimestampParam,
};
pub trait GeneralRoutes {
fn add_general_routes(self) -> Self;
@@ -6,12 +6,16 @@ use axum::{
routing::get,
};
use brk_types::{
BlockCountParam, BlockFeesEntry, BlockInfoV1, BlockRewardsEntry, BlockSizesWeights,
BlockFeesEntry, BlockInfoV1, BlockRewardsEntry, BlockSizesWeights,
DifficultyAdjustmentEntry, HashrateSummary, PoolDetail, PoolHashrateEntry, PoolInfo,
PoolSlugAndHeightParam, PoolSlugParam, PoolsSummary, RewardStats, TimePeriodParam,
PoolsSummary, RewardStats,
};
use crate::{AppState, CacheStrategy, Error, extended::TransformResponseExtended};
use crate::{
AppState, CacheStrategy, Error,
extended::TransformResponseExtended,
params::{BlockCountParam, PoolSlugAndHeightParam, PoolSlugParam, TimePeriodParam},
};
pub trait MiningRoutes {
fn add_mining_routes(self) -> Self;
@@ -6,12 +6,13 @@ use axum::{
extract::{Path, State},
http::{HeaderMap, Uri},
};
use brk_types::{
CpfpInfo, MerkleProof, Transaction, TxOutspend, TxStatus, Txid, TxidParam, TxidVout,
TxidsParam, Version,
};
use brk_types::{CpfpInfo, MerkleProof, Transaction, TxOutspend, TxStatus, Txid, Version};
use crate::{AppState, CacheStrategy, extended::TransformResponseExtended};
use crate::{
AppState, CacheStrategy,
extended::TransformResponseExtended,
params::{TxidParam, TxidVout, TxidsParam},
};
pub trait TxRoutes {
fn add_tx_routes(self) -> Self;
@@ -24,7 +25,7 @@ impl TxRoutes for ApiRouter<AppState> {
"/api/v1/cpfp/{txid}",
get_with(
async |uri: Uri, headers: HeaderMap, Path(param): Path<TxidParam>, State(state): State<AppState>| {
state.cached_json(&headers, state.tx_cache(Version::ONE, &param.txid), &uri, move |q| q.cpfp(param)).await
state.cached_json(&headers, state.tx_cache(Version::ONE, &param.txid), &uri, move |q| q.cpfp(&param.txid)).await
},
|op| op
.id("get_cpfp")
@@ -45,7 +46,7 @@ impl TxRoutes for ApiRouter<AppState> {
Path(param): Path<TxidParam>,
State(state): State<AppState>
| {
state.cached_json(&headers, state.tx_cache(Version::ONE, &param.txid), &uri, move |q| q.transaction(param)).await
state.cached_json(&headers, state.tx_cache(Version::ONE, &param.txid), &uri, move |q| q.transaction(&param.txid)).await
},
|op| op
.id("get_tx")
@@ -67,10 +68,10 @@ impl TxRoutes for ApiRouter<AppState> {
async |
uri: Uri,
headers: HeaderMap,
Path(txid): Path<TxidParam>,
Path(param): Path<TxidParam>,
State(state): State<AppState>
| {
state.cached_text(&headers, state.tx_cache(Version::ONE, &txid.txid), &uri, move |q| q.transaction_hex(txid)).await
state.cached_text(&headers, state.tx_cache(Version::ONE, &param.txid), &uri, move |q| q.transaction_hex(&param.txid)).await
},
|op| op
.id("get_tx_hex")
@@ -89,8 +90,8 @@ impl TxRoutes for ApiRouter<AppState> {
.api_route(
"/api/tx/{txid}/merkleblock-proof",
get_with(
async |uri: Uri, headers: HeaderMap, Path(txid): Path<TxidParam>, State(state): State<AppState>| {
state.cached_text(&headers, state.tx_cache(Version::ONE, &txid.txid), &uri, move |q| q.merkleblock_proof(txid)).await
async |uri: Uri, headers: HeaderMap, Path(param): Path<TxidParam>, State(state): State<AppState>| {
state.cached_text(&headers, state.tx_cache(Version::ONE, &param.txid), &uri, move |q| q.merkleblock_proof(&param.txid)).await
},
|op| op
.id("get_tx_merkleblock_proof")
@@ -107,8 +108,8 @@ impl TxRoutes for ApiRouter<AppState> {
.api_route(
"/api/tx/{txid}/merkle-proof",
get_with(
async |uri: Uri, headers: HeaderMap, Path(txid): Path<TxidParam>, State(state): State<AppState>| {
state.cached_json(&headers, state.tx_cache(Version::ONE, &txid.txid), &uri, move |q| q.merkle_proof(txid)).await
async |uri: Uri, headers: HeaderMap, Path(param): Path<TxidParam>, State(state): State<AppState>| {
state.cached_json(&headers, state.tx_cache(Version::ONE, &param.txid), &uri, move |q| q.merkle_proof(&param.txid)).await
},
|op| op
.id("get_tx_merkle_proof")
@@ -131,8 +132,7 @@ impl TxRoutes for ApiRouter<AppState> {
Path(path): Path<TxidVout>,
State(state): State<AppState>
| {
let txid = TxidParam { txid: path.txid };
state.cached_json(&headers, CacheStrategy::Tip, &uri, move |q| q.outspend(txid, path.vout)).await
state.cached_json(&headers, CacheStrategy::Tip, &uri, move |q| q.outspend(&path.txid, path.vout)).await
},
|op| op
.id("get_tx_outspend")
@@ -154,10 +154,10 @@ impl TxRoutes for ApiRouter<AppState> {
async |
uri: Uri,
headers: HeaderMap,
Path(txid): Path<TxidParam>,
Path(param): Path<TxidParam>,
State(state): State<AppState>
| {
state.cached_json(&headers, CacheStrategy::Tip, &uri, move |q| q.outspends(txid)).await
state.cached_json(&headers, CacheStrategy::Tip, &uri, move |q| q.outspends(&param.txid)).await
},
|op| op
.id("get_tx_outspends")
@@ -176,8 +176,8 @@ impl TxRoutes for ApiRouter<AppState> {
.api_route(
"/api/tx/{txid}/raw",
get_with(
async |uri: Uri, headers: HeaderMap, Path(txid): Path<TxidParam>, State(state): State<AppState>| {
state.cached_bytes(&headers, state.tx_cache(Version::ONE, &txid.txid), &uri, move |q| q.transaction_raw(txid)).await
async |uri: Uri, headers: HeaderMap, Path(param): Path<TxidParam>, State(state): State<AppState>| {
state.cached_bytes(&headers, state.tx_cache(Version::ONE, &param.txid), &uri, move |q| q.transaction_raw(&param.txid)).await
},
|op| op
.id("get_tx_raw")
@@ -200,7 +200,7 @@ impl TxRoutes for ApiRouter<AppState> {
Path(param): Path<TxidParam>,
State(state): State<AppState>
| {
state.cached_json(&headers, state.tx_cache(Version::ONE, &param.txid), &uri, move |q| q.transaction_status(param)).await
state.cached_json(&headers, state.tx_cache(Version::ONE, &param.txid), &uri, move |q| q.transaction_status(&param.txid)).await
},
|op| op
.id("get_tx_status")
+5 -3
View File
@@ -9,10 +9,12 @@ use axum::{
};
use brk_traversable::TreeNode;
use brk_types::{
CostBasisCohortParam, CostBasisFormatted, CostBasisParams, CostBasisQuery, DataRangeFormat,
Date, DetailedSeriesCount, Index, IndexInfo, PaginatedSeries, Pagination, SearchQuery,
SeriesData, SeriesInfo, SeriesList, SeriesName, SeriesSelection, SeriesSelectionLegacy,
CostBasisFormatted, DataRangeFormat, Date, DetailedSeriesCount, Index, IndexInfo,
PaginatedSeries, Pagination, SearchQuery, SeriesData, SeriesInfo, SeriesList, SeriesName,
SeriesSelection, SeriesSelectionLegacy,
};
use crate::params::{CostBasisCohortParam, CostBasisParams, CostBasisQuery};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
+7 -4
View File
@@ -9,12 +9,15 @@ use axum::{
};
use brk_traversable::TreeNode;
use brk_types::{
CostBasisCohortParam, CostBasisFormatted, CostBasisParams, CostBasisQuery, DataRangeFormat,
Date, IndexInfo, PaginatedSeries, Pagination, SearchQuery, SeriesCount, SeriesData, SeriesInfo,
SeriesNameWithIndex, SeriesParam, SeriesSelection,
CostBasisFormatted, DataRangeFormat, Date, IndexInfo, PaginatedSeries, Pagination, SearchQuery,
SeriesCount, SeriesData, SeriesInfo, SeriesNameWithIndex, SeriesSelection,
};
use crate::{CacheStrategy, extended::TransformResponseExtended};
use crate::{
CacheStrategy,
extended::TransformResponseExtended,
params::{CostBasisCohortParam, CostBasisParams, CostBasisQuery, SeriesParam},
};
use super::AppState;