mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
server: moved params from brk_types
This commit is contained in:
@@ -3,7 +3,7 @@ use std::cmp::Ordering;
|
||||
use brk_error::{Error, Result};
|
||||
use brk_types::{
|
||||
CpfpEntry, CpfpInfo, FeeRate, MempoolBlock, MempoolInfo, MempoolRecentTx, RecommendedFees,
|
||||
Txid, TxidParam, TxidPrefix, Weight,
|
||||
Txid, TxidPrefix, Weight,
|
||||
};
|
||||
|
||||
use crate::Query;
|
||||
@@ -51,10 +51,10 @@ impl Query {
|
||||
Ok(mempool.get_txs().recent().to_vec())
|
||||
}
|
||||
|
||||
pub fn cpfp(&self, TxidParam { txid }: TxidParam) -> Result<CpfpInfo> {
|
||||
pub fn cpfp(&self, txid: &Txid) -> Result<CpfpInfo> {
|
||||
let mempool = self.mempool().ok_or(Error::MempoolNotAvailable)?;
|
||||
let entries = mempool.get_entries();
|
||||
let prefix = TxidPrefix::from(&txid);
|
||||
let prefix = TxidPrefix::from(txid);
|
||||
|
||||
let entry = entries
|
||||
.get(&prefix)
|
||||
|
||||
@@ -2,23 +2,23 @@ use bitcoin::hex::DisplayHex;
|
||||
use brk_error::{Error, Result};
|
||||
use brk_types::{
|
||||
BlockHash, Height, MerkleProof, Timestamp, TxInIndex, TxIndex, TxOutspend, TxStatus,
|
||||
Transaction, Txid, TxidParam, TxidPrefix, Vin, Vout,
|
||||
Transaction, Txid, TxidPrefix, Vin, Vout,
|
||||
};
|
||||
use vecdb::{ReadableVec, VecIndex};
|
||||
|
||||
use crate::Query;
|
||||
|
||||
impl Query {
|
||||
pub fn transaction(&self, TxidParam { txid }: TxidParam) -> Result<Transaction> {
|
||||
pub fn transaction(&self, txid: &Txid) -> Result<Transaction> {
|
||||
// First check mempool for unconfirmed transactions
|
||||
if let Some(mempool) = self.mempool()
|
||||
&& let Some(tx_with_hex) = mempool.get_txs().get(&txid)
|
||||
&& let Some(tx_with_hex) = mempool.get_txs().get(txid)
|
||||
{
|
||||
return Ok(tx_with_hex.tx().clone());
|
||||
}
|
||||
|
||||
// Look up confirmed transaction by txid prefix
|
||||
let prefix = TxidPrefix::from(&txid);
|
||||
let prefix = TxidPrefix::from(txid);
|
||||
let indexer = self.indexer();
|
||||
let Ok(Some(tx_index)) = indexer
|
||||
.stores
|
||||
@@ -32,16 +32,16 @@ impl Query {
|
||||
self.transaction_by_index(tx_index)
|
||||
}
|
||||
|
||||
pub fn transaction_status(&self, TxidParam { txid }: TxidParam) -> Result<TxStatus> {
|
||||
pub fn transaction_status(&self, txid: &Txid) -> Result<TxStatus> {
|
||||
// First check mempool for unconfirmed transactions
|
||||
if let Some(mempool) = self.mempool()
|
||||
&& mempool.get_txs().contains_key(&txid)
|
||||
&& mempool.get_txs().contains_key(txid)
|
||||
{
|
||||
return Ok(TxStatus::UNCONFIRMED);
|
||||
}
|
||||
|
||||
// Look up confirmed transaction by txid prefix
|
||||
let prefix = TxidPrefix::from(&txid);
|
||||
let prefix = TxidPrefix::from(txid);
|
||||
let indexer = self.indexer();
|
||||
let Ok(Some(tx_index)) = indexer
|
||||
.stores
|
||||
@@ -70,8 +70,8 @@ impl Query {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn transaction_raw(&self, TxidParam { txid }: TxidParam) -> Result<Vec<u8>> {
|
||||
let prefix = TxidPrefix::from(&txid);
|
||||
pub fn transaction_raw(&self, txid: &Txid) -> Result<Vec<u8>> {
|
||||
let prefix = TxidPrefix::from(txid);
|
||||
let indexer = self.indexer();
|
||||
let Ok(Some(tx_index)) = indexer
|
||||
.stores
|
||||
@@ -84,16 +84,16 @@ impl Query {
|
||||
self.transaction_raw_by_index(tx_index)
|
||||
}
|
||||
|
||||
pub fn transaction_hex(&self, TxidParam { txid }: TxidParam) -> Result<String> {
|
||||
pub fn transaction_hex(&self, txid: &Txid) -> Result<String> {
|
||||
// First check mempool for unconfirmed transactions
|
||||
if let Some(mempool) = self.mempool()
|
||||
&& let Some(tx_with_hex) = mempool.get_txs().get(&txid)
|
||||
&& let Some(tx_with_hex) = mempool.get_txs().get(txid)
|
||||
{
|
||||
return Ok(tx_with_hex.hex().to_string());
|
||||
}
|
||||
|
||||
// Look up confirmed transaction by txid prefix
|
||||
let prefix = TxidPrefix::from(&txid);
|
||||
let prefix = TxidPrefix::from(txid);
|
||||
let indexer = self.indexer();
|
||||
let Ok(Some(tx_index)) = indexer
|
||||
.stores
|
||||
@@ -107,24 +107,24 @@ impl Query {
|
||||
self.transaction_hex_by_index(tx_index)
|
||||
}
|
||||
|
||||
pub fn outspend(&self, txid: TxidParam, vout: Vout) -> Result<TxOutspend> {
|
||||
pub fn outspend(&self, txid: &Txid, vout: Vout) -> Result<TxOutspend> {
|
||||
let all = self.outspends(txid)?;
|
||||
all.into_iter()
|
||||
.nth(usize::from(vout))
|
||||
.ok_or(Error::OutOfRange("Output index out of range".into()))
|
||||
}
|
||||
|
||||
pub fn outspends(&self, TxidParam { txid }: TxidParam) -> Result<Vec<TxOutspend>> {
|
||||
pub fn outspends(&self, txid: &Txid) -> Result<Vec<TxOutspend>> {
|
||||
// Mempool outputs are unspent in on-chain terms
|
||||
if let Some(mempool) = self.mempool()
|
||||
&& let Some(tx_with_hex) = mempool.get_txs().get(&txid)
|
||||
&& let Some(tx_with_hex) = mempool.get_txs().get(txid)
|
||||
{
|
||||
let output_count = tx_with_hex.tx().output.len();
|
||||
return Ok(vec![TxOutspend::UNSPENT; output_count]);
|
||||
}
|
||||
|
||||
// Look up confirmed transaction
|
||||
let prefix = TxidPrefix::from(&txid);
|
||||
let prefix = TxidPrefix::from(txid);
|
||||
let indexer = self.indexer();
|
||||
let Ok(Some(tx_index)) = indexer
|
||||
.stores
|
||||
@@ -248,12 +248,12 @@ impl Query {
|
||||
self.client().send_raw_transaction(hex)
|
||||
}
|
||||
|
||||
pub fn merkleblock_proof(&self, txid_param: TxidParam) -> Result<String> {
|
||||
let (_, height) = self.resolve_tx(&txid_param.txid)?;
|
||||
pub fn merkleblock_proof(&self, txid: &Txid) -> Result<String> {
|
||||
let (_, height) = self.resolve_tx(txid)?;
|
||||
let header = self.read_block_header(height)?;
|
||||
let txids = self.block_txids_by_height(height)?;
|
||||
|
||||
let target: bitcoin::Txid = (&txid_param.txid).into();
|
||||
let target: bitcoin::Txid = txid.into();
|
||||
let btxids: Vec<bitcoin::Txid> = txids.iter().map(bitcoin::Txid::from).collect();
|
||||
let mb = bitcoin::MerkleBlock::from_header_txids_with_predicate(&header, &btxids, |t| {
|
||||
*t == target
|
||||
@@ -261,8 +261,8 @@ impl Query {
|
||||
Ok(bitcoin::consensus::encode::serialize_hex(&mb))
|
||||
}
|
||||
|
||||
pub fn merkle_proof(&self, txid_param: TxidParam) -> Result<MerkleProof> {
|
||||
let (tx_index, height) = self.resolve_tx(&txid_param.txid)?;
|
||||
pub fn merkle_proof(&self, txid: &Txid) -> Result<MerkleProof> {
|
||||
let (tx_index, height) = self.resolve_tx(txid)?;
|
||||
let first_tx = self
|
||||
.indexer()
|
||||
.vecs
|
||||
|
||||
@@ -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, ¶m.txid), &uri, move |q| q.cpfp(param)).await
|
||||
state.cached_json(&headers, state.tx_cache(Version::ONE, ¶m.txid), &uri, move |q| q.cpfp(¶m.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, ¶m.txid), &uri, move |q| q.transaction(param)).await
|
||||
state.cached_json(&headers, state.tx_cache(Version::ONE, ¶m.txid), &uri, move |q| q.transaction(¶m.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, ¶m.txid), &uri, move |q| q.transaction_hex(¶m.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, ¶m.txid), &uri, move |q| q.merkleblock_proof(¶m.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, ¶m.txid), &uri, move |q| q.merkle_proof(¶m.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(¶m.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, ¶m.txid), &uri, move |q| q.transaction_raw(¶m.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, ¶m.txid), &uri, move |q| q.transaction_status(param)).await
|
||||
state.cached_json(&headers, state.tx_cache(Version::ONE, ¶m.txid), &uri, move |q| q.transaction_status(¶m.txid)).await
|
||||
},
|
||||
|op| op
|
||||
.id("get_tx_status")
|
||||
|
||||
@@ -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};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ mod api;
|
||||
pub mod cache;
|
||||
mod error;
|
||||
mod extended;
|
||||
pub mod params;
|
||||
mod state;
|
||||
|
||||
pub use api::ApiRoutes;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::Addr;
|
||||
use brk_types::Addr;
|
||||
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
pub struct AddrParam {
|
||||
@@ -1,7 +1,7 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::Txid;
|
||||
use brk_types::Txid;
|
||||
|
||||
#[derive(Debug, Default, Deserialize, JsonSchema)]
|
||||
pub struct AddrTxidsParam {
|
||||
@@ -1,7 +1,7 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::BlockHash;
|
||||
use brk_types::BlockHash;
|
||||
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
pub struct BlockHashParam {
|
||||
@@ -1,7 +1,7 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{BlockHash, TxIndex};
|
||||
use brk_types::{BlockHash, TxIndex};
|
||||
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
pub struct BlockHashStartIndex {
|
||||
@@ -1,7 +1,7 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{BlockHash, TxIndex};
|
||||
use brk_types::{BlockHash, TxIndex};
|
||||
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
pub struct BlockHashTxIndex {
|
||||
@@ -1,33 +1,7 @@
|
||||
use std::{fmt, ops::Deref};
|
||||
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{CostBasisBucket, CostBasisValue, Date};
|
||||
|
||||
/// Cohort identifier for cost basis distribution.
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
#[schemars(example = &"all", example = &"sth", example = &"lth")]
|
||||
pub struct Cohort(String);
|
||||
|
||||
impl fmt::Display for Cohort {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Into<String>> From<T> for Cohort {
|
||||
fn from(s: T) -> Self {
|
||||
Self(s.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Cohort {
|
||||
type Target = str;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
use brk_types::{Cohort, CostBasisBucket, CostBasisValue, Date};
|
||||
|
||||
/// Path parameters for cost basis distribution endpoint.
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
@@ -1,7 +1,7 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::Height;
|
||||
use brk_types::Height;
|
||||
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
pub struct HeightParam {
|
||||
@@ -1,7 +1,7 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::Limit;
|
||||
use brk_types::Limit;
|
||||
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
pub struct LimitParam {
|
||||
35
crates/brk_server/src/params/mod.rs
Normal file
35
crates/brk_server/src/params/mod.rs
Normal 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::*;
|
||||
@@ -1,7 +1,7 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
||||
use super::{Height, PoolSlug};
|
||||
use brk_types::{Height, PoolSlug};
|
||||
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
pub struct PoolSlugParam {
|
||||
@@ -1,7 +1,7 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::SeriesName;
|
||||
use brk_types::SeriesName;
|
||||
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
pub struct SeriesParam {
|
||||
@@ -1,7 +1,7 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
||||
use super::TimePeriod;
|
||||
use brk_types::TimePeriod;
|
||||
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
pub struct TimePeriodParam {
|
||||
@@ -1,7 +1,7 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::Timestamp;
|
||||
use brk_types::Timestamp;
|
||||
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
pub struct TimestampParam {
|
||||
@@ -1,7 +1,7 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::Txid;
|
||||
use brk_types::Txid;
|
||||
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
pub struct TxidParam {
|
||||
@@ -1,7 +1,7 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{Txid, Vout};
|
||||
use brk_types::{Txid, Vout};
|
||||
|
||||
/// Transaction output reference (txid + output index)
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
@@ -2,7 +2,7 @@ use std::str::FromStr;
|
||||
|
||||
use schemars::JsonSchema;
|
||||
|
||||
use crate::Txid;
|
||||
use brk_types::Txid;
|
||||
|
||||
/// Query parameter for transaction-times endpoint.
|
||||
#[derive(JsonSchema)]
|
||||
28
crates/brk_types/src/cohort.rs
Normal file
28
crates/brk_types/src/cohort.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use std::{fmt, ops::Deref};
|
||||
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
|
||||
/// Cohort identifier for cost basis distribution.
|
||||
#[derive(Deserialize, JsonSchema)]
|
||||
#[schemars(example = &"all", example = &"sth", example = &"lth")]
|
||||
pub struct Cohort(String);
|
||||
|
||||
impl fmt::Display for Cohort {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Into<String>> From<T> for Cohort {
|
||||
fn from(s: T) -> Self {
|
||||
Self(s.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Cohort {
|
||||
type Target = str;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,7 @@ mod addr_index_any;
|
||||
mod addr_index_outpoint;
|
||||
mod addr_index_tx_index;
|
||||
mod addr_mempool_stats;
|
||||
mod addr_param;
|
||||
mod addr_stats;
|
||||
mod addr_txids_param;
|
||||
mod addr_validation;
|
||||
mod age;
|
||||
mod basis_points_16;
|
||||
@@ -23,7 +21,6 @@ mod bitcoin;
|
||||
mod blk_metadata;
|
||||
mod blk_position;
|
||||
mod block;
|
||||
mod block_count_param;
|
||||
mod block_extras;
|
||||
mod block_fee_rates_entry;
|
||||
mod block_fees_entry;
|
||||
@@ -38,21 +35,18 @@ mod block_status;
|
||||
mod block_timestamp;
|
||||
mod block_weight_entry;
|
||||
mod blockhash;
|
||||
mod blockhash_param;
|
||||
mod blockhash_prefix;
|
||||
mod blockhash_start_index;
|
||||
mod blockhash_tx_index;
|
||||
mod bytes;
|
||||
mod cents;
|
||||
mod cents_compact;
|
||||
mod cents_sats;
|
||||
mod cents_signed;
|
||||
mod cents_squared_sats;
|
||||
mod cohort;
|
||||
mod coinbase_tag;
|
||||
mod cpfp;
|
||||
mod cost_basis_bucket;
|
||||
mod cost_basis_distribution;
|
||||
mod cost_basis_params;
|
||||
mod cost_basis_value;
|
||||
mod data_range;
|
||||
mod data_range_format;
|
||||
@@ -83,7 +77,6 @@ mod hashrate_summary;
|
||||
mod health;
|
||||
mod height;
|
||||
mod historical_price;
|
||||
mod height_param;
|
||||
mod hex;
|
||||
mod hour1;
|
||||
mod hour12;
|
||||
@@ -92,7 +85,6 @@ mod index;
|
||||
mod index_info;
|
||||
mod indexes;
|
||||
mod limit;
|
||||
mod limit_param;
|
||||
mod mempool_block;
|
||||
mod mempool_entry_info;
|
||||
mod mempool_info;
|
||||
@@ -135,7 +127,6 @@ mod pool_detail;
|
||||
mod pool_info;
|
||||
mod pool_hashrate_entry;
|
||||
mod pool_slug;
|
||||
mod pool_slug_param;
|
||||
mod pool_stats;
|
||||
mod pools;
|
||||
mod pools_summary;
|
||||
@@ -157,7 +148,6 @@ mod series_name;
|
||||
mod series_name_with_index;
|
||||
mod series_output;
|
||||
mod series_paginated;
|
||||
mod series_param;
|
||||
mod series_selection;
|
||||
mod series_selection_legacy;
|
||||
mod stored_bool;
|
||||
@@ -175,9 +165,7 @@ mod supply_state;
|
||||
mod sync_status;
|
||||
mod term;
|
||||
mod time_period;
|
||||
mod time_period_param;
|
||||
mod timestamp;
|
||||
mod timestamp_param;
|
||||
mod tree_node;
|
||||
mod tx;
|
||||
mod tx_index;
|
||||
@@ -185,10 +173,7 @@ mod tx_status;
|
||||
mod tx_version;
|
||||
mod tx_with_hex;
|
||||
mod txid;
|
||||
mod txid_param;
|
||||
mod txid_prefix;
|
||||
mod txids_param;
|
||||
mod txid_vout;
|
||||
mod txin;
|
||||
mod txin_index;
|
||||
mod txout;
|
||||
@@ -198,7 +183,6 @@ mod type_index;
|
||||
mod unit;
|
||||
mod unknown_output_index;
|
||||
mod utxo;
|
||||
mod validate_addr_param;
|
||||
mod vin;
|
||||
mod vout;
|
||||
mod vsize;
|
||||
@@ -216,9 +200,7 @@ pub use addr_index_any::*;
|
||||
pub use addr_index_outpoint::*;
|
||||
pub use addr_index_tx_index::*;
|
||||
pub use addr_mempool_stats::*;
|
||||
pub use addr_param::*;
|
||||
pub use addr_stats::*;
|
||||
pub use addr_txids_param::*;
|
||||
pub use addr_validation::*;
|
||||
pub use age::*;
|
||||
pub use basis_points_16::*;
|
||||
@@ -229,7 +211,6 @@ pub use bitcoin::*;
|
||||
pub use blk_metadata::*;
|
||||
pub use blk_position::*;
|
||||
pub use block::*;
|
||||
pub use block_count_param::*;
|
||||
pub use block_extras::*;
|
||||
pub use block_fee_rates_entry::*;
|
||||
pub use block_fees_entry::*;
|
||||
@@ -244,21 +225,18 @@ pub use block_status::*;
|
||||
pub use block_timestamp::*;
|
||||
pub use block_weight_entry::*;
|
||||
pub use blockhash::*;
|
||||
pub use blockhash_param::*;
|
||||
pub use blockhash_prefix::*;
|
||||
pub use blockhash_start_index::*;
|
||||
pub use blockhash_tx_index::*;
|
||||
pub use bytes::*;
|
||||
pub use cents::*;
|
||||
pub use cents_compact::*;
|
||||
pub use cents_sats::*;
|
||||
pub use cents_signed::*;
|
||||
pub use cents_squared_sats::*;
|
||||
pub use cohort::*;
|
||||
pub use coinbase_tag::*;
|
||||
pub use cpfp::*;
|
||||
pub use cost_basis_bucket::*;
|
||||
pub use cost_basis_distribution::*;
|
||||
pub use cost_basis_params::*;
|
||||
pub use cost_basis_value::*;
|
||||
pub use data_range::*;
|
||||
pub use data_range_format::*;
|
||||
@@ -289,7 +267,6 @@ pub use hashrate_summary::*;
|
||||
pub use health::*;
|
||||
pub use height::*;
|
||||
pub use historical_price::*;
|
||||
pub use height_param::*;
|
||||
pub use hex::*;
|
||||
pub use hour1::*;
|
||||
pub use hour4::*;
|
||||
@@ -298,7 +275,6 @@ pub use index::*;
|
||||
pub use index_info::*;
|
||||
pub use indexes::*;
|
||||
pub use limit::*;
|
||||
pub use limit_param::*;
|
||||
pub use mempool_block::*;
|
||||
pub use mempool_entry_info::*;
|
||||
pub use mempool_info::*;
|
||||
@@ -341,7 +317,6 @@ pub use pool_detail::*;
|
||||
pub use pool_info::*;
|
||||
pub use pool_hashrate_entry::*;
|
||||
pub use pool_slug::*;
|
||||
pub use pool_slug_param::*;
|
||||
pub use pool_stats::*;
|
||||
pub use pools::*;
|
||||
pub use pools_summary::*;
|
||||
@@ -363,7 +338,6 @@ pub use series_name::*;
|
||||
pub use series_name_with_index::*;
|
||||
pub use series_output::*;
|
||||
pub use series_paginated::*;
|
||||
pub use series_param::*;
|
||||
pub use series_selection::*;
|
||||
pub use series_selection_legacy::*;
|
||||
pub use stored_bool::*;
|
||||
@@ -381,9 +355,7 @@ pub use supply_state::*;
|
||||
pub use sync_status::*;
|
||||
pub use term::*;
|
||||
pub use time_period::*;
|
||||
pub use time_period_param::*;
|
||||
pub use timestamp::*;
|
||||
pub use timestamp_param::*;
|
||||
pub use tree_node::*;
|
||||
pub use tx::*;
|
||||
pub use tx_index::*;
|
||||
@@ -391,10 +363,7 @@ pub use tx_status::*;
|
||||
pub use tx_version::*;
|
||||
pub use tx_with_hex::*;
|
||||
pub use txid::*;
|
||||
pub use txid_param::*;
|
||||
pub use txid_prefix::*;
|
||||
pub use txids_param::*;
|
||||
pub use txid_vout::*;
|
||||
pub use txin::*;
|
||||
pub use txin_index::*;
|
||||
pub use txout::*;
|
||||
@@ -404,7 +373,6 @@ pub use type_index::*;
|
||||
pub use unit::*;
|
||||
pub use unknown_output_index::*;
|
||||
pub use utxo::*;
|
||||
pub use validate_addr_param::*;
|
||||
pub use vin::*;
|
||||
pub use vout::*;
|
||||
pub use vsize::*;
|
||||
|
||||
Reference in New Issue
Block a user