mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-31 18:23:39 -07:00
global: snapshot
This commit is contained in:
@@ -13,6 +13,7 @@ full = [
|
||||
"bencher",
|
||||
"binder",
|
||||
"bundler",
|
||||
"client",
|
||||
"computer",
|
||||
"error",
|
||||
"fetcher",
|
||||
@@ -33,6 +34,7 @@ full = [
|
||||
bencher = ["brk_bencher"]
|
||||
binder = ["brk_binder"]
|
||||
bundler = ["brk_bundler"]
|
||||
client = ["brk_client"]
|
||||
computer = ["brk_computer"]
|
||||
error = ["brk_error"]
|
||||
fetcher = ["brk_fetcher"]
|
||||
@@ -54,6 +56,7 @@ types = ["brk_types"]
|
||||
brk_bencher = { workspace = true, optional = true }
|
||||
brk_binder = { workspace = true, optional = true }
|
||||
brk_bundler = { workspace = true, optional = true }
|
||||
brk_client = { workspace = true, optional = true }
|
||||
brk_computer = { workspace = true, optional = true }
|
||||
brk_error = { workspace = true, optional = true }
|
||||
brk_fetcher = { workspace = true, optional = true }
|
||||
|
||||
@@ -12,6 +12,10 @@ pub use brk_binder as binder;
|
||||
#[doc(inline)]
|
||||
pub use brk_bundler as bundler;
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
#[doc(inline)]
|
||||
pub use brk_client as client;
|
||||
|
||||
#[cfg(feature = "computer")]
|
||||
#[doc(inline)]
|
||||
pub use brk_computer as computer;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
lib.rs
|
||||
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "brk_client"
|
||||
description = "A BRK API client"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
brk_types = { workspace = true }
|
||||
minreq = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
@@ -0,0 +1 @@
|
||||
# brk_client
|
||||
@@ -0,0 +1,8 @@
|
||||
fn main() {
|
||||
let profile = std::env::var("PROFILE").unwrap_or_default();
|
||||
|
||||
if profile == "release" {
|
||||
println!("cargo:rustc-flag=-C");
|
||||
println!("cargo:rustc-flag=target-cpu=native");
|
||||
}
|
||||
}
|
||||
@@ -176,84 +176,84 @@ impl Computer {
|
||||
info!("Computed prices in {:?}", i.elapsed());
|
||||
}
|
||||
|
||||
// thread::scope(|scope| -> Result<()> {
|
||||
// let blks = scope.spawn(|| -> Result<()> {
|
||||
info!("Computing BLKs metadata...");
|
||||
let i = Instant::now();
|
||||
self.blks
|
||||
.compute(indexer, &starting_indexes, reader, exit)?;
|
||||
info!("Computed blk in {:?}", i.elapsed());
|
||||
// Ok(())
|
||||
// });
|
||||
thread::scope(|scope| -> Result<()> {
|
||||
let blks = scope.spawn(|| -> Result<()> {
|
||||
info!("Computing BLKs metadata...");
|
||||
let i = Instant::now();
|
||||
self.blks
|
||||
.compute(indexer, &starting_indexes, reader, exit)?;
|
||||
info!("Computed blk in {:?}", i.elapsed());
|
||||
Ok(())
|
||||
});
|
||||
|
||||
// let constants = scope.spawn(|| -> Result<()> {
|
||||
info!("Computing constants...");
|
||||
let i = Instant::now();
|
||||
self.constants
|
||||
.compute(&self.indexes, &starting_indexes, exit)?;
|
||||
info!("Computed constants in {:?}", i.elapsed());
|
||||
// Ok(())
|
||||
// });
|
||||
let constants = scope.spawn(|| -> Result<()> {
|
||||
info!("Computing constants...");
|
||||
let i = Instant::now();
|
||||
self.constants
|
||||
.compute(&self.indexes, &starting_indexes, exit)?;
|
||||
info!("Computed constants in {:?}", i.elapsed());
|
||||
Ok(())
|
||||
});
|
||||
|
||||
// let chain = scope.spawn(|| -> Result<()> {
|
||||
info!("Computing chain...");
|
||||
let i = Instant::now();
|
||||
self.chain.compute(
|
||||
indexer,
|
||||
&self.indexes,
|
||||
&starting_indexes,
|
||||
self.price.as_ref(),
|
||||
exit,
|
||||
)?;
|
||||
info!("Computed chain in {:?}", i.elapsed());
|
||||
// Ok(())
|
||||
// });
|
||||
let chain = scope.spawn(|| -> Result<()> {
|
||||
info!("Computing chain...");
|
||||
let i = Instant::now();
|
||||
self.chain.compute(
|
||||
indexer,
|
||||
&self.indexes,
|
||||
&starting_indexes,
|
||||
self.price.as_ref(),
|
||||
exit,
|
||||
)?;
|
||||
info!("Computed chain in {:?}", i.elapsed());
|
||||
Ok(())
|
||||
});
|
||||
|
||||
if let Some(price) = self.price.as_ref() {
|
||||
info!("Computing market...");
|
||||
let i = Instant::now();
|
||||
self.market.compute(price, &starting_indexes, exit)?;
|
||||
info!("Computed market in {:?}", i.elapsed());
|
||||
}
|
||||
if let Some(price) = self.price.as_ref() {
|
||||
info!("Computing market...");
|
||||
let i = Instant::now();
|
||||
self.market.compute(price, &starting_indexes, exit)?;
|
||||
info!("Computed market in {:?}", i.elapsed());
|
||||
}
|
||||
|
||||
// blks.join().unwrap()?;
|
||||
// constants.join().unwrap()?;
|
||||
// chain.join().unwrap()?;
|
||||
// Ok(())
|
||||
// })?;
|
||||
blks.join().unwrap()?;
|
||||
constants.join().unwrap()?;
|
||||
chain.join().unwrap()?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
let starting_indexes_clone = starting_indexes.clone();
|
||||
// thread::scope(|scope| -> Result<()> {
|
||||
// let pools = scope.spawn(|| -> Result<()> {
|
||||
info!("Computing pools...");
|
||||
let i = Instant::now();
|
||||
self.pools.compute(
|
||||
indexer,
|
||||
&self.indexes,
|
||||
&starting_indexes_clone,
|
||||
&self.chain,
|
||||
self.price.as_ref(),
|
||||
exit,
|
||||
)?;
|
||||
info!("Computed pools in {:?}", i.elapsed());
|
||||
// Ok(())
|
||||
// });
|
||||
thread::scope(|scope| -> Result<()> {
|
||||
let pools = scope.spawn(|| -> Result<()> {
|
||||
info!("Computing pools...");
|
||||
let i = Instant::now();
|
||||
self.pools.compute(
|
||||
indexer,
|
||||
&self.indexes,
|
||||
&starting_indexes_clone,
|
||||
&self.chain,
|
||||
self.price.as_ref(),
|
||||
exit,
|
||||
)?;
|
||||
info!("Computed pools in {:?}", i.elapsed());
|
||||
Ok(())
|
||||
});
|
||||
|
||||
info!("Computing stateful...");
|
||||
let i = Instant::now();
|
||||
self.stateful.compute(
|
||||
indexer,
|
||||
&self.indexes,
|
||||
&self.chain,
|
||||
self.price.as_ref(),
|
||||
&mut starting_indexes,
|
||||
exit,
|
||||
)?;
|
||||
info!("Computed stateful in {:?}", i.elapsed());
|
||||
info!("Computing stateful...");
|
||||
let i = Instant::now();
|
||||
self.stateful.compute(
|
||||
indexer,
|
||||
&self.indexes,
|
||||
&self.chain,
|
||||
self.price.as_ref(),
|
||||
&mut starting_indexes,
|
||||
exit,
|
||||
)?;
|
||||
info!("Computed stateful in {:?}", i.elapsed());
|
||||
|
||||
// pools.join().unwrap()?;
|
||||
// Ok(())
|
||||
// })?;
|
||||
pools.join().unwrap()?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
info!("Computing cointime...");
|
||||
let i = Instant::now();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use crate::{Sats, TypeIndex};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Address statistics on the blockchain (confirmed transactions only)
|
||||
///
|
||||
/// Based on mempool.space's format with type_index extension.
|
||||
#[derive(Debug, Default, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct AddressChainStats {
|
||||
/// Total number of transaction outputs that funded this address
|
||||
#[schemars(example = 5)]
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use crate::{Sats, TxOut};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
///
|
||||
/// Address statistics in the mempool (unconfirmed transactions only)
|
||||
///
|
||||
/// Based on mempool.space's format.
|
||||
///
|
||||
#[derive(Debug, Default, Clone, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct AddressMempoolStats {
|
||||
/// Number of unconfirmed transaction outputs funding this address
|
||||
#[schemars(example = 0)]
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::{Address, AddressChainStats, AddressMempoolStats};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Address information compatible with mempool.space API format
|
||||
#[derive(Debug, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct AddressStats {
|
||||
/// Bitcoin address string
|
||||
#[schemars(
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use bitcoin::hex::DisplayHex;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{AddressBytes, OutputType};
|
||||
|
||||
/// Address validation result
|
||||
#[derive(Debug, Clone, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct AddressValidation {
|
||||
/// Whether the address is valid
|
||||
pub isvalid: bool,
|
||||
|
||||
@@ -4,13 +4,13 @@ use std::{
|
||||
};
|
||||
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vecdb::{CheckedSub, Formattable, Pco};
|
||||
|
||||
use super::{Sats, StoredF64};
|
||||
|
||||
/// Bitcoin amount as floating point (1 BTC = 100,000,000 satoshis)
|
||||
#[derive(Debug, Default, Clone, Copy, Serialize, Pco, JsonSchema)]
|
||||
#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, Pco, JsonSchema)]
|
||||
pub struct Bitcoin(f64);
|
||||
|
||||
impl Add for Bitcoin {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{BlockHash, Height, Timestamp, Weight};
|
||||
|
||||
/// Block information returned by the API
|
||||
#[derive(Debug, Clone, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct BlockInfo {
|
||||
/// Block hash
|
||||
pub id: BlockHash,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{BlockHash, Height};
|
||||
|
||||
/// Block status indicating whether block is in the best chain
|
||||
#[derive(Debug, Clone, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct BlockStatus {
|
||||
/// Whether this block is in the best chain
|
||||
pub in_best_chain: bool,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::ser::SerializeTuple;
|
||||
use serde::{Serialize, Serializer};
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
|
||||
use crate::{Height, Timestamp};
|
||||
|
||||
/// A single difficulty adjustment entry.
|
||||
/// Serializes as array: [timestamp, height, difficulty, change_percent]
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(Debug, Deserialize, JsonSchema)]
|
||||
pub struct DifficultyAdjustmentEntry {
|
||||
pub timestamp: Timestamp,
|
||||
pub height: Height,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{Height, Timestamp};
|
||||
|
||||
/// A single difficulty data point.
|
||||
#[derive(Debug, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct DifficultyEntry {
|
||||
/// Unix timestamp of the difficulty adjustment.
|
||||
pub timestamp: Timestamp,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vecdb::{Bytes, Formattable};
|
||||
|
||||
use crate::{LoadedAddressData, Sats};
|
||||
|
||||
/// Data of an empty address
|
||||
#[derive(Debug, Default, Clone, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[repr(C)]
|
||||
pub struct EmptyAddressData {
|
||||
/// Total transaction count
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::Timestamp;
|
||||
|
||||
/// A single hashrate data point.
|
||||
#[derive(Debug, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct HashrateEntry {
|
||||
/// Unix timestamp.
|
||||
pub timestamp: Timestamp,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{DifficultyEntry, HashrateEntry};
|
||||
|
||||
/// Summary of network hashrate and difficulty data.
|
||||
#[derive(Debug, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct HashrateSummary {
|
||||
/// Historical hashrate data points.
|
||||
pub hashrates: Vec<HashrateEntry>,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Server health status
|
||||
#[derive(Debug, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct Health {
|
||||
pub status: &'static str,
|
||||
pub service: &'static str,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use brk_error::{Error, Result};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vecdb::{Bytes, CheckedSub, Formattable};
|
||||
|
||||
use crate::{Bitcoin, Dollars, EmptyAddressData, Sats};
|
||||
|
||||
/// Data for a loaded (non-empty) address with current balance
|
||||
#[derive(Debug, Default, Clone, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[repr(C)]
|
||||
pub struct LoadedAddressData {
|
||||
/// Total transaction count
|
||||
@@ -51,13 +51,15 @@ impl LoadedAddressData {
|
||||
|
||||
#[inline]
|
||||
pub fn utxo_count(&self) -> u32 {
|
||||
self.funded_txo_count.checked_sub(self.spent_txo_count).unwrap_or_else(|| {
|
||||
panic!(
|
||||
"LoadedAddressData corruption: spent_txo_count ({}) > funded_txo_count ({}). \
|
||||
self.funded_txo_count
|
||||
.checked_sub(self.spent_txo_count)
|
||||
.unwrap_or_else(|| {
|
||||
panic!(
|
||||
"LoadedAddressData corruption: spent_txo_count ({}) > funded_txo_count ({}). \
|
||||
Address data: {:?}",
|
||||
self.spent_txo_count, self.funded_txo_count, self
|
||||
)
|
||||
})
|
||||
self.spent_txo_count, self.funded_txo_count, self
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{Sats, Transaction, VSize};
|
||||
|
||||
/// Mempool statistics
|
||||
#[derive(Debug, Default, Clone, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct MempoolInfo {
|
||||
/// Number of transactions in the mempool
|
||||
pub count: usize,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Metric count statistics - distinct metrics and total metric-index combinations
|
||||
#[derive(Debug, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct MetricCount {
|
||||
/// Number of unique metrics available (e.g., realized_price, market_cap)
|
||||
#[schemars(example = 3141)]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::io::Write;
|
||||
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use vecdb::AnySerializableVec;
|
||||
|
||||
@@ -8,7 +9,7 @@ use vecdb::AnySerializableVec;
|
||||
///
|
||||
/// All metric data endpoints return this structure when format is JSON.
|
||||
/// This type is not instantiated - use `MetricData::serialize()` to write JSON bytes directly.
|
||||
#[derive(JsonSchema)]
|
||||
#[derive(JsonSchema, Deserialize)]
|
||||
pub struct MetricData {
|
||||
/// Total number of data points in the metric
|
||||
pub total: usize,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{Pool, PoolSlug};
|
||||
|
||||
@@ -62,7 +62,7 @@ impl From<&'static Pool> for PoolDetailInfo {
|
||||
}
|
||||
|
||||
/// Block counts for different time periods
|
||||
#[derive(Debug, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct PoolBlockCounts {
|
||||
/// Total blocks mined (all time)
|
||||
pub all: u32,
|
||||
@@ -77,7 +77,7 @@ pub struct PoolBlockCounts {
|
||||
}
|
||||
|
||||
/// Pool's share of total blocks for different time periods
|
||||
#[derive(Debug, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct PoolBlockShares {
|
||||
/// Share of all blocks (0.0 - 1.0)
|
||||
pub all: f64,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use bitcoin::{absolute::LockTime, locktime::absolute::LOCK_TIME_THRESHOLD};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vecdb::{Formattable, Pco};
|
||||
|
||||
/// Transaction locktime
|
||||
#[derive(Debug, Clone, Copy, Serialize, Pco, JsonSchema)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Pco, JsonSchema)]
|
||||
pub struct RawLockTime(u32);
|
||||
|
||||
impl From<LockTime> for RawLockTime {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{Height, Sats};
|
||||
|
||||
/// Block reward statistics over a range of blocks
|
||||
#[derive(Debug, Clone, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RewardStats {
|
||||
/// First block in the range
|
||||
|
||||
@@ -1,10 +1,24 @@
|
||||
use derive_deref::Deref;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vecdb::{Formattable, Pco, PrintableIndex};
|
||||
|
||||
/// Fixed-size boolean value optimized for on-disk storage (stored as u16)
|
||||
#[derive(Debug, Deref, Clone, Default, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Pco, JsonSchema)]
|
||||
#[derive(
|
||||
Debug,
|
||||
Deref,
|
||||
Clone,
|
||||
Default,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Pco,
|
||||
JsonSchema,
|
||||
)]
|
||||
pub struct StoredBool(u16);
|
||||
|
||||
impl StoredBool {
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::{
|
||||
|
||||
use derive_deref::Deref;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex};
|
||||
|
||||
use crate::{Close, StoredU32};
|
||||
@@ -16,7 +16,7 @@ use crate::{Close, StoredU32};
|
||||
use super::{Dollars, StoredF64};
|
||||
|
||||
/// Stored 32-bit floating point value
|
||||
#[derive(Debug, Deref, Default, Clone, Copy, Serialize, Pco, JsonSchema)]
|
||||
#[derive(Debug, Deref, Default, Clone, Copy, Serialize, Deserialize, Pco, JsonSchema)]
|
||||
pub struct StoredF32(f32);
|
||||
|
||||
impl StoredF32 {
|
||||
|
||||
@@ -7,13 +7,13 @@ use std::{
|
||||
|
||||
use derive_deref::Deref;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex};
|
||||
|
||||
use crate::{Bitcoin, Dollars};
|
||||
|
||||
/// Fixed-size 64-bit floating point value optimized for on-disk storage
|
||||
#[derive(Debug, Deref, Default, Clone, Copy, Serialize, Pco, JsonSchema)]
|
||||
#[derive(Debug, Deref, Default, Clone, Copy, Serialize, Deserialize, Pco, JsonSchema)]
|
||||
pub struct StoredF64(f64);
|
||||
|
||||
impl StoredF64 {
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::ops::{Add, AddAssign, Div, Mul};
|
||||
|
||||
use derive_deref::Deref;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex};
|
||||
|
||||
use super::{
|
||||
@@ -12,7 +12,21 @@ use super::{
|
||||
};
|
||||
|
||||
/// Fixed-size 32-bit unsigned integer optimized for on-disk storage
|
||||
#[derive(Debug, Deref, Clone, Default, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Pco, JsonSchema)]
|
||||
#[derive(
|
||||
Debug,
|
||||
Deref,
|
||||
Clone,
|
||||
Default,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Pco,
|
||||
JsonSchema,
|
||||
)]
|
||||
pub struct StoredU32(u32);
|
||||
|
||||
impl StoredU32 {
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::ops::{Add, AddAssign, Div};
|
||||
|
||||
use derive_deref::Deref;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex};
|
||||
|
||||
use super::{
|
||||
@@ -13,7 +13,21 @@ use super::{
|
||||
};
|
||||
|
||||
/// Fixed-size 64-bit unsigned integer optimized for on-disk storage
|
||||
#[derive(Debug, Default, Deref, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Pco, JsonSchema)]
|
||||
#[derive(
|
||||
Debug,
|
||||
Default,
|
||||
Deref,
|
||||
Clone,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Pco,
|
||||
JsonSchema,
|
||||
)]
|
||||
pub struct StoredU64(u64);
|
||||
|
||||
impl StoredU64 {
|
||||
|
||||
@@ -4,12 +4,12 @@ use std::{
|
||||
};
|
||||
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::Index;
|
||||
|
||||
/// Leaf node containing metric metadata
|
||||
#[derive(Debug, Clone, Serialize, PartialEq, Eq, JsonSchema)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||
pub struct MetricLeaf {
|
||||
/// The metric name/identifier
|
||||
pub name: String,
|
||||
@@ -35,7 +35,7 @@ impl MetricLeaf {
|
||||
}
|
||||
|
||||
/// MetricLeaf with JSON Schema for client generation
|
||||
#[derive(Debug, Clone, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct MetricLeafWithSchema {
|
||||
/// The core metric metadata
|
||||
#[serde(flatten)]
|
||||
@@ -85,7 +85,7 @@ impl PartialEq for MetricLeafWithSchema {
|
||||
impl Eq for MetricLeafWithSchema {}
|
||||
|
||||
/// Hierarchical tree node for organizing metrics into categories
|
||||
#[derive(Debug, Clone, Serialize, PartialEq, Eq, JsonSchema)]
|
||||
#[derive(Debug, Clone, Serialize, PartialEq, Eq, Deserialize, JsonSchema)]
|
||||
#[serde(untagged)]
|
||||
pub enum TreeNode {
|
||||
/// Branch node containing subcategories
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
use crate::{FeeRate, RawLockTime, Sats, TxIn, TxIndex, TxOut, TxStatus, TxVersion, Txid, VSize, Weight};
|
||||
use crate::{
|
||||
FeeRate, RawLockTime, Sats, TxIn, TxIndex, TxOut, TxStatus, TxVersion, Txid, VSize, Weight,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vecdb::CheckedSub;
|
||||
|
||||
/// Transaction information compatible with mempool.space API format
|
||||
#[derive(Debug, Clone, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct Transaction {
|
||||
#[schemars(example = TxIndex::new(0))]
|
||||
pub index: Option<TxIndex>,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::{TxOut, Txid, Vout};
|
||||
use bitcoin::{Script, ScriptBuf};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Serialize, Serializer, ser::SerializeStruct};
|
||||
use serde::{Deserialize, Serialize, Serializer, ser::SerializeStruct};
|
||||
|
||||
/// Transaction input
|
||||
#[derive(Debug, Clone, JsonSchema)]
|
||||
#[derive(Debug, Clone, Deserialize, JsonSchema)]
|
||||
pub struct TxIn {
|
||||
/// Transaction ID of the output being spent
|
||||
#[schemars(example = "0000000000000000000000000000000000000000000000000000000000000000")]
|
||||
|
||||
@@ -2,13 +2,26 @@ use std::ops::{Add, AddAssign};
|
||||
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex};
|
||||
|
||||
use super::Vin;
|
||||
|
||||
#[derive(
|
||||
Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Default, Serialize, Pco, JsonSchema,
|
||||
Debug,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Clone,
|
||||
Copy,
|
||||
Deref,
|
||||
DerefMut,
|
||||
Default,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Pco,
|
||||
JsonSchema,
|
||||
)]
|
||||
pub struct TxInIndex(u64);
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::{Address, AddressBytes, OutputType, Sats};
|
||||
use bitcoin::ScriptBuf;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Serialize, Serializer, ser::SerializeStruct};
|
||||
use serde::{Deserialize, Serialize, Serializer, ser::SerializeStruct};
|
||||
|
||||
/// Transaction output
|
||||
#[derive(Debug, Clone, JsonSchema)]
|
||||
#[derive(Debug, Clone, Deserialize, JsonSchema)]
|
||||
pub struct TxOut {
|
||||
/// Script pubkey (locking script)
|
||||
#[serde(
|
||||
|
||||
@@ -2,13 +2,26 @@ use std::ops::{Add, AddAssign};
|
||||
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex};
|
||||
|
||||
use super::Vout;
|
||||
|
||||
#[derive(
|
||||
Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Default, Serialize, Pco, JsonSchema,
|
||||
Debug,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Clone,
|
||||
Copy,
|
||||
Deref,
|
||||
DerefMut,
|
||||
Default,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Pco,
|
||||
JsonSchema,
|
||||
)]
|
||||
pub struct TxOutIndex(u64);
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{BlockHash, Height, Timestamp};
|
||||
|
||||
/// Transaction confirmation status
|
||||
#[derive(Debug, Clone, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct TxStatus {
|
||||
/// Whether the transaction is confirmed
|
||||
#[schemars(example = true)]
|
||||
|
||||
@@ -1,12 +1,25 @@
|
||||
use derive_deref::Deref;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vecdb::{Formattable, Pco};
|
||||
|
||||
use super::StoredU16;
|
||||
|
||||
/// Transaction version number
|
||||
#[derive(Debug, Deref, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Pco, JsonSchema)]
|
||||
#[derive(
|
||||
Debug,
|
||||
Deref,
|
||||
Clone,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Pco,
|
||||
JsonSchema,
|
||||
)]
|
||||
pub struct TxVersion(u16);
|
||||
|
||||
impl TxVersion {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{Sats, TxStatus, Txid, Vout};
|
||||
|
||||
/// Unspent transaction output
|
||||
#[derive(Debug, Clone, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct Utxo {
|
||||
pub txid: Txid,
|
||||
pub vout: Vout,
|
||||
|
||||
@@ -2,13 +2,27 @@ use std::ops::{Add, AddAssign, Div, Sub, SubAssign};
|
||||
|
||||
use derive_deref::Deref;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vecdb::{Formattable, Pco};
|
||||
|
||||
use crate::Weight;
|
||||
|
||||
/// Virtual size in vbytes (weight / 4, rounded up)
|
||||
#[derive(Debug, Default, Deref, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Pco, JsonSchema)]
|
||||
#[derive(
|
||||
Debug,
|
||||
Default,
|
||||
Deref,
|
||||
Clone,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Pco,
|
||||
JsonSchema,
|
||||
)]
|
||||
pub struct VSize(u64);
|
||||
|
||||
impl VSize {
|
||||
@@ -49,7 +63,10 @@ impl From<usize> for VSize {
|
||||
impl From<f64> for VSize {
|
||||
#[inline]
|
||||
fn from(value: f64) -> Self {
|
||||
debug_assert!(value >= 0.0 && value.fract() == 0.0, "VSize must be a non-negative integer");
|
||||
debug_assert!(
|
||||
value >= 0.0 && value.fract() == 0.0,
|
||||
"VSize must be a non-negative integer"
|
||||
);
|
||||
Self(value as u64)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,24 @@ use std::ops::{Add, AddAssign, Div};
|
||||
|
||||
use derive_deref::Deref;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vecdb::{Formattable, Pco};
|
||||
|
||||
/// Transaction or block weight in weight units (WU)
|
||||
#[derive(Debug, Deref, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Pco, JsonSchema)]
|
||||
#[derive(
|
||||
Debug,
|
||||
Deref,
|
||||
Clone,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Pco,
|
||||
JsonSchema,
|
||||
)]
|
||||
pub struct Weight(u64);
|
||||
|
||||
impl Weight {
|
||||
|
||||
Reference in New Issue
Block a user