mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
types: docs
This commit is contained in:
@@ -199,7 +199,7 @@ impl BlockRoutes for ApiRouter<AppState> {
|
|||||||
"/api/blocks/tip/hash",
|
"/api/blocks/tip/hash",
|
||||||
get_with(
|
get_with(
|
||||||
async |uri: Uri, headers: HeaderMap, State(state): State<AppState>| {
|
async |uri: Uri, headers: HeaderMap, State(state): State<AppState>| {
|
||||||
state.cached_text(&headers, CacheStrategy::Tip, &uri, |q| q.block_hash_by_height(q.height()).map(|h| h.to_string())).await
|
state.cached_text(&headers, CacheStrategy::Tip, &uri, |q| Ok(q.tip_blockhash().to_string())).await
|
||||||
},
|
},
|
||||||
|op| {
|
|op| {
|
||||||
op.id("get_block_tip_hash")
|
op.id("get_block_tip_hash")
|
||||||
|
|||||||
@@ -9,8 +9,11 @@ use super::FeeRatePercentiles;
|
|||||||
#[derive(Debug, Serialize, JsonSchema)]
|
#[derive(Debug, Serialize, JsonSchema)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct BlockFeeRatesEntry {
|
pub struct BlockFeeRatesEntry {
|
||||||
|
/// Average block height in this window
|
||||||
pub avg_height: Height,
|
pub avg_height: Height,
|
||||||
|
/// Unix timestamp at the window midpoint
|
||||||
pub timestamp: Timestamp,
|
pub timestamp: Timestamp,
|
||||||
|
/// Fee rate percentiles (min, 10th, 25th, median, 75th, 90th, max)
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub percentiles: FeeRatePercentiles,
|
pub percentiles: FeeRatePercentiles,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,17 @@ use crate::{Dollars, Height, Sats, Timestamp};
|
|||||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct BlockFeesEntry {
|
pub struct BlockFeesEntry {
|
||||||
|
/// Average block height in this window
|
||||||
|
#[schemars(example = 890621)]
|
||||||
pub avg_height: Height,
|
pub avg_height: Height,
|
||||||
|
/// Unix timestamp at the window midpoint
|
||||||
|
#[schemars(example = 1743631892)]
|
||||||
pub timestamp: Timestamp,
|
pub timestamp: Timestamp,
|
||||||
|
/// Average fees per block in this window (sats)
|
||||||
|
#[schemars(example = 3215861)]
|
||||||
pub avg_fees: Sats,
|
pub avg_fees: Sats,
|
||||||
/// BTC/USD price at that height
|
/// BTC/USD price at this height
|
||||||
#[serde(rename = "USD")]
|
#[serde(rename = "USD")]
|
||||||
|
#[schemars(example = 84342.12)]
|
||||||
pub usd: Dollars,
|
pub usd: Dollars,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,17 @@ use crate::{Dollars, Height, Sats, Timestamp};
|
|||||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct BlockRewardsEntry {
|
pub struct BlockRewardsEntry {
|
||||||
|
/// Average block height in this window
|
||||||
|
#[schemars(example = 890621)]
|
||||||
pub avg_height: Height,
|
pub avg_height: Height,
|
||||||
|
/// Unix timestamp at the window midpoint
|
||||||
|
#[schemars(example = 1743631892)]
|
||||||
pub timestamp: Timestamp,
|
pub timestamp: Timestamp,
|
||||||
|
/// Average coinbase reward per block (subsidy + fees, sats)
|
||||||
|
#[schemars(example = 315715861)]
|
||||||
pub avg_rewards: Sats,
|
pub avg_rewards: Sats,
|
||||||
/// BTC/USD price at that height
|
/// BTC/USD price at this height
|
||||||
#[serde(rename = "USD")]
|
#[serde(rename = "USD")]
|
||||||
|
#[schemars(example = 84342.12)]
|
||||||
pub usd: Dollars,
|
pub usd: Dollars,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,13 @@ use crate::{Height, Timestamp};
|
|||||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct BlockSizeEntry {
|
pub struct BlockSizeEntry {
|
||||||
|
/// Average block height in this window
|
||||||
|
#[schemars(example = 890621)]
|
||||||
pub avg_height: Height,
|
pub avg_height: Height,
|
||||||
|
/// Unix timestamp at the window midpoint
|
||||||
|
#[schemars(example = 1743631892)]
|
||||||
pub timestamp: Timestamp,
|
pub timestamp: Timestamp,
|
||||||
|
/// Rolling 24h median block size (bytes)
|
||||||
|
#[schemars(example = 1580000)]
|
||||||
pub avg_size: u64,
|
pub avg_size: u64,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ use super::{BlockSizeEntry, BlockWeightEntry};
|
|||||||
/// Combined block sizes and weights response.
|
/// Combined block sizes and weights response.
|
||||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||||
pub struct BlockSizesWeights {
|
pub struct BlockSizesWeights {
|
||||||
|
/// Block size data points
|
||||||
pub sizes: Vec<BlockSizeEntry>,
|
pub sizes: Vec<BlockSizeEntry>,
|
||||||
|
/// Block weight data points
|
||||||
pub weights: Vec<BlockWeightEntry>,
|
pub weights: Vec<BlockWeightEntry>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,13 @@ use crate::{Height, Timestamp, Weight};
|
|||||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct BlockWeightEntry {
|
pub struct BlockWeightEntry {
|
||||||
|
/// Average block height in this window
|
||||||
|
#[schemars(example = 890621)]
|
||||||
pub avg_height: Height,
|
pub avg_height: Height,
|
||||||
|
/// Unix timestamp at the window midpoint
|
||||||
|
#[schemars(example = 1743631892)]
|
||||||
pub timestamp: Timestamp,
|
pub timestamp: Timestamp,
|
||||||
|
/// Rolling 24h median block weight (weight units)
|
||||||
|
#[schemars(example = 3990000)]
|
||||||
pub avg_weight: Weight,
|
pub avg_weight: Weight,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,13 @@ use crate::{Height, Timestamp};
|
|||||||
/// Serializes as array: [timestamp, height, difficulty, change_percent]
|
/// Serializes as array: [timestamp, height, difficulty, change_percent]
|
||||||
#[derive(Debug, Deserialize, JsonSchema)]
|
#[derive(Debug, Deserialize, JsonSchema)]
|
||||||
pub struct DifficultyAdjustmentEntry {
|
pub struct DifficultyAdjustmentEntry {
|
||||||
|
/// Unix timestamp of the adjustment
|
||||||
pub timestamp: Timestamp,
|
pub timestamp: Timestamp,
|
||||||
|
/// Block height of the adjustment
|
||||||
pub height: Height,
|
pub height: Height,
|
||||||
|
/// Difficulty value
|
||||||
pub difficulty: f64,
|
pub difficulty: f64,
|
||||||
|
/// Adjustment ratio (new/previous, e.g. 1.068 = +6.8%)
|
||||||
pub change_percent: f64,
|
pub change_percent: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,19 @@ use crate::SyncStatus;
|
|||||||
/// Server health status
|
/// Server health status
|
||||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||||
pub struct Health {
|
pub struct Health {
|
||||||
|
/// Health status ("healthy")
|
||||||
pub status: Cow<'static, str>,
|
pub status: Cow<'static, str>,
|
||||||
|
/// Service name
|
||||||
pub service: Cow<'static, str>,
|
pub service: Cow<'static, str>,
|
||||||
|
/// Server version
|
||||||
pub version: Cow<'static, str>,
|
pub version: Cow<'static, str>,
|
||||||
|
/// Current server time (ISO 8601)
|
||||||
pub timestamp: String,
|
pub timestamp: String,
|
||||||
/// Server start time (ISO 8601)
|
/// Server start time (ISO 8601)
|
||||||
pub started_at: String,
|
pub started_at: String,
|
||||||
/// Uptime in seconds
|
/// Uptime in seconds
|
||||||
pub uptime_seconds: u64,
|
pub uptime_seconds: u64,
|
||||||
|
/// Sync status
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub sync: SyncStatus,
|
pub sync: SyncStatus,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ use crate::{Dollars, Timestamp};
|
|||||||
/// Current price response matching mempool.space /api/v1/prices format
|
/// Current price response matching mempool.space /api/v1/prices format
|
||||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||||
pub struct Prices {
|
pub struct Prices {
|
||||||
|
/// Unix timestamp
|
||||||
pub time: Timestamp,
|
pub time: Timestamp,
|
||||||
|
/// BTC/USD price
|
||||||
#[serde(rename = "USD")]
|
#[serde(rename = "USD")]
|
||||||
pub usd: Dollars,
|
pub usd: Dollars,
|
||||||
}
|
}
|
||||||
@@ -14,7 +16,9 @@ pub struct Prices {
|
|||||||
/// Historical price response
|
/// Historical price response
|
||||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||||
pub struct HistoricalPrice {
|
pub struct HistoricalPrice {
|
||||||
|
/// Price data points
|
||||||
pub prices: Vec<HistoricalPriceEntry>,
|
pub prices: Vec<HistoricalPriceEntry>,
|
||||||
|
/// Exchange rates (currently empty)
|
||||||
#[serde(rename = "exchangeRates")]
|
#[serde(rename = "exchangeRates")]
|
||||||
pub exchange_rates: ExchangeRates,
|
pub exchange_rates: ExchangeRates,
|
||||||
}
|
}
|
||||||
@@ -22,7 +26,9 @@ pub struct HistoricalPrice {
|
|||||||
/// A single price data point
|
/// A single price data point
|
||||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||||
pub struct HistoricalPriceEntry {
|
pub struct HistoricalPriceEntry {
|
||||||
|
/// Unix timestamp
|
||||||
pub time: u64,
|
pub time: u64,
|
||||||
|
/// BTC/USD price
|
||||||
#[serde(rename = "USD")]
|
#[serde(rename = "USD")]
|
||||||
pub usd: Dollars,
|
pub usd: Dollars,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,16 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use crate::{Sats, Transaction, Txid, VSize};
|
use crate::{Sats, Transaction, Txid, VSize};
|
||||||
|
|
||||||
/// Simplified mempool transaction for the recent transactions endpoint
|
/// Simplified mempool transaction for the `/api/mempool/recent` endpoint.
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||||
pub struct MempoolRecentTx {
|
pub struct MempoolRecentTx {
|
||||||
|
/// Transaction ID
|
||||||
pub txid: Txid,
|
pub txid: Txid,
|
||||||
|
/// Transaction fee (sats)
|
||||||
pub fee: Sats,
|
pub fee: Sats,
|
||||||
|
/// Virtual size (vbytes)
|
||||||
pub vsize: VSize,
|
pub vsize: VSize,
|
||||||
|
/// Total output value (sats)
|
||||||
pub value: Sats,
|
pub value: Sats,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ use crate::Height;
|
|||||||
/// Merkle inclusion proof for a transaction
|
/// Merkle inclusion proof for a transaction
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||||
pub struct MerkleProof {
|
pub struct MerkleProof {
|
||||||
|
/// Block height containing the transaction
|
||||||
pub block_height: Height,
|
pub block_height: Height,
|
||||||
|
/// Merkle proof path (hex-encoded hashes)
|
||||||
pub merkle: Vec<String>,
|
pub merkle: Vec<String>,
|
||||||
|
/// Transaction position in the block
|
||||||
pub pos: usize,
|
pub pos: usize,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,13 @@ pub struct RewardStats {
|
|||||||
pub start_block: Height,
|
pub start_block: Height,
|
||||||
/// Last block in the range
|
/// Last block in the range
|
||||||
pub end_block: Height,
|
pub end_block: Height,
|
||||||
|
/// Total coinbase rewards (subsidy + fees) in sats
|
||||||
#[serde(serialize_with = "sats_as_string")]
|
#[serde(serialize_with = "sats_as_string")]
|
||||||
pub total_reward: Sats,
|
pub total_reward: Sats,
|
||||||
|
/// Total transaction fees in sats
|
||||||
#[serde(serialize_with = "sats_as_string")]
|
#[serde(serialize_with = "sats_as_string")]
|
||||||
pub total_fee: Sats,
|
pub total_fee: Sats,
|
||||||
|
/// Total number of transactions
|
||||||
#[serde(serialize_with = "u64_as_string")]
|
#[serde(serialize_with = "u64_as_string")]
|
||||||
pub total_tx: u64,
|
pub total_tx: u64,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,19 @@ use vecdb::CheckedSub;
|
|||||||
/// Transaction information compatible with mempool.space API format
|
/// Transaction information compatible with mempool.space API format
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||||
pub struct Transaction {
|
pub struct Transaction {
|
||||||
|
/// Internal transaction index (brk-specific, not in mempool.space)
|
||||||
#[schemars(example = TxIndex::new(0))]
|
#[schemars(example = TxIndex::new(0))]
|
||||||
pub index: Option<TxIndex>,
|
pub index: Option<TxIndex>,
|
||||||
|
|
||||||
|
/// Transaction ID
|
||||||
#[schemars(example = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b")]
|
#[schemars(example = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b")]
|
||||||
pub txid: Txid,
|
pub txid: Txid,
|
||||||
|
|
||||||
|
/// Transaction version
|
||||||
#[schemars(example = 2)]
|
#[schemars(example = 2)]
|
||||||
pub version: TxVersion,
|
pub version: TxVersion,
|
||||||
|
|
||||||
|
/// Transaction lock time
|
||||||
#[schemars(example = 0)]
|
#[schemars(example = 0)]
|
||||||
#[serde(rename = "locktime")]
|
#[serde(rename = "locktime")]
|
||||||
pub lock_time: RawLockTime,
|
pub lock_time: RawLockTime,
|
||||||
@@ -47,6 +51,7 @@ pub struct Transaction {
|
|||||||
#[schemars(example = Sats::new(31))]
|
#[schemars(example = Sats::new(31))]
|
||||||
pub fee: Sats,
|
pub fee: Sats,
|
||||||
|
|
||||||
|
/// Confirmation status (confirmed, block height/hash/time)
|
||||||
pub status: TxStatus,
|
pub status: TxStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,12 @@ use crate::{Sats, TxStatus, Txid, Vout};
|
|||||||
/// Unspent transaction output
|
/// Unspent transaction output
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||||
pub struct Utxo {
|
pub struct Utxo {
|
||||||
|
/// Transaction ID of the UTXO
|
||||||
pub txid: Txid,
|
pub txid: Txid,
|
||||||
|
/// Output index
|
||||||
pub vout: Vout,
|
pub vout: Vout,
|
||||||
|
/// Confirmation status
|
||||||
pub status: TxStatus,
|
pub status: TxStatus,
|
||||||
|
/// Output value in satoshis
|
||||||
pub value: Sats,
|
pub value: Sats,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user