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
@@ -0,0 +1,10 @@
use schemars::JsonSchema;
use serde::Deserialize;
use brk_types::Addr;
#[derive(Deserialize, JsonSchema)]
pub struct AddrParam {
#[serde(rename = "address")]
pub addr: Addr,
}
@@ -0,0 +1,10 @@
use schemars::JsonSchema;
use serde::Deserialize;
use brk_types::Txid;
#[derive(Debug, Default, Deserialize, JsonSchema)]
pub struct AddrTxidsParam {
/// Txid to paginate from (return transactions before this one)
pub after_txid: Option<Txid>,
}
@@ -0,0 +1,9 @@
use schemars::JsonSchema;
use serde::Deserialize;
#[derive(Deserialize, JsonSchema)]
pub struct BlockCountParam {
/// Number of recent blocks to include
#[schemars(example = 100)]
pub block_count: usize,
}
@@ -0,0 +1,9 @@
use schemars::JsonSchema;
use serde::Deserialize;
use brk_types::BlockHash;
#[derive(Deserialize, JsonSchema)]
pub struct BlockHashParam {
pub hash: BlockHash,
}
@@ -0,0 +1,14 @@
use schemars::JsonSchema;
use serde::Deserialize;
use brk_types::{BlockHash, TxIndex};
#[derive(Deserialize, JsonSchema)]
pub struct BlockHashStartIndex {
/// Bitcoin block hash
pub hash: BlockHash,
/// Starting transaction index within the block (0-based)
#[schemars(example = 0)]
pub start_index: TxIndex,
}
@@ -0,0 +1,14 @@
use schemars::JsonSchema;
use serde::Deserialize;
use brk_types::{BlockHash, TxIndex};
#[derive(Deserialize, JsonSchema)]
pub struct BlockHashTxIndex {
/// Bitcoin block hash
pub hash: BlockHash,
/// Transaction index within the block (0-based)
#[schemars(example = 0)]
pub index: TxIndex,
}
@@ -0,0 +1,29 @@
use schemars::JsonSchema;
use serde::Deserialize;
use brk_types::{Cohort, CostBasisBucket, CostBasisValue, Date};
/// Path parameters for cost basis distribution endpoint.
#[derive(Deserialize, JsonSchema)]
pub struct CostBasisParams {
pub cohort: Cohort,
#[schemars(with = "String", example = &"2024-01-01")]
pub date: Date,
}
/// Path parameters for cost basis dates endpoint.
#[derive(Deserialize, JsonSchema)]
pub struct CostBasisCohortParam {
pub cohort: Cohort,
}
/// Query parameters for cost basis distribution endpoint.
#[derive(Deserialize, JsonSchema)]
pub struct CostBasisQuery {
/// Bucket type for aggregation. Default: raw (no aggregation).
#[serde(default)]
pub bucket: CostBasisBucket,
/// Value type to return. Default: supply.
#[serde(default)]
pub value: CostBasisValue,
}
@@ -0,0 +1,9 @@
use schemars::JsonSchema;
use serde::Deserialize;
use brk_types::Height;
#[derive(Deserialize, JsonSchema)]
pub struct HeightParam {
pub height: Height,
}
@@ -0,0 +1,10 @@
use schemars::JsonSchema;
use serde::Deserialize;
use brk_types::Limit;
#[derive(Deserialize, JsonSchema)]
pub struct LimitParam {
#[serde(default)]
pub limit: Limit,
}
+35
View File
@@ -0,0 +1,35 @@
mod addr_param;
mod addr_txids_param;
mod block_count_param;
mod blockhash_param;
mod blockhash_start_index;
mod blockhash_tx_index;
mod cost_basis_params;
mod height_param;
mod limit_param;
mod pool_slug_param;
mod series_param;
mod time_period_param;
mod timestamp_param;
mod txid_param;
mod txid_vout;
mod txids_param;
mod validate_addr_param;
pub use addr_param::*;
pub use addr_txids_param::*;
pub use block_count_param::*;
pub use blockhash_param::*;
pub use blockhash_start_index::*;
pub use blockhash_tx_index::*;
pub use cost_basis_params::*;
pub use height_param::*;
pub use limit_param::*;
pub use pool_slug_param::*;
pub use series_param::*;
pub use time_period_param::*;
pub use timestamp_param::*;
pub use txid_param::*;
pub use txid_vout::*;
pub use txids_param::*;
pub use validate_addr_param::*;
@@ -0,0 +1,15 @@
use schemars::JsonSchema;
use serde::Deserialize;
use brk_types::{Height, PoolSlug};
#[derive(Deserialize, JsonSchema)]
pub struct PoolSlugParam {
pub slug: PoolSlug,
}
#[derive(Deserialize, JsonSchema)]
pub struct PoolSlugAndHeightParam {
pub slug: PoolSlug,
pub height: Height,
}
@@ -0,0 +1,9 @@
use schemars::JsonSchema;
use serde::Deserialize;
use brk_types::SeriesName;
#[derive(Deserialize, JsonSchema)]
pub struct SeriesParam {
pub series: SeriesName,
}
@@ -0,0 +1,10 @@
use schemars::JsonSchema;
use serde::Deserialize;
use brk_types::TimePeriod;
#[derive(Deserialize, JsonSchema)]
pub struct TimePeriodParam {
#[schemars(example = &"24h")]
pub time_period: TimePeriod,
}
@@ -0,0 +1,14 @@
use schemars::JsonSchema;
use serde::Deserialize;
use brk_types::Timestamp;
#[derive(Deserialize, JsonSchema)]
pub struct TimestampParam {
pub timestamp: Timestamp,
}
#[derive(Deserialize, JsonSchema)]
pub struct OptionalTimestampParam {
pub timestamp: Option<Timestamp>,
}
@@ -0,0 +1,9 @@
use schemars::JsonSchema;
use serde::Deserialize;
use brk_types::Txid;
#[derive(Deserialize, JsonSchema)]
pub struct TxidParam {
pub txid: Txid,
}
+13
View File
@@ -0,0 +1,13 @@
use schemars::JsonSchema;
use serde::Deserialize;
use brk_types::{Txid, Vout};
/// Transaction output reference (txid + output index)
#[derive(Deserialize, JsonSchema)]
pub struct TxidVout {
/// Transaction ID
pub txid: Txid,
/// Output index
pub vout: Vout,
}
@@ -0,0 +1,31 @@
use std::str::FromStr;
use schemars::JsonSchema;
use brk_types::Txid;
/// Query parameter for transaction-times endpoint.
#[derive(JsonSchema)]
pub struct TxidsParam {
#[serde(rename = "txId[]")]
pub txids: Vec<Txid>,
}
impl TxidsParam {
/// Parsed manually from URI since serde_urlencoded doesn't support repeated keys.
pub fn from_query(query: &str) -> Self {
Self {
txids: query
.split('&')
.filter_map(|pair| {
let (key, val) = pair.split_once('=')?;
if key == "txId[]" || key == "txId%5B%5D" {
Txid::from_str(val).ok()
} else {
None
}
})
.collect(),
}
}
}
@@ -0,0 +1,15 @@
use schemars::JsonSchema;
use serde::Deserialize;
#[derive(Deserialize, JsonSchema)]
pub struct ValidateAddrParam {
/// Bitcoin address to validate (can be any string)
#[schemars(
example = &"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f",
example = &"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
example = &"not-a-valid-addr",
example = &"bc1qinvalid"
)]
#[serde(rename = "address")]
pub addr: String,
}