diff --git a/crates/brk_client/src/lib.rs b/crates/brk_client/src/lib.rs index 741fe8a46..d982ec70a 100644 --- a/crates/brk_client/src/lib.rs +++ b/crates/brk_client/src/lib.rs @@ -3147,8 +3147,7 @@ impl MetricsTree_Blocks { /// Metrics tree node. pub struct MetricsTree_Blocks_Difficulty { - pub raw: MetricPattern18, - pub base: MetricPattern2, + pub value: MetricPattern1, pub as_hash: MetricPattern1, pub adjustment: BpsPercentRatioPattern, pub epoch: MetricPattern1, @@ -3159,8 +3158,7 @@ pub struct MetricsTree_Blocks_Difficulty { impl MetricsTree_Blocks_Difficulty { pub fn new(client: Arc, base_path: String) -> Self { Self { - raw: MetricPattern18::new(client.clone(), "difficulty".to_string()), - base: MetricPattern2::new(client.clone(), "difficulty".to_string()), + value: MetricPattern1::new(client.clone(), "difficulty".to_string()), as_hash: MetricPattern1::new(client.clone(), "difficulty_as_hash".to_string()), adjustment: BpsPercentRatioPattern::new(client.clone(), "difficulty_adjustment".to_string()), epoch: MetricPattern1::new(client.clone(), "difficulty_epoch".to_string()), @@ -3990,7 +3988,7 @@ impl MetricsTree_Scripts { /// Metrics tree node. pub struct MetricsTree_Scripts_Raw { pub empty: MetricsTree_Scripts_Raw_Empty, - pub opreturn: MetricsTree_Scripts_Raw_Opreturn, + pub op_return: MetricsTree_Scripts_Raw_OpReturn, pub p2ms: MetricsTree_Scripts_Raw_P2ms, pub unknown: MetricsTree_Scripts_Raw_Unknown, } @@ -3999,7 +3997,7 @@ impl MetricsTree_Scripts_Raw { pub fn new(client: Arc, base_path: String) -> Self { Self { empty: MetricsTree_Scripts_Raw_Empty::new(client.clone(), format!("{base_path}_empty")), - opreturn: MetricsTree_Scripts_Raw_Opreturn::new(client.clone(), format!("{base_path}_opreturn")), + op_return: MetricsTree_Scripts_Raw_OpReturn::new(client.clone(), format!("{base_path}_op_return")), p2ms: MetricsTree_Scripts_Raw_P2ms::new(client.clone(), format!("{base_path}_p2ms")), unknown: MetricsTree_Scripts_Raw_Unknown::new(client.clone(), format!("{base_path}_unknown")), } @@ -4022,12 +4020,12 @@ impl MetricsTree_Scripts_Raw_Empty { } /// Metrics tree node. -pub struct MetricsTree_Scripts_Raw_Opreturn { +pub struct MetricsTree_Scripts_Raw_OpReturn { pub first_index: MetricPattern18, pub to_tx_index: MetricPattern23, } -impl MetricsTree_Scripts_Raw_Opreturn { +impl MetricsTree_Scripts_Raw_OpReturn { pub fn new(client: Arc, base_path: String) -> Self { Self { first_index: MetricPattern18::new(client.clone(), "first_op_return_index".to_string()), @@ -4077,7 +4075,7 @@ pub struct MetricsTree_Scripts_Count { pub p2tr: BaseCumulativeSumPattern, pub p2wpkh: BaseCumulativeSumPattern, pub p2wsh: BaseCumulativeSumPattern, - pub opreturn: BaseCumulativeSumPattern, + pub op_return: BaseCumulativeSumPattern, pub empty_output: BaseCumulativeSumPattern, pub unknown_output: BaseCumulativeSumPattern, pub segwit: BaseCumulativeSumPattern, @@ -4095,7 +4093,7 @@ impl MetricsTree_Scripts_Count { p2tr: BaseCumulativeSumPattern::new(client.clone(), "p2tr_count".to_string()), p2wpkh: BaseCumulativeSumPattern::new(client.clone(), "p2wpkh_count".to_string()), p2wsh: BaseCumulativeSumPattern::new(client.clone(), "p2wsh_count".to_string()), - opreturn: BaseCumulativeSumPattern::new(client.clone(), "opreturn_count".to_string()), + op_return: BaseCumulativeSumPattern::new(client.clone(), "op_return_count".to_string()), empty_output: BaseCumulativeSumPattern::new(client.clone(), "empty_output_count".to_string()), unknown_output: BaseCumulativeSumPattern::new(client.clone(), "unknown_output_count".to_string()), segwit: BaseCumulativeSumPattern::new(client.clone(), "segwit_count".to_string()), @@ -4105,28 +4103,28 @@ impl MetricsTree_Scripts_Count { /// Metrics tree node. pub struct MetricsTree_Scripts_Value { - pub opreturn: MetricsTree_Scripts_Value_Opreturn, + pub op_return: MetricsTree_Scripts_Value_OpReturn, } impl MetricsTree_Scripts_Value { pub fn new(client: Arc, base_path: String) -> Self { Self { - opreturn: MetricsTree_Scripts_Value_Opreturn::new(client.clone(), format!("{base_path}_opreturn")), + op_return: MetricsTree_Scripts_Value_OpReturn::new(client.clone(), format!("{base_path}_op_return")), } } } /// Metrics tree node. -pub struct MetricsTree_Scripts_Value_Opreturn { +pub struct MetricsTree_Scripts_Value_OpReturn { pub base: BtcCentsSatsUsdPattern, pub cumulative: BtcCentsSatsUsdPattern, } -impl MetricsTree_Scripts_Value_Opreturn { +impl MetricsTree_Scripts_Value_OpReturn { pub fn new(client: Arc, base_path: String) -> Self { Self { - base: BtcCentsSatsUsdPattern::new(client.clone(), "opreturn_value".to_string()), - cumulative: BtcCentsSatsUsdPattern::new(client.clone(), "opreturn_value_cumulative".to_string()), + base: BtcCentsSatsUsdPattern::new(client.clone(), "op_return_value".to_string()), + cumulative: BtcCentsSatsUsdPattern::new(client.clone(), "op_return_value_cumulative".to_string()), } } } @@ -4581,7 +4579,7 @@ pub struct MetricsTree_Indexes_Address { pub p2ms: MetricsTree_Indexes_Address_P2ms, pub empty: MetricsTree_Indexes_Address_Empty, pub unknown: MetricsTree_Indexes_Address_Unknown, - pub opreturn: MetricsTree_Indexes_Address_Opreturn, + pub op_return: MetricsTree_Indexes_Address_OpReturn, } impl MetricsTree_Indexes_Address { @@ -4598,7 +4596,7 @@ impl MetricsTree_Indexes_Address { p2ms: MetricsTree_Indexes_Address_P2ms::new(client.clone(), format!("{base_path}_p2ms")), empty: MetricsTree_Indexes_Address_Empty::new(client.clone(), format!("{base_path}_empty")), unknown: MetricsTree_Indexes_Address_Unknown::new(client.clone(), format!("{base_path}_unknown")), - opreturn: MetricsTree_Indexes_Address_Opreturn::new(client.clone(), format!("{base_path}_opreturn")), + op_return: MetricsTree_Indexes_Address_OpReturn::new(client.clone(), format!("{base_path}_op_return")), } } } @@ -4606,12 +4604,14 @@ impl MetricsTree_Indexes_Address { /// Metrics tree node. pub struct MetricsTree_Indexes_Address_P2pk33 { pub identity: MetricPattern26, + pub address: MetricPattern26
, } impl MetricsTree_Indexes_Address_P2pk33 { pub fn new(client: Arc, base_path: String) -> Self { Self { identity: MetricPattern26::new(client.clone(), "p2pk33_address_index".to_string()), + address: MetricPattern26::new(client.clone(), "p2pk33_address".to_string()), } } } @@ -4619,12 +4619,14 @@ impl MetricsTree_Indexes_Address_P2pk33 { /// Metrics tree node. pub struct MetricsTree_Indexes_Address_P2pk65 { pub identity: MetricPattern27, + pub address: MetricPattern27
, } impl MetricsTree_Indexes_Address_P2pk65 { pub fn new(client: Arc, base_path: String) -> Self { Self { identity: MetricPattern27::new(client.clone(), "p2pk65_address_index".to_string()), + address: MetricPattern27::new(client.clone(), "p2pk65_address".to_string()), } } } @@ -4632,12 +4634,14 @@ impl MetricsTree_Indexes_Address_P2pk65 { /// Metrics tree node. pub struct MetricsTree_Indexes_Address_P2pkh { pub identity: MetricPattern28, + pub address: MetricPattern28
, } impl MetricsTree_Indexes_Address_P2pkh { pub fn new(client: Arc, base_path: String) -> Self { Self { identity: MetricPattern28::new(client.clone(), "p2pkh_address_index".to_string()), + address: MetricPattern28::new(client.clone(), "p2pkh_address".to_string()), } } } @@ -4645,12 +4649,14 @@ impl MetricsTree_Indexes_Address_P2pkh { /// Metrics tree node. pub struct MetricsTree_Indexes_Address_P2sh { pub identity: MetricPattern29, + pub address: MetricPattern29
, } impl MetricsTree_Indexes_Address_P2sh { pub fn new(client: Arc, base_path: String) -> Self { Self { identity: MetricPattern29::new(client.clone(), "p2sh_address_index".to_string()), + address: MetricPattern29::new(client.clone(), "p2sh_address".to_string()), } } } @@ -4658,12 +4664,14 @@ impl MetricsTree_Indexes_Address_P2sh { /// Metrics tree node. pub struct MetricsTree_Indexes_Address_P2tr { pub identity: MetricPattern30, + pub address: MetricPattern30
, } impl MetricsTree_Indexes_Address_P2tr { pub fn new(client: Arc, base_path: String) -> Self { Self { identity: MetricPattern30::new(client.clone(), "p2tr_address_index".to_string()), + address: MetricPattern30::new(client.clone(), "p2tr_address".to_string()), } } } @@ -4671,12 +4679,14 @@ impl MetricsTree_Indexes_Address_P2tr { /// Metrics tree node. pub struct MetricsTree_Indexes_Address_P2wpkh { pub identity: MetricPattern31, + pub address: MetricPattern31
, } impl MetricsTree_Indexes_Address_P2wpkh { pub fn new(client: Arc, base_path: String) -> Self { Self { identity: MetricPattern31::new(client.clone(), "p2wpkh_address_index".to_string()), + address: MetricPattern31::new(client.clone(), "p2wpkh_address".to_string()), } } } @@ -4684,12 +4694,14 @@ impl MetricsTree_Indexes_Address_P2wpkh { /// Metrics tree node. pub struct MetricsTree_Indexes_Address_P2wsh { pub identity: MetricPattern32, + pub address: MetricPattern32
, } impl MetricsTree_Indexes_Address_P2wsh { pub fn new(client: Arc, base_path: String) -> Self { Self { identity: MetricPattern32::new(client.clone(), "p2wsh_address_index".to_string()), + address: MetricPattern32::new(client.clone(), "p2wsh_address".to_string()), } } } @@ -4697,12 +4709,14 @@ impl MetricsTree_Indexes_Address_P2wsh { /// Metrics tree node. pub struct MetricsTree_Indexes_Address_P2a { pub identity: MetricPattern24, + pub address: MetricPattern24
, } impl MetricsTree_Indexes_Address_P2a { pub fn new(client: Arc, base_path: String) -> Self { Self { identity: MetricPattern24::new(client.clone(), "p2a_address_index".to_string()), + address: MetricPattern24::new(client.clone(), "p2a_address".to_string()), } } } @@ -4747,11 +4761,11 @@ impl MetricsTree_Indexes_Address_Unknown { } /// Metrics tree node. -pub struct MetricsTree_Indexes_Address_Opreturn { +pub struct MetricsTree_Indexes_Address_OpReturn { pub identity: MetricPattern23, } -impl MetricsTree_Indexes_Address_Opreturn { +impl MetricsTree_Indexes_Address_OpReturn { pub fn new(client: Arc, base_path: String) -> Self { Self { identity: MetricPattern23::new(client.clone(), "op_return_index".to_string()), @@ -4845,8 +4859,8 @@ pub struct MetricsTree_Indexes_Minute10 { impl MetricsTree_Indexes_Minute10 { pub fn new(client: Arc, base_path: String) -> Self { Self { - identity: MetricPattern3::new(client.clone(), "minute10".to_string()), - first_height: MetricPattern3::new(client.clone(), "minute10_first_height".to_string()), + identity: MetricPattern3::new(client.clone(), "minute10_index".to_string()), + first_height: MetricPattern3::new(client.clone(), "first_height".to_string()), } } } @@ -4860,8 +4874,8 @@ pub struct MetricsTree_Indexes_Minute30 { impl MetricsTree_Indexes_Minute30 { pub fn new(client: Arc, base_path: String) -> Self { Self { - identity: MetricPattern4::new(client.clone(), "minute30".to_string()), - first_height: MetricPattern4::new(client.clone(), "minute30_first_height".to_string()), + identity: MetricPattern4::new(client.clone(), "minute30_index".to_string()), + first_height: MetricPattern4::new(client.clone(), "first_height".to_string()), } } } @@ -4875,8 +4889,8 @@ pub struct MetricsTree_Indexes_Hour1 { impl MetricsTree_Indexes_Hour1 { pub fn new(client: Arc, base_path: String) -> Self { Self { - identity: MetricPattern5::new(client.clone(), "hour1".to_string()), - first_height: MetricPattern5::new(client.clone(), "hour1_first_height".to_string()), + identity: MetricPattern5::new(client.clone(), "hour1_index".to_string()), + first_height: MetricPattern5::new(client.clone(), "first_height".to_string()), } } } @@ -4890,8 +4904,8 @@ pub struct MetricsTree_Indexes_Hour4 { impl MetricsTree_Indexes_Hour4 { pub fn new(client: Arc, base_path: String) -> Self { Self { - identity: MetricPattern6::new(client.clone(), "hour4".to_string()), - first_height: MetricPattern6::new(client.clone(), "hour4_first_height".to_string()), + identity: MetricPattern6::new(client.clone(), "hour4_index".to_string()), + first_height: MetricPattern6::new(client.clone(), "first_height".to_string()), } } } @@ -4905,8 +4919,8 @@ pub struct MetricsTree_Indexes_Hour12 { impl MetricsTree_Indexes_Hour12 { pub fn new(client: Arc, base_path: String) -> Self { Self { - identity: MetricPattern7::new(client.clone(), "hour12".to_string()), - first_height: MetricPattern7::new(client.clone(), "hour12_first_height".to_string()), + identity: MetricPattern7::new(client.clone(), "hour12_index".to_string()), + first_height: MetricPattern7::new(client.clone(), "first_height".to_string()), } } } @@ -4922,7 +4936,7 @@ pub struct MetricsTree_Indexes_Day1 { impl MetricsTree_Indexes_Day1 { pub fn new(client: Arc, base_path: String) -> Self { Self { - identity: MetricPattern8::new(client.clone(), "day1".to_string()), + identity: MetricPattern8::new(client.clone(), "day1_index".to_string()), date: MetricPattern8::new(client.clone(), "date".to_string()), first_height: MetricPattern8::new(client.clone(), "first_height".to_string()), height_count: MetricPattern8::new(client.clone(), "height_count".to_string()), @@ -4939,8 +4953,8 @@ pub struct MetricsTree_Indexes_Day3 { impl MetricsTree_Indexes_Day3 { pub fn new(client: Arc, base_path: String) -> Self { Self { - identity: MetricPattern9::new(client.clone(), "day3".to_string()), - first_height: MetricPattern9::new(client.clone(), "day3_first_height".to_string()), + identity: MetricPattern9::new(client.clone(), "day3_index".to_string()), + first_height: MetricPattern9::new(client.clone(), "first_height".to_string()), } } } @@ -4955,9 +4969,9 @@ pub struct MetricsTree_Indexes_Week1 { impl MetricsTree_Indexes_Week1 { pub fn new(client: Arc, base_path: String) -> Self { Self { - identity: MetricPattern10::new(client.clone(), "week1".to_string()), + identity: MetricPattern10::new(client.clone(), "week1_index".to_string()), date: MetricPattern10::new(client.clone(), "date".to_string()), - first_height: MetricPattern10::new(client.clone(), "week1_first_height".to_string()), + first_height: MetricPattern10::new(client.clone(), "first_height".to_string()), } } } @@ -4972,9 +4986,9 @@ pub struct MetricsTree_Indexes_Month1 { impl MetricsTree_Indexes_Month1 { pub fn new(client: Arc, base_path: String) -> Self { Self { - identity: MetricPattern11::new(client.clone(), "month1".to_string()), + identity: MetricPattern11::new(client.clone(), "month1_index".to_string()), date: MetricPattern11::new(client.clone(), "date".to_string()), - first_height: MetricPattern11::new(client.clone(), "month1_first_height".to_string()), + first_height: MetricPattern11::new(client.clone(), "first_height".to_string()), } } } @@ -4989,9 +5003,9 @@ pub struct MetricsTree_Indexes_Month3 { impl MetricsTree_Indexes_Month3 { pub fn new(client: Arc, base_path: String) -> Self { Self { - identity: MetricPattern12::new(client.clone(), "month3".to_string()), + identity: MetricPattern12::new(client.clone(), "month3_index".to_string()), date: MetricPattern12::new(client.clone(), "date".to_string()), - first_height: MetricPattern12::new(client.clone(), "month3_first_height".to_string()), + first_height: MetricPattern12::new(client.clone(), "first_height".to_string()), } } } @@ -5006,9 +5020,9 @@ pub struct MetricsTree_Indexes_Month6 { impl MetricsTree_Indexes_Month6 { pub fn new(client: Arc, base_path: String) -> Self { Self { - identity: MetricPattern13::new(client.clone(), "month6".to_string()), + identity: MetricPattern13::new(client.clone(), "month6_index".to_string()), date: MetricPattern13::new(client.clone(), "date".to_string()), - first_height: MetricPattern13::new(client.clone(), "month6_first_height".to_string()), + first_height: MetricPattern13::new(client.clone(), "first_height".to_string()), } } } @@ -5023,9 +5037,9 @@ pub struct MetricsTree_Indexes_Year1 { impl MetricsTree_Indexes_Year1 { pub fn new(client: Arc, base_path: String) -> Self { Self { - identity: MetricPattern14::new(client.clone(), "year1".to_string()), + identity: MetricPattern14::new(client.clone(), "year1_index".to_string()), date: MetricPattern14::new(client.clone(), "date".to_string()), - first_height: MetricPattern14::new(client.clone(), "year1_first_height".to_string()), + first_height: MetricPattern14::new(client.clone(), "first_height".to_string()), } } } @@ -5040,9 +5054,9 @@ pub struct MetricsTree_Indexes_Year10 { impl MetricsTree_Indexes_Year10 { pub fn new(client: Arc, base_path: String) -> Self { Self { - identity: MetricPattern15::new(client.clone(), "year10".to_string()), + identity: MetricPattern15::new(client.clone(), "year10_index".to_string()), date: MetricPattern15::new(client.clone(), "date".to_string()), - first_height: MetricPattern15::new(client.clone(), "year10_first_height".to_string()), + first_height: MetricPattern15::new(client.clone(), "first_height".to_string()), } } } @@ -6436,14 +6450,14 @@ impl MetricsTree_Supply { /// Metrics tree node. pub struct MetricsTree_Supply_Burned { - pub opreturn: BaseCumulativeSumPattern4, + pub op_return: BaseCumulativeSumPattern4, pub unspendable: BaseCumulativeSumPattern4, } impl MetricsTree_Supply_Burned { pub fn new(client: Arc, base_path: String) -> Self { Self { - opreturn: BaseCumulativeSumPattern4::new(client.clone(), "opreturn_supply".to_string()), + op_return: BaseCumulativeSumPattern4::new(client.clone(), "op_return_supply".to_string()), unspendable: BaseCumulativeSumPattern4::new(client.clone(), "unspendable_supply".to_string()), } } diff --git a/crates/brk_cohort/src/by_type.rs b/crates/brk_cohort/src/by_type.rs index 881373f8a..be036ea34 100644 --- a/crates/brk_cohort/src/by_type.rs +++ b/crates/brk_cohort/src/by_type.rs @@ -24,7 +24,7 @@ impl ByType { OutputType::P2A => &self.spendable.p2a, OutputType::Empty => &self.spendable.empty, OutputType::Unknown => &self.spendable.unknown, - OutputType::OpReturn => &self.unspendable.opreturn, + OutputType::OpReturn => &self.unspendable.op_return, } } @@ -41,7 +41,7 @@ impl ByType { OutputType::P2A => &mut self.spendable.p2a, OutputType::Unknown => &mut self.spendable.unknown, OutputType::Empty => &mut self.spendable.empty, - OutputType::OpReturn => &mut self.unspendable.opreturn, + OutputType::OpReturn => &mut self.unspendable.op_return, } } } diff --git a/crates/brk_cohort/src/unspendable_type.rs b/crates/brk_cohort/src/unspendable_type.rs index f1772f1cc..5d581a164 100644 --- a/crates/brk_cohort/src/unspendable_type.rs +++ b/crates/brk_cohort/src/unspendable_type.rs @@ -4,12 +4,12 @@ use brk_traversable::Traversable; #[derive(Default, Clone, Debug, Traversable)] pub struct UnspendableType { - pub opreturn: T, + pub op_return: T, } impl UnspendableType { pub fn as_vec(&self) -> [&T; 1] { - [&self.opreturn] + [&self.op_return] } } @@ -20,7 +20,7 @@ where type Output = Self; fn add(self, rhs: Self) -> Self::Output { Self { - opreturn: self.opreturn + rhs.opreturn, + op_return: self.op_return + rhs.op_return, } } } @@ -30,6 +30,6 @@ where T: AddAssign, { fn add_assign(&mut self, rhs: Self) { - self.opreturn += rhs.opreturn; + self.op_return += rhs.op_return; } } diff --git a/crates/brk_computer/src/blocks/difficulty/import.rs b/crates/brk_computer/src/blocks/difficulty/import.rs index ce461e65d..0ed8bec5f 100644 --- a/crates/brk_computer/src/blocks/difficulty/import.rs +++ b/crates/brk_computer/src/blocks/difficulty/import.rs @@ -42,14 +42,19 @@ impl Vecs { ); Ok(Self { - base: Resolutions::forced_import( + value: Resolutions::forced_import( "difficulty", indexer.vecs.blocks.difficulty.read_only_boxed_clone(), version, indexes, ), as_hash, - adjustment: PercentPerBlock::forced_import(db, "difficulty_adjustment", version, indexes)?, + adjustment: PercentPerBlock::forced_import( + db, + "difficulty_adjustment", + version, + indexes, + )?, epoch: PerBlock::forced_import(db, "difficulty_epoch", version, indexes)?, blocks_before_next, days_before_next, diff --git a/crates/brk_computer/src/distribution/cohorts/utxo/fenwick.rs b/crates/brk_computer/src/distribution/cohorts/utxo/fenwick.rs index bf55d6445..b3c42d5b4 100644 --- a/crates/brk_computer/src/distribution/cohorts/utxo/fenwick.rs +++ b/crates/brk_computer/src/distribution/cohorts/utxo/fenwick.rs @@ -297,7 +297,7 @@ impl CostBasisFenwick { if total <= 0 { 0 } else { - (range as f64 / total as f64 * 10000.0) as u16 + (range as f64 / total as f64 * 10000.0).round() as u16 } }; diff --git a/crates/brk_computer/src/distribution/state/cost_basis/realized.rs b/crates/brk_computer/src/distribution/state/cost_basis/realized.rs index ac1df0018..e80e9919e 100644 --- a/crates/brk_computer/src/distribution/state/cost_basis/realized.rs +++ b/crates/brk_computer/src/distribution/state/cost_basis/realized.rs @@ -461,4 +461,34 @@ impl RealizedState { } Cents::new((self.peak_regret_raw / Sats::ONE_BTC_U128) as u64) } + + /// Raw profit value created for lossless aggregation. + #[inline] + pub(crate) fn profit_value_created_raw(&self) -> u128 { + self.profit_value_created_raw + } + + /// Raw profit value destroyed for lossless aggregation. + #[inline] + pub(crate) fn profit_value_destroyed_raw(&self) -> u128 { + self.profit_value_destroyed_raw + } + + /// Raw loss value created for lossless aggregation. + #[inline] + pub(crate) fn loss_value_created_raw(&self) -> u128 { + self.loss_value_created_raw + } + + /// Raw loss value destroyed for lossless aggregation. + #[inline] + pub(crate) fn loss_value_destroyed_raw(&self) -> u128 { + self.loss_value_destroyed_raw + } + + /// Raw peak regret for lossless aggregation. + #[inline] + pub(crate) fn peak_regret_raw(&self) -> u128 { + self.peak_regret_raw + } } diff --git a/crates/brk_computer/src/indexes/address.rs b/crates/brk_computer/src/indexes/address.rs index 5c620543c..86f7165b3 100644 --- a/crates/brk_computer/src/indexes/address.rs +++ b/crates/brk_computer/src/indexes/address.rs @@ -1,10 +1,11 @@ use brk_indexer::Indexer; use brk_traversable::Traversable; use brk_types::{ - EmptyOutputIndex, OpReturnIndex, P2AAddressIndex, P2ABytes, P2MSOutputIndex, - P2PK33AddressIndex, P2PK33Bytes, P2PK65AddressIndex, P2PK65Bytes, P2PKHAddressIndex, - P2PKHBytes, P2SHAddressIndex, P2SHBytes, P2TRAddressIndex, P2TRBytes, P2WPKHAddressIndex, - P2WPKHBytes, P2WSHAddressIndex, P2WSHBytes, TxIndex, UnknownOutputIndex, Version, + Address, AddressBytes, EmptyOutputIndex, OpReturnIndex, P2AAddressIndex, P2ABytes, + P2MSOutputIndex, P2PK33AddressIndex, P2PK33Bytes, P2PK65AddressIndex, P2PK65Bytes, + P2PKHAddressIndex, P2PKHBytes, P2SHAddressIndex, P2SHBytes, P2TRAddressIndex, P2TRBytes, + P2WPKHAddressIndex, P2WPKHBytes, P2WSHAddressIndex, P2WSHBytes, TxIndex, UnknownOutputIndex, + Version, }; use vecdb::{LazyVecFrom1, ReadableCloneableVec}; @@ -21,50 +22,58 @@ pub struct Vecs { pub p2ms: P2MSVecs, pub empty: EmptyVecs, pub unknown: UnknownVecs, - pub opreturn: OpReturnVecs, + pub op_return: OpReturnVecs, } #[derive(Clone, Traversable)] pub struct P2PK33Vecs { pub identity: LazyVecFrom1, + pub address: LazyVecFrom1, } #[derive(Clone, Traversable)] pub struct P2PK65Vecs { pub identity: LazyVecFrom1, + pub address: LazyVecFrom1, } #[derive(Clone, Traversable)] pub struct P2PKHVecs { pub identity: LazyVecFrom1, + pub address: LazyVecFrom1, } #[derive(Clone, Traversable)] pub struct P2SHVecs { pub identity: LazyVecFrom1, + pub address: LazyVecFrom1, } #[derive(Clone, Traversable)] pub struct P2TRVecs { pub identity: LazyVecFrom1, + pub address: LazyVecFrom1, } #[derive(Clone, Traversable)] pub struct P2WPKHVecs { pub identity: LazyVecFrom1, + pub address: LazyVecFrom1, } #[derive(Clone, Traversable)] pub struct P2WSHVecs { pub identity: LazyVecFrom1, + pub address: LazyVecFrom1, } #[derive(Clone, Traversable)] pub struct P2AVecs { pub identity: LazyVecFrom1, + pub address: LazyVecFrom1, } #[derive(Clone, Traversable)] @@ -97,6 +106,12 @@ impl Vecs { indexer.vecs.addresses.p2pk33.bytes.read_only_boxed_clone(), |index, _| index, ), + address: LazyVecFrom1::init( + "p2pk33_address", + version, + indexer.vecs.addresses.p2pk33.bytes.read_only_boxed_clone(), + |_, bytes| Address::try_from(&AddressBytes::from(bytes)).unwrap(), + ), }, p2pk65: P2PK65Vecs { identity: LazyVecFrom1::init( @@ -105,6 +120,12 @@ impl Vecs { indexer.vecs.addresses.p2pk65.bytes.read_only_boxed_clone(), |index, _| index, ), + address: LazyVecFrom1::init( + "p2pk65_address", + version, + indexer.vecs.addresses.p2pk65.bytes.read_only_boxed_clone(), + |_, bytes| Address::try_from(&AddressBytes::from(bytes)).unwrap(), + ), }, p2pkh: P2PKHVecs { identity: LazyVecFrom1::init( @@ -113,6 +134,12 @@ impl Vecs { indexer.vecs.addresses.p2pkh.bytes.read_only_boxed_clone(), |index, _| index, ), + address: LazyVecFrom1::init( + "p2pkh_address", + version, + indexer.vecs.addresses.p2pkh.bytes.read_only_boxed_clone(), + |_, bytes| Address::try_from(&AddressBytes::from(bytes)).unwrap(), + ), }, p2sh: P2SHVecs { identity: LazyVecFrom1::init( @@ -121,6 +148,12 @@ impl Vecs { indexer.vecs.addresses.p2sh.bytes.read_only_boxed_clone(), |index, _| index, ), + address: LazyVecFrom1::init( + "p2sh_address", + version, + indexer.vecs.addresses.p2sh.bytes.read_only_boxed_clone(), + |_, bytes| Address::try_from(&AddressBytes::from(bytes)).unwrap(), + ), }, p2tr: P2TRVecs { identity: LazyVecFrom1::init( @@ -129,6 +162,12 @@ impl Vecs { indexer.vecs.addresses.p2tr.bytes.read_only_boxed_clone(), |index, _| index, ), + address: LazyVecFrom1::init( + "p2tr_address", + version, + indexer.vecs.addresses.p2tr.bytes.read_only_boxed_clone(), + |_, bytes| Address::try_from(&AddressBytes::from(bytes)).unwrap(), + ), }, p2wpkh: P2WPKHVecs { identity: LazyVecFrom1::init( @@ -137,6 +176,12 @@ impl Vecs { indexer.vecs.addresses.p2wpkh.bytes.read_only_boxed_clone(), |index, _| index, ), + address: LazyVecFrom1::init( + "p2wpkh_address", + version, + indexer.vecs.addresses.p2wpkh.bytes.read_only_boxed_clone(), + |_, bytes| Address::try_from(&AddressBytes::from(bytes)).unwrap(), + ), }, p2wsh: P2WSHVecs { identity: LazyVecFrom1::init( @@ -145,6 +190,12 @@ impl Vecs { indexer.vecs.addresses.p2wsh.bytes.read_only_boxed_clone(), |index, _| index, ), + address: LazyVecFrom1::init( + "p2wsh_address", + version, + indexer.vecs.addresses.p2wsh.bytes.read_only_boxed_clone(), + |_, bytes| Address::try_from(&AddressBytes::from(bytes)).unwrap(), + ), }, p2a: P2AVecs { identity: LazyVecFrom1::init( @@ -153,6 +204,12 @@ impl Vecs { indexer.vecs.addresses.p2a.bytes.read_only_boxed_clone(), |index, _| index, ), + address: LazyVecFrom1::init( + "p2a_address", + version, + indexer.vecs.addresses.p2a.bytes.read_only_boxed_clone(), + |_, bytes| Address::try_from(&AddressBytes::from(bytes)).unwrap(), + ), }, p2ms: P2MSVecs { identity: LazyVecFrom1::init( @@ -186,14 +243,14 @@ impl Vecs { |index, _| index, ), }, - opreturn: OpReturnVecs { + op_return: OpReturnVecs { identity: LazyVecFrom1::init( "op_return_index", version, indexer .vecs .scripts - .opreturn.to_tx_index + .op_return.to_tx_index .read_only_boxed_clone(), |index, _| index, ), diff --git a/crates/brk_computer/src/outputs/count/compute.rs b/crates/brk_computer/src/outputs/count/compute.rs index abbbd5d72..0134fbb0b 100644 --- a/crates/brk_computer/src/outputs/count/compute.rs +++ b/crates/brk_computer/src/outputs/count/compute.rs @@ -35,12 +35,12 @@ impl Vecs { starting_indexes.height, &self.total.full.cumulative, &inputs_count.full.cumulative, - &scripts_count.opreturn.cumulative.height, - |(h, output_count, input_count, opreturn_count, ..)| { + &scripts_count.op_return.cumulative.height, + |(h, output_count, input_count, op_return_count, ..)| { let block_count = u64::from(h + 1_usize); // -1 > genesis output is unspendable let mut utxo_count = - *output_count - (*input_count - block_count) - *opreturn_count - 1; + *output_count - (*input_count - block_count) - *op_return_count - 1; // txid dup: e3bf3d07d4b0375638d5f1db5255fe07ba2c4cb067cd81b84ee974b6585fb468 // Block 91_722 https://mempool.space/block/00000000000271a2dc26e7667f8419f2e15416dc6955e5a6c6cdf3f2574dd08e diff --git a/crates/brk_computer/src/scripts/count/compute.rs b/crates/brk_computer/src/scripts/count/compute.rs index 86cad3e78..b85a4034d 100644 --- a/crates/brk_computer/src/scripts/count/compute.rs +++ b/crates/brk_computer/src/scripts/count/compute.rs @@ -102,12 +102,12 @@ impl Vecs { )?) })?; - self.opreturn + self.op_return .compute(starting_indexes.height, exit, |v| { Ok(v.compute_count_from_indexes( starting_indexes.height, - &indexer.vecs.scripts.opreturn.first_index, - &indexer.vecs.scripts.opreturn.to_tx_index, + &indexer.vecs.scripts.op_return.first_index, + &indexer.vecs.scripts.op_return.to_tx_index, exit, )?) })?; diff --git a/crates/brk_computer/src/scripts/count/import.rs b/crates/brk_computer/src/scripts/count/import.rs index c2d79ce45..2735709be 100644 --- a/crates/brk_computer/src/scripts/count/import.rs +++ b/crates/brk_computer/src/scripts/count/import.rs @@ -46,9 +46,9 @@ impl Vecs { p2tr, p2wpkh, p2wsh, - opreturn: PerBlockCumulativeWithSums::forced_import( + op_return: PerBlockCumulativeWithSums::forced_import( db, - "opreturn_count", + "op_return_count", version, indexes, cached_starts, diff --git a/crates/brk_computer/src/scripts/count/vecs.rs b/crates/brk_computer/src/scripts/count/vecs.rs index 5102d9ce1..47131f83c 100644 --- a/crates/brk_computer/src/scripts/count/vecs.rs +++ b/crates/brk_computer/src/scripts/count/vecs.rs @@ -15,7 +15,7 @@ pub struct Vecs { pub p2tr: PerBlockCumulativeWithSums, pub p2wpkh: PerBlockCumulativeWithSums, pub p2wsh: PerBlockCumulativeWithSums, - pub opreturn: PerBlockCumulativeWithSums, + pub op_return: PerBlockCumulativeWithSums, pub empty_output: PerBlockCumulativeWithSums, pub unknown_output: PerBlockCumulativeWithSums, diff --git a/crates/brk_computer/src/scripts/value/compute.rs b/crates/brk_computer/src/scripts/value/compute.rs index f343fd97c..380bd03d2 100644 --- a/crates/brk_computer/src/scripts/value/compute.rs +++ b/crates/brk_computer/src/scripts/value/compute.rs @@ -14,7 +14,7 @@ impl Vecs { starting_indexes: &Indexes, exit: &Exit, ) -> Result<()> { - self.opreturn.compute_with( + self.op_return.compute_with( starting_indexes.height, prices, exit, @@ -81,14 +81,14 @@ impl Vecs { .value .collect_range_into_at(out_start, out_end, &mut values_buf); - let mut opreturn_value = Sats::ZERO; + let mut op_return_value = Sats::ZERO; for (ot, val) in output_types_buf.iter().zip(values_buf.iter()) { if *ot == OutputType::OpReturn { - opreturn_value += *val; + op_return_value += *val; } } - height_vec.truncate_push(height, opreturn_value)?; + height_vec.truncate_push(height, op_return_value)?; } height_vec.write()?; diff --git a/crates/brk_computer/src/scripts/value/import.rs b/crates/brk_computer/src/scripts/value/import.rs index 927026f54..6d45eacb0 100644 --- a/crates/brk_computer/src/scripts/value/import.rs +++ b/crates/brk_computer/src/scripts/value/import.rs @@ -12,9 +12,9 @@ impl Vecs { indexes: &indexes::Vecs, ) -> Result { Ok(Self { - opreturn: AmountPerBlockCumulative::forced_import( + op_return: AmountPerBlockCumulative::forced_import( db, - "opreturn_value", + "op_return_value", version, indexes, )?, diff --git a/crates/brk_computer/src/scripts/value/vecs.rs b/crates/brk_computer/src/scripts/value/vecs.rs index 6db747bcf..511f88aac 100644 --- a/crates/brk_computer/src/scripts/value/vecs.rs +++ b/crates/brk_computer/src/scripts/value/vecs.rs @@ -5,5 +5,5 @@ use crate::internal::AmountPerBlockCumulative; #[derive(Traversable)] pub struct Vecs { - pub opreturn: AmountPerBlockCumulative, + pub op_return: AmountPerBlockCumulative, } diff --git a/crates/brk_computer/src/supply/burned/compute.rs b/crates/brk_computer/src/supply/burned/compute.rs index 591938237..09dae8273 100644 --- a/crates/brk_computer/src/supply/burned/compute.rs +++ b/crates/brk_computer/src/supply/burned/compute.rs @@ -14,18 +14,18 @@ impl Vecs { starting_indexes: &Indexes, exit: &Exit, ) -> Result<()> { - self.opreturn.compute( + self.op_return.compute( starting_indexes.height, prices, exit, |height_vec| { // Validate computed versions against dependencies - let opreturn_dep_version = scripts.value.opreturn.base.sats.height.version(); - height_vec.validate_computed_version_or_reset(opreturn_dep_version)?; + let op_return_dep_version = scripts.value.op_return.base.sats.height.version(); + height_vec.validate_computed_version_or_reset(op_return_dep_version)?; - // Copy per-block opreturn values from scripts - let scripts_target = scripts.value.opreturn.base.sats.height.len(); + // Copy per-block op_return values from scripts + let scripts_target = scripts.value.op_return.base.sats.height.len(); if scripts_target > 0 { let target_height = Height::from(scripts_target - 1); let current_len = height_vec.len(); @@ -35,7 +35,7 @@ impl Vecs { if starting_height <= target_height { let start = starting_height.to_usize(); let end = target_height.to_usize() + 1; - scripts.value.opreturn.base.sats.height.fold_range_at( + scripts.value.op_return.base.sats.height.fold_range_at( start, end, start, @@ -52,9 +52,9 @@ impl Vecs { }, )?; - // 2. Compute unspendable supply = opreturn + unclaimed_rewards + genesis (at height 0) - // Get reference to opreturn height vec for computing unspendable - let opreturn_height = &self.opreturn.base.sats.height; + // 2. Compute unspendable supply = op_return + unclaimed_rewards + genesis (at height 0) + // Get reference to op_return height vec for computing unspendable + let op_return_height = &self.op_return.base.sats.height; let unclaimed_height = &mining.rewards.unclaimed.base.sats.height; self.unspendable.compute( @@ -63,12 +63,12 @@ impl Vecs { exit, |height_vec| { let unspendable_dep_version = - opreturn_height.version() + unclaimed_height.version(); + op_return_height.version() + unclaimed_height.version(); height_vec.validate_computed_version_or_reset(unspendable_dep_version)?; - let opreturn_target = opreturn_height.len(); - if opreturn_target > 0 { - let target_height = Height::from(opreturn_target - 1); + let op_return_target = op_return_height.len(); + if op_return_target > 0 { + let target_height = Height::from(op_return_target - 1); let current_len = height_vec.len(); let starting_height = Height::from(current_len.min(starting_indexes.height.to_usize())); @@ -77,14 +77,14 @@ impl Vecs { let start = starting_height.to_usize(); let end = target_height.to_usize() + 1; let unclaimed_data = unclaimed_height.collect_range_at(start, end); - opreturn_height.fold_range_at(start, end, start, |idx, opreturn| { + op_return_height.fold_range_at(start, end, start, |idx, op_return| { let unclaimed = unclaimed_data[idx - start]; let genesis = if idx == 0 { Sats::FIFTY_BTC } else { Sats::ZERO }; - let unspendable = genesis + opreturn + unclaimed; + let unspendable = genesis + op_return + unclaimed; height_vec .truncate_push(Height::from(idx), unspendable) .unwrap(); diff --git a/crates/brk_computer/src/supply/burned/import.rs b/crates/brk_computer/src/supply/burned/import.rs index 8e475dcbb..111184e6c 100644 --- a/crates/brk_computer/src/supply/burned/import.rs +++ b/crates/brk_computer/src/supply/burned/import.rs @@ -13,9 +13,9 @@ impl Vecs { cached_starts: &CachedWindowStarts, ) -> Result { Ok(Self { - opreturn: AmountPerBlockCumulativeWithSums::forced_import( + op_return: AmountPerBlockCumulativeWithSums::forced_import( db, - "opreturn_supply", + "op_return_supply", version, indexes, cached_starts, diff --git a/crates/brk_computer/src/supply/burned/vecs.rs b/crates/brk_computer/src/supply/burned/vecs.rs index 054d7db81..74998a0a1 100644 --- a/crates/brk_computer/src/supply/burned/vecs.rs +++ b/crates/brk_computer/src/supply/burned/vecs.rs @@ -5,6 +5,6 @@ use crate::internal::AmountPerBlockCumulativeWithSums; #[derive(Traversable)] pub struct Vecs { - pub opreturn: AmountPerBlockCumulativeWithSums, + pub op_return: AmountPerBlockCumulativeWithSums, pub unspendable: AmountPerBlockCumulativeWithSums, } diff --git a/crates/brk_indexer/src/indexes.rs b/crates/brk_indexer/src/indexes.rs index 8995f1497..7e40ef435 100644 --- a/crates/brk_indexer/src/indexes.rs +++ b/crates/brk_indexer/src/indexes.rs @@ -36,7 +36,7 @@ impl IndexesExt for Indexes { .p2ms.first_index .checked_push(height, self.p2ms_output_index)?; vecs.scripts - .opreturn.first_index + .op_return.first_index .checked_push(height, self.op_return_index)?; vecs.addresses .p2a.first_index @@ -110,8 +110,8 @@ impl IndexesExt for Indexes { )?; let op_return_index = starting_index( - &vecs.scripts.opreturn.first_index, - &vecs.scripts.opreturn.to_tx_index, + &vecs.scripts.op_return.first_index, + &vecs.scripts.op_return.to_tx_index, starting_height, )?; diff --git a/crates/brk_indexer/src/processor/txout.rs b/crates/brk_indexer/src/processor/txout.rs index fd65163db..4235ff987 100644 --- a/crates/brk_indexer/src/processor/txout.rs +++ b/crates/brk_indexer/src/processor/txout.rs @@ -174,7 +174,7 @@ pub(super) fn finalize_outputs( } OutputType::OpReturn => { scripts - .opreturn.to_tx_index + .op_return.to_tx_index .checked_push(indexes.op_return_index, tx_index)?; indexes.op_return_index.copy_then_increment() } diff --git a/crates/brk_indexer/src/vecs/scripts.rs b/crates/brk_indexer/src/vecs/scripts.rs index b7c7042b9..fd4c207e0 100644 --- a/crates/brk_indexer/src/vecs/scripts.rs +++ b/crates/brk_indexer/src/vecs/scripts.rs @@ -22,7 +22,7 @@ pub struct ScriptTypeVecs { pub empty: ScriptTypeVecs, - pub opreturn: ScriptTypeVecs, + pub op_return: ScriptTypeVecs, pub p2ms: ScriptTypeVecs, pub unknown: ScriptTypeVecs, } @@ -50,7 +50,7 @@ impl ScriptsVecs { }; Ok(Self { empty: ScriptTypeVecs { first_index: first_empty_output_index, to_tx_index: empty_output_index_to_tx_index }, - opreturn: ScriptTypeVecs { first_index: first_op_return_index, to_tx_index: op_return_index_to_tx_index }, + op_return: ScriptTypeVecs { first_index: first_op_return_index, to_tx_index: op_return_index_to_tx_index }, p2ms: ScriptTypeVecs { first_index: first_p2ms_output_index, to_tx_index: p2ms_output_index_to_tx_index }, unknown: ScriptTypeVecs { first_index: first_unknown_output_index, to_tx_index: unknown_output_index_to_tx_index }, }) @@ -67,7 +67,7 @@ impl ScriptsVecs { ) -> Result<()> { self.empty.first_index .truncate_if_needed_with_stamp(height, stamp)?; - self.opreturn.first_index + self.op_return.first_index .truncate_if_needed_with_stamp(height, stamp)?; self.p2ms.first_index .truncate_if_needed_with_stamp(height, stamp)?; @@ -75,7 +75,7 @@ impl ScriptsVecs { .truncate_if_needed_with_stamp(height, stamp)?; self.empty.to_tx_index .truncate_if_needed_with_stamp(empty_output_index, stamp)?; - self.opreturn.to_tx_index + self.op_return.to_tx_index .truncate_if_needed_with_stamp(op_return_index, stamp)?; self.p2ms.to_tx_index .truncate_if_needed_with_stamp(p2ms_output_index, stamp)?; @@ -87,11 +87,11 @@ impl ScriptsVecs { pub fn par_iter_mut_any(&mut self) -> impl ParallelIterator { [ &mut self.empty.first_index as &mut dyn AnyStoredVec, - &mut self.opreturn.first_index, + &mut self.op_return.first_index, &mut self.p2ms.first_index, &mut self.unknown.first_index, &mut self.empty.to_tx_index, - &mut self.opreturn.to_tx_index, + &mut self.op_return.to_tx_index, &mut self.p2ms.to_tx_index, &mut self.unknown.to_tx_index, ] diff --git a/crates/brk_types/src/address.rs b/crates/brk_types/src/address.rs index b458afda2..166cd3e08 100644 --- a/crates/brk_types/src/address.rs +++ b/crates/brk_types/src/address.rs @@ -5,13 +5,14 @@ use brk_error::Error; use derive_more::Deref; use schemars::JsonSchema; use serde::{Deserialize, Serialize, Serializer}; +use vecdb::Formattable; use crate::AddressBytes; use super::OutputType; /// Bitcoin address string -#[derive(Debug, Deref, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Deref, Deserialize, JsonSchema)] #[serde(transparent)] #[schemars( example = &"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f", @@ -99,3 +100,15 @@ impl Address { AddressBytes::address_to_script(&self.0) } } + +impl Formattable for Address { + fn write_to(&self, buf: &mut Vec) { + buf.extend_from_slice(self.0.as_bytes()); + } + + fn fmt_json(&self, buf: &mut Vec) { + buf.push(b'"'); + self.write_to(buf); + buf.push(b'"'); + } +} diff --git a/crates/brk_types/src/bytes.rs b/crates/brk_types/src/bytes.rs index 20d4b7c32..7fa6fab1f 100644 --- a/crates/brk_types/src/bytes.rs +++ b/crates/brk_types/src/bytes.rs @@ -1,5 +1,5 @@ use derive_more::{Deref, DerefMut}; -use schemars::JsonSchema; +use schemars::{JsonSchema, SchemaGenerator}; use serde::{Deserialize, Serialize}; use vecdb::Bytes; @@ -99,9 +99,8 @@ impl JsonSchema for U8x33 { "U8x33".into() } - fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema { - // Represent as a byte string - String::json_schema(_gen) + fn json_schema(generator: &mut SchemaGenerator) -> schemars::Schema { + Vec::::json_schema(generator) } } @@ -135,9 +134,8 @@ impl JsonSchema for U8x65 { "U8x65".into() } - fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema { - // Represent as a byte string - String::json_schema(_gen) + fn json_schema(generator: &mut SchemaGenerator) -> schemars::Schema { + Vec::::json_schema(generator) } } diff --git a/crates/brk_types/src/op_return_index.rs b/crates/brk_types/src/op_return_index.rs index d4e1c5bcb..968570a12 100644 --- a/crates/brk_types/src/op_return_index.rs +++ b/crates/brk_types/src/op_return_index.rs @@ -72,7 +72,7 @@ impl PrintableIndex for OpReturnIndex { } fn to_possible_strings() -> &'static [&'static str] { - &["op", "opreturn", "op_return_index"] + &["op", "opreturn", "op_return", "op_return_index"] } } diff --git a/modules/brk-client/index.js b/modules/brk-client/index.js index 6185c9cfe..bf32fda7b 100644 --- a/modules/brk-client/index.js +++ b/modules/brk-client/index.js @@ -900,8 +900,8 @@ /** @typedef {number[]} U8x2 */ /** @typedef {number[]} U8x20 */ /** @typedef {number[]} U8x32 */ -/** @typedef {string} U8x33 */ -/** @typedef {string} U8x65 */ +/** @typedef {number[]} U8x33 */ +/** @typedef {number[]} U8x65 */ /** @typedef {TypeIndex} UnknownOutputIndex */ /** * Unspent transaction output @@ -4075,8 +4075,7 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Blocks_Difficulty - * @property {MetricPattern18} raw - * @property {MetricPattern2} base + * @property {MetricPattern1} value * @property {MetricPattern1} asHash * @property {BpsPercentRatioPattern} adjustment * @property {MetricPattern1} epoch @@ -4440,7 +4439,7 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Scripts_Raw * @property {MetricsTree_Scripts_Raw_Empty} empty - * @property {MetricsTree_Scripts_Raw_Opreturn} opreturn + * @property {MetricsTree_Scripts_Raw_OpReturn} opReturn * @property {MetricsTree_Scripts_Raw_P2ms} p2ms * @property {MetricsTree_Scripts_Raw_Unknown} unknown */ @@ -4452,7 +4451,7 @@ function createUnspentPattern(client, acc) { */ /** - * @typedef {Object} MetricsTree_Scripts_Raw_Opreturn + * @typedef {Object} MetricsTree_Scripts_Raw_OpReturn * @property {MetricPattern18} firstIndex * @property {MetricPattern23} toTxIndex */ @@ -4480,7 +4479,7 @@ function createUnspentPattern(client, acc) { * @property {BaseCumulativeSumPattern} p2tr * @property {BaseCumulativeSumPattern} p2wpkh * @property {BaseCumulativeSumPattern} p2wsh - * @property {BaseCumulativeSumPattern} opreturn + * @property {BaseCumulativeSumPattern} opReturn * @property {BaseCumulativeSumPattern} emptyOutput * @property {BaseCumulativeSumPattern} unknownOutput * @property {BaseCumulativeSumPattern} segwit @@ -4488,11 +4487,11 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Scripts_Value - * @property {MetricsTree_Scripts_Value_Opreturn} opreturn + * @property {MetricsTree_Scripts_Value_OpReturn} opReturn */ /** - * @typedef {Object} MetricsTree_Scripts_Value_Opreturn + * @typedef {Object} MetricsTree_Scripts_Value_OpReturn * @property {BtcCentsSatsUsdPattern} base * @property {BtcCentsSatsUsdPattern} cumulative */ @@ -4700,47 +4699,55 @@ function createUnspentPattern(client, acc) { * @property {MetricsTree_Indexes_Address_P2ms} p2ms * @property {MetricsTree_Indexes_Address_Empty} empty * @property {MetricsTree_Indexes_Address_Unknown} unknown - * @property {MetricsTree_Indexes_Address_Opreturn} opreturn + * @property {MetricsTree_Indexes_Address_OpReturn} opReturn */ /** * @typedef {Object} MetricsTree_Indexes_Address_P2pk33 * @property {MetricPattern26} identity + * @property {MetricPattern26
} address */ /** * @typedef {Object} MetricsTree_Indexes_Address_P2pk65 * @property {MetricPattern27} identity + * @property {MetricPattern27
} address */ /** * @typedef {Object} MetricsTree_Indexes_Address_P2pkh * @property {MetricPattern28} identity + * @property {MetricPattern28
} address */ /** * @typedef {Object} MetricsTree_Indexes_Address_P2sh * @property {MetricPattern29} identity + * @property {MetricPattern29
} address */ /** * @typedef {Object} MetricsTree_Indexes_Address_P2tr * @property {MetricPattern30} identity + * @property {MetricPattern30
} address */ /** * @typedef {Object} MetricsTree_Indexes_Address_P2wpkh * @property {MetricPattern31} identity + * @property {MetricPattern31
} address */ /** * @typedef {Object} MetricsTree_Indexes_Address_P2wsh * @property {MetricPattern32} identity + * @property {MetricPattern32
} address */ /** * @typedef {Object} MetricsTree_Indexes_Address_P2a * @property {MetricPattern24} identity + * @property {MetricPattern24
} address */ /** @@ -4759,7 +4766,7 @@ function createUnspentPattern(client, acc) { */ /** - * @typedef {Object} MetricsTree_Indexes_Address_Opreturn + * @typedef {Object} MetricsTree_Indexes_Address_OpReturn * @property {MetricPattern23} identity */ @@ -5508,7 +5515,7 @@ function createUnspentPattern(client, acc) { /** * @typedef {Object} MetricsTree_Supply_Burned - * @property {BaseCumulativeSumPattern4} opreturn + * @property {BaseCumulativeSumPattern4} opReturn * @property {BaseCumulativeSumPattern4} unspendable */ @@ -6909,8 +6916,7 @@ class BrkClient extends BrkClientBase { blocks: { blockhash: createMetricPattern18(this, 'blockhash'), difficulty: { - raw: createMetricPattern18(this, 'difficulty'), - base: createMetricPattern2(this, 'difficulty'), + value: createMetricPattern1(this, 'difficulty'), asHash: createMetricPattern1(this, 'difficulty_as_hash'), adjustment: createBpsPercentRatioPattern(this, 'difficulty_adjustment'), epoch: createMetricPattern1(this, 'difficulty_epoch'), @@ -7174,7 +7180,7 @@ class BrkClient extends BrkClientBase { firstIndex: createMetricPattern18(this, 'first_empty_output_index'), toTxIndex: createMetricPattern22(this, 'tx_index'), }, - opreturn: { + opReturn: { firstIndex: createMetricPattern18(this, 'first_op_return_index'), toTxIndex: createMetricPattern23(this, 'tx_index'), }, @@ -7197,15 +7203,15 @@ class BrkClient extends BrkClientBase { p2tr: createBaseCumulativeSumPattern(this, 'p2tr_count'), p2wpkh: createBaseCumulativeSumPattern(this, 'p2wpkh_count'), p2wsh: createBaseCumulativeSumPattern(this, 'p2wsh_count'), - opreturn: createBaseCumulativeSumPattern(this, 'opreturn_count'), + opReturn: createBaseCumulativeSumPattern(this, 'op_return_count'), emptyOutput: createBaseCumulativeSumPattern(this, 'empty_output_count'), unknownOutput: createBaseCumulativeSumPattern(this, 'unknown_output_count'), segwit: createBaseCumulativeSumPattern(this, 'segwit_count'), }, value: { - opreturn: { - base: createBtcCentsSatsUsdPattern(this, 'opreturn_value'), - cumulative: createBtcCentsSatsUsdPattern(this, 'opreturn_value_cumulative'), + opReturn: { + base: createBtcCentsSatsUsdPattern(this, 'op_return_value'), + cumulative: createBtcCentsSatsUsdPattern(this, 'op_return_value_cumulative'), }, }, adoption: { @@ -7329,27 +7335,35 @@ class BrkClient extends BrkClientBase { address: { p2pk33: { identity: createMetricPattern26(this, 'p2pk33_address_index'), + address: createMetricPattern26(this, 'p2pk33_address'), }, p2pk65: { identity: createMetricPattern27(this, 'p2pk65_address_index'), + address: createMetricPattern27(this, 'p2pk65_address'), }, p2pkh: { identity: createMetricPattern28(this, 'p2pkh_address_index'), + address: createMetricPattern28(this, 'p2pkh_address'), }, p2sh: { identity: createMetricPattern29(this, 'p2sh_address_index'), + address: createMetricPattern29(this, 'p2sh_address'), }, p2tr: { identity: createMetricPattern30(this, 'p2tr_address_index'), + address: createMetricPattern30(this, 'p2tr_address'), }, p2wpkh: { identity: createMetricPattern31(this, 'p2wpkh_address_index'), + address: createMetricPattern31(this, 'p2wpkh_address'), }, p2wsh: { identity: createMetricPattern32(this, 'p2wsh_address_index'), + address: createMetricPattern32(this, 'p2wsh_address'), }, p2a: { identity: createMetricPattern24(this, 'p2a_address_index'), + address: createMetricPattern24(this, 'p2a_address'), }, p2ms: { identity: createMetricPattern25(this, 'p2ms_output_index'), @@ -7360,7 +7374,7 @@ class BrkClient extends BrkClientBase { unknown: { identity: createMetricPattern33(this, 'unknown_output_index'), }, - opreturn: { + opReturn: { identity: createMetricPattern23(this, 'op_return_index'), }, }, @@ -7393,64 +7407,64 @@ class BrkClient extends BrkClientBase { firstHeight: createMetricPattern16(this, 'first_height'), }, minute10: { - identity: createMetricPattern3(this, 'minute10'), - firstHeight: createMetricPattern3(this, 'minute10_first_height'), + identity: createMetricPattern3(this, 'minute10_index'), + firstHeight: createMetricPattern3(this, 'first_height'), }, minute30: { - identity: createMetricPattern4(this, 'minute30'), - firstHeight: createMetricPattern4(this, 'minute30_first_height'), + identity: createMetricPattern4(this, 'minute30_index'), + firstHeight: createMetricPattern4(this, 'first_height'), }, hour1: { - identity: createMetricPattern5(this, 'hour1'), - firstHeight: createMetricPattern5(this, 'hour1_first_height'), + identity: createMetricPattern5(this, 'hour1_index'), + firstHeight: createMetricPattern5(this, 'first_height'), }, hour4: { - identity: createMetricPattern6(this, 'hour4'), - firstHeight: createMetricPattern6(this, 'hour4_first_height'), + identity: createMetricPattern6(this, 'hour4_index'), + firstHeight: createMetricPattern6(this, 'first_height'), }, hour12: { - identity: createMetricPattern7(this, 'hour12'), - firstHeight: createMetricPattern7(this, 'hour12_first_height'), + identity: createMetricPattern7(this, 'hour12_index'), + firstHeight: createMetricPattern7(this, 'first_height'), }, day1: { - identity: createMetricPattern8(this, 'day1'), + identity: createMetricPattern8(this, 'day1_index'), date: createMetricPattern8(this, 'date'), firstHeight: createMetricPattern8(this, 'first_height'), heightCount: createMetricPattern8(this, 'height_count'), }, day3: { - identity: createMetricPattern9(this, 'day3'), - firstHeight: createMetricPattern9(this, 'day3_first_height'), + identity: createMetricPattern9(this, 'day3_index'), + firstHeight: createMetricPattern9(this, 'first_height'), }, week1: { - identity: createMetricPattern10(this, 'week1'), + identity: createMetricPattern10(this, 'week1_index'), date: createMetricPattern10(this, 'date'), - firstHeight: createMetricPattern10(this, 'week1_first_height'), + firstHeight: createMetricPattern10(this, 'first_height'), }, month1: { - identity: createMetricPattern11(this, 'month1'), + identity: createMetricPattern11(this, 'month1_index'), date: createMetricPattern11(this, 'date'), - firstHeight: createMetricPattern11(this, 'month1_first_height'), + firstHeight: createMetricPattern11(this, 'first_height'), }, month3: { - identity: createMetricPattern12(this, 'month3'), + identity: createMetricPattern12(this, 'month3_index'), date: createMetricPattern12(this, 'date'), - firstHeight: createMetricPattern12(this, 'month3_first_height'), + firstHeight: createMetricPattern12(this, 'first_height'), }, month6: { - identity: createMetricPattern13(this, 'month6'), + identity: createMetricPattern13(this, 'month6_index'), date: createMetricPattern13(this, 'date'), - firstHeight: createMetricPattern13(this, 'month6_first_height'), + firstHeight: createMetricPattern13(this, 'first_height'), }, year1: { - identity: createMetricPattern14(this, 'year1'), + identity: createMetricPattern14(this, 'year1_index'), date: createMetricPattern14(this, 'date'), - firstHeight: createMetricPattern14(this, 'year1_first_height'), + firstHeight: createMetricPattern14(this, 'first_height'), }, year10: { - identity: createMetricPattern15(this, 'year10'), + identity: createMetricPattern15(this, 'year10_index'), date: createMetricPattern15(this, 'date'), - firstHeight: createMetricPattern15(this, 'year10_first_height'), + firstHeight: createMetricPattern15(this, 'first_height'), }, txIndex: { identity: createMetricPattern19(this, 'tx_index'), @@ -7936,7 +7950,7 @@ class BrkClient extends BrkClientBase { supply: { circulating: createBtcCentsSatsUsdPattern(this, 'circulating_supply'), burned: { - opreturn: createBaseCumulativeSumPattern4(this, 'opreturn_supply'), + opReturn: createBaseCumulativeSumPattern4(this, 'op_return_supply'), unspendable: createBaseCumulativeSumPattern4(this, 'unspendable_supply'), }, inflationRate: createBpsPercentRatioPattern(this, 'inflation_rate'), diff --git a/packages/brk_client/brk_client/__init__.py b/packages/brk_client/brk_client/__init__.py index 2ab30bcf0..ff3898bbf 100644 --- a/packages/brk_client/brk_client/__init__.py +++ b/packages/brk_client/brk_client/__init__.py @@ -134,10 +134,10 @@ U8x2 = List[int] P2ABytes = U8x2 P2MSOutputIndex = TypeIndex P2PK33AddressIndex = TypeIndex -U8x33 = str +U8x33 = List[int] P2PK33Bytes = U8x33 P2PK65AddressIndex = TypeIndex -U8x65 = str +U8x65 = List[int] P2PK65Bytes = U8x65 P2PKHAddressIndex = TypeIndex U8x20 = List[int] @@ -3190,8 +3190,7 @@ class MetricsTree_Blocks_Difficulty: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.raw: MetricPattern18[StoredF64] = MetricPattern18(client, 'difficulty') - self.base: MetricPattern2[StoredF64] = MetricPattern2(client, 'difficulty') + self.value: MetricPattern1[StoredF64] = MetricPattern1(client, 'difficulty') self.as_hash: MetricPattern1[StoredF64] = MetricPattern1(client, 'difficulty_as_hash') self.adjustment: BpsPercentRatioPattern = BpsPercentRatioPattern(client, 'difficulty_adjustment') self.epoch: MetricPattern1[Epoch] = MetricPattern1(client, 'difficulty_epoch') @@ -3602,7 +3601,7 @@ class MetricsTree_Scripts_Raw_Empty: self.first_index: MetricPattern18[EmptyOutputIndex] = MetricPattern18(client, 'first_empty_output_index') self.to_tx_index: MetricPattern22[TxIndex] = MetricPattern22(client, 'tx_index') -class MetricsTree_Scripts_Raw_Opreturn: +class MetricsTree_Scripts_Raw_OpReturn: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): @@ -3628,7 +3627,7 @@ class MetricsTree_Scripts_Raw: def __init__(self, client: BrkClientBase, base_path: str = ''): self.empty: MetricsTree_Scripts_Raw_Empty = MetricsTree_Scripts_Raw_Empty(client) - self.opreturn: MetricsTree_Scripts_Raw_Opreturn = MetricsTree_Scripts_Raw_Opreturn(client) + self.op_return: MetricsTree_Scripts_Raw_OpReturn = MetricsTree_Scripts_Raw_OpReturn(client) self.p2ms: MetricsTree_Scripts_Raw_P2ms = MetricsTree_Scripts_Raw_P2ms(client) self.unknown: MetricsTree_Scripts_Raw_Unknown = MetricsTree_Scripts_Raw_Unknown(client) @@ -3645,23 +3644,23 @@ class MetricsTree_Scripts_Count: self.p2tr: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2tr_count') self.p2wpkh: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2wpkh_count') self.p2wsh: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'p2wsh_count') - self.opreturn: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'opreturn_count') + self.op_return: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'op_return_count') self.empty_output: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'empty_output_count') self.unknown_output: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'unknown_output_count') self.segwit: BaseCumulativeSumPattern[StoredU64] = BaseCumulativeSumPattern(client, 'segwit_count') -class MetricsTree_Scripts_Value_Opreturn: +class MetricsTree_Scripts_Value_OpReturn: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.base: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, 'opreturn_value') - self.cumulative: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, 'opreturn_value_cumulative') + self.base: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, 'op_return_value') + self.cumulative: BtcCentsSatsUsdPattern = BtcCentsSatsUsdPattern(client, 'op_return_value_cumulative') class MetricsTree_Scripts_Value: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.opreturn: MetricsTree_Scripts_Value_Opreturn = MetricsTree_Scripts_Value_Opreturn(client) + self.op_return: MetricsTree_Scripts_Value_OpReturn = MetricsTree_Scripts_Value_OpReturn(client) class MetricsTree_Scripts_Adoption: """Metrics tree node.""" @@ -3861,48 +3860,56 @@ class MetricsTree_Indexes_Address_P2pk33: def __init__(self, client: BrkClientBase, base_path: str = ''): self.identity: MetricPattern26[P2PK33AddressIndex] = MetricPattern26(client, 'p2pk33_address_index') + self.address: MetricPattern26[Address] = MetricPattern26(client, 'p2pk33_address') class MetricsTree_Indexes_Address_P2pk65: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): self.identity: MetricPattern27[P2PK65AddressIndex] = MetricPattern27(client, 'p2pk65_address_index') + self.address: MetricPattern27[Address] = MetricPattern27(client, 'p2pk65_address') class MetricsTree_Indexes_Address_P2pkh: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): self.identity: MetricPattern28[P2PKHAddressIndex] = MetricPattern28(client, 'p2pkh_address_index') + self.address: MetricPattern28[Address] = MetricPattern28(client, 'p2pkh_address') class MetricsTree_Indexes_Address_P2sh: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): self.identity: MetricPattern29[P2SHAddressIndex] = MetricPattern29(client, 'p2sh_address_index') + self.address: MetricPattern29[Address] = MetricPattern29(client, 'p2sh_address') class MetricsTree_Indexes_Address_P2tr: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): self.identity: MetricPattern30[P2TRAddressIndex] = MetricPattern30(client, 'p2tr_address_index') + self.address: MetricPattern30[Address] = MetricPattern30(client, 'p2tr_address') class MetricsTree_Indexes_Address_P2wpkh: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): self.identity: MetricPattern31[P2WPKHAddressIndex] = MetricPattern31(client, 'p2wpkh_address_index') + self.address: MetricPattern31[Address] = MetricPattern31(client, 'p2wpkh_address') class MetricsTree_Indexes_Address_P2wsh: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): self.identity: MetricPattern32[P2WSHAddressIndex] = MetricPattern32(client, 'p2wsh_address_index') + self.address: MetricPattern32[Address] = MetricPattern32(client, 'p2wsh_address') class MetricsTree_Indexes_Address_P2a: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): self.identity: MetricPattern24[P2AAddressIndex] = MetricPattern24(client, 'p2a_address_index') + self.address: MetricPattern24[Address] = MetricPattern24(client, 'p2a_address') class MetricsTree_Indexes_Address_P2ms: """Metrics tree node.""" @@ -3922,7 +3929,7 @@ class MetricsTree_Indexes_Address_Unknown: def __init__(self, client: BrkClientBase, base_path: str = ''): self.identity: MetricPattern33[UnknownOutputIndex] = MetricPattern33(client, 'unknown_output_index') -class MetricsTree_Indexes_Address_Opreturn: +class MetricsTree_Indexes_Address_OpReturn: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): @@ -3943,7 +3950,7 @@ class MetricsTree_Indexes_Address: self.p2ms: MetricsTree_Indexes_Address_P2ms = MetricsTree_Indexes_Address_P2ms(client) self.empty: MetricsTree_Indexes_Address_Empty = MetricsTree_Indexes_Address_Empty(client) self.unknown: MetricsTree_Indexes_Address_Unknown = MetricsTree_Indexes_Address_Unknown(client) - self.opreturn: MetricsTree_Indexes_Address_Opreturn = MetricsTree_Indexes_Address_Opreturn(client) + self.op_return: MetricsTree_Indexes_Address_OpReturn = MetricsTree_Indexes_Address_OpReturn(client) class MetricsTree_Indexes_Height: """Metrics tree node.""" @@ -3986,42 +3993,42 @@ class MetricsTree_Indexes_Minute10: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.identity: MetricPattern3[Minute10] = MetricPattern3(client, 'minute10') - self.first_height: MetricPattern3[Height] = MetricPattern3(client, 'minute10_first_height') + self.identity: MetricPattern3[Minute10] = MetricPattern3(client, 'minute10_index') + self.first_height: MetricPattern3[Height] = MetricPattern3(client, 'first_height') class MetricsTree_Indexes_Minute30: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.identity: MetricPattern4[Minute30] = MetricPattern4(client, 'minute30') - self.first_height: MetricPattern4[Height] = MetricPattern4(client, 'minute30_first_height') + self.identity: MetricPattern4[Minute30] = MetricPattern4(client, 'minute30_index') + self.first_height: MetricPattern4[Height] = MetricPattern4(client, 'first_height') class MetricsTree_Indexes_Hour1: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.identity: MetricPattern5[Hour1] = MetricPattern5(client, 'hour1') - self.first_height: MetricPattern5[Height] = MetricPattern5(client, 'hour1_first_height') + self.identity: MetricPattern5[Hour1] = MetricPattern5(client, 'hour1_index') + self.first_height: MetricPattern5[Height] = MetricPattern5(client, 'first_height') class MetricsTree_Indexes_Hour4: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.identity: MetricPattern6[Hour4] = MetricPattern6(client, 'hour4') - self.first_height: MetricPattern6[Height] = MetricPattern6(client, 'hour4_first_height') + self.identity: MetricPattern6[Hour4] = MetricPattern6(client, 'hour4_index') + self.first_height: MetricPattern6[Height] = MetricPattern6(client, 'first_height') class MetricsTree_Indexes_Hour12: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.identity: MetricPattern7[Hour12] = MetricPattern7(client, 'hour12') - self.first_height: MetricPattern7[Height] = MetricPattern7(client, 'hour12_first_height') + self.identity: MetricPattern7[Hour12] = MetricPattern7(client, 'hour12_index') + self.first_height: MetricPattern7[Height] = MetricPattern7(client, 'first_height') class MetricsTree_Indexes_Day1: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.identity: MetricPattern8[Day1] = MetricPattern8(client, 'day1') + self.identity: MetricPattern8[Day1] = MetricPattern8(client, 'day1_index') self.date: MetricPattern8[Date] = MetricPattern8(client, 'date') self.first_height: MetricPattern8[Height] = MetricPattern8(client, 'first_height') self.height_count: MetricPattern8[StoredU64] = MetricPattern8(client, 'height_count') @@ -4030,56 +4037,56 @@ class MetricsTree_Indexes_Day3: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.identity: MetricPattern9[Day3] = MetricPattern9(client, 'day3') - self.first_height: MetricPattern9[Height] = MetricPattern9(client, 'day3_first_height') + self.identity: MetricPattern9[Day3] = MetricPattern9(client, 'day3_index') + self.first_height: MetricPattern9[Height] = MetricPattern9(client, 'first_height') class MetricsTree_Indexes_Week1: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.identity: MetricPattern10[Week1] = MetricPattern10(client, 'week1') + self.identity: MetricPattern10[Week1] = MetricPattern10(client, 'week1_index') self.date: MetricPattern10[Date] = MetricPattern10(client, 'date') - self.first_height: MetricPattern10[Height] = MetricPattern10(client, 'week1_first_height') + self.first_height: MetricPattern10[Height] = MetricPattern10(client, 'first_height') class MetricsTree_Indexes_Month1: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.identity: MetricPattern11[Month1] = MetricPattern11(client, 'month1') + self.identity: MetricPattern11[Month1] = MetricPattern11(client, 'month1_index') self.date: MetricPattern11[Date] = MetricPattern11(client, 'date') - self.first_height: MetricPattern11[Height] = MetricPattern11(client, 'month1_first_height') + self.first_height: MetricPattern11[Height] = MetricPattern11(client, 'first_height') class MetricsTree_Indexes_Month3: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.identity: MetricPattern12[Month3] = MetricPattern12(client, 'month3') + self.identity: MetricPattern12[Month3] = MetricPattern12(client, 'month3_index') self.date: MetricPattern12[Date] = MetricPattern12(client, 'date') - self.first_height: MetricPattern12[Height] = MetricPattern12(client, 'month3_first_height') + self.first_height: MetricPattern12[Height] = MetricPattern12(client, 'first_height') class MetricsTree_Indexes_Month6: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.identity: MetricPattern13[Month6] = MetricPattern13(client, 'month6') + self.identity: MetricPattern13[Month6] = MetricPattern13(client, 'month6_index') self.date: MetricPattern13[Date] = MetricPattern13(client, 'date') - self.first_height: MetricPattern13[Height] = MetricPattern13(client, 'month6_first_height') + self.first_height: MetricPattern13[Height] = MetricPattern13(client, 'first_height') class MetricsTree_Indexes_Year1: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.identity: MetricPattern14[Year1] = MetricPattern14(client, 'year1') + self.identity: MetricPattern14[Year1] = MetricPattern14(client, 'year1_index') self.date: MetricPattern14[Date] = MetricPattern14(client, 'date') - self.first_height: MetricPattern14[Height] = MetricPattern14(client, 'year1_first_height') + self.first_height: MetricPattern14[Height] = MetricPattern14(client, 'first_height') class MetricsTree_Indexes_Year10: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.identity: MetricPattern15[Year10] = MetricPattern15(client, 'year10') + self.identity: MetricPattern15[Year10] = MetricPattern15(client, 'year10_index') self.date: MetricPattern15[Date] = MetricPattern15(client, 'date') - self.first_height: MetricPattern15[Height] = MetricPattern15(client, 'year10_first_height') + self.first_height: MetricPattern15[Height] = MetricPattern15(client, 'first_height') class MetricsTree_Indexes_TxIndex: """Metrics tree node.""" @@ -4767,7 +4774,7 @@ class MetricsTree_Supply_Burned: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.opreturn: BaseCumulativeSumPattern4 = BaseCumulativeSumPattern4(client, 'opreturn_supply') + self.op_return: BaseCumulativeSumPattern4 = BaseCumulativeSumPattern4(client, 'op_return_supply') self.unspendable: BaseCumulativeSumPattern4 = BaseCumulativeSumPattern4(client, 'unspendable_supply') class MetricsTree_Supply_Velocity: diff --git a/website/scripts/options/investing.js b/website/scripts/options/investing.js index ad7a066e6..f48ce5030 100644 --- a/website/scripts/options/investing.js +++ b/website/scripts/options/investing.js @@ -2,8 +2,7 @@ import { colors } from "../utils/colors.js"; import { brk } from "../client.js"; -import { Unit } from "../utils/units.js"; -import { baseline, price } from "./series.js"; +import { percentRatioBaseline, price } from "./series.js"; import { satsBtcUsd } from "./shared.js"; import { periodIdToName } from "./utils.js"; @@ -31,7 +30,7 @@ const LONG_PERIODS = /** @type {const} */ ([ /** * Add CAGR to a base entry item * @param {BaseEntryItem} entry - * @param {AnyMetricPattern} cagr + * @param {PercentRatioPattern} cagr * @returns {LongEntryItem} */ const withCagr = (entry, cagr) => ({ ...entry, cagr }); @@ -47,19 +46,23 @@ const YEARS_2010S = /** @type {const} */ ([2019, 2018, 2017, 2016, 2015]); /** @param {AllPeriodKey} key */ const periodName = (key) => periodIdToName(key.slice(1), true); +/** + * @typedef {{ percent: AnyMetricPattern, ratio: AnyMetricPattern }} PercentRatioPattern + */ + /** * Base entry item for compare and single-entry charts * @typedef {Object} BaseEntryItem * @property {string} name - Display name * @property {Color} color - Item color * @property {AnyPricePattern} costBasis - Cost basis metric - * @property {AnyMetricPattern} returns - Returns metric + * @property {PercentRatioPattern} returns - Returns metric * @property {AnyValuePattern} stack - Stack pattern */ /** * Long-term entry item with CAGR - * @typedef {BaseEntryItem & { cagr: AnyMetricPattern }} LongEntryItem + * @typedef {BaseEntryItem & { cagr: PercentRatioPattern }} LongEntryItem */ const ALL_YEARS = /** @type {const} */ ([...YEARS_2020S, ...YEARS_2010S]); @@ -77,7 +80,7 @@ function buildYearEntry(dca, year, i) { name: `${year}`, color: colors.at(i, ALL_YEARS.length), costBasis: dca.class.costBasis[key], - returns: dca.class.return[key].ratio, + returns: dca.class.return[key], stack: dca.class.stack[key], }; } @@ -122,12 +125,11 @@ function createCompareFolder(context, items) { name: "Returns", title: `Returns: ${context}`, top: topPane, - bottom: items.map(({ name, color, returns }) => - baseline({ - metric: returns, + bottom: items.flatMap(({ name, color, returns }) => + percentRatioBaseline({ + pattern: returns, name, color: [color, color], - unit: Unit.percentage, }), ), }, @@ -176,9 +178,7 @@ function createSingleEntryTree(item, returnsBottom) { * @param {BaseEntryItem & { titlePrefix?: string }} item */ function createShortSingleEntry(item) { - return createSingleEntryTree(item, [ - baseline({ metric: item.returns, name: "Current", unit: Unit.percentage }), - ]); + return createSingleEntryTree(item, percentRatioBaseline({ pattern: item.returns, name: "Current" })); } /** @@ -187,8 +187,8 @@ function createShortSingleEntry(item) { */ function createLongSingleEntry(item) { return createSingleEntryTree(item, [ - baseline({ metric: item.returns, name: "Current", unit: Unit.percentage }), - baseline({ metric: item.cagr, name: "CAGR", unit: Unit.cagr }), + ...percentRatioBaseline({ pattern: item.returns, name: "Current" }), + ...percentRatioBaseline({ pattern: item.cagr, name: "CAGR" }), ]); } @@ -223,16 +223,14 @@ export function createDcaVsLumpSumSection({ dca, lookback, returns }) { title: `Returns: ${name} DCA vs Lump Sum`, top: topPane(key), bottom: [ - baseline({ - metric: dca.period.return[key].ratio, + ...percentRatioBaseline({ + pattern: dca.period.return[key], name: "DCA", - unit: Unit.percentage, }), - baseline({ - metric: dca.period.lumpSumReturn[key].ratio, + ...percentRatioBaseline({ + pattern: dca.period.lumpSumReturn[key], name: "Lump Sum", color: colors.bi.p2, - unit: Unit.percentage, }), ], }); @@ -243,27 +241,23 @@ export function createDcaVsLumpSumSection({ dca, lookback, returns }) { title: `Returns: ${name} DCA vs Lump Sum`, top: topPane(key), bottom: [ - baseline({ - metric: dca.period.return[key].ratio, + ...percentRatioBaseline({ + pattern: dca.period.return[key], name: "DCA", - unit: Unit.percentage, }), - baseline({ - metric: dca.period.lumpSumReturn[key].ratio, + ...percentRatioBaseline({ + pattern: dca.period.lumpSumReturn[key], name: "Lump Sum", color: colors.bi.p2, - unit: Unit.percentage, }), - baseline({ - metric: dca.period.cagr[key].ratio, + ...percentRatioBaseline({ + pattern: dca.period.cagr[key], name: "DCA CAGR", - unit: Unit.cagr, }), - baseline({ - metric: returns.cagr[key].ratio, + ...percentRatioBaseline({ + pattern: returns.cagr[key], name: "Lump Sum CAGR", color: colors.bi.p2, - unit: Unit.cagr, }), ], }); @@ -350,8 +344,8 @@ function createPeriodSection({ dca, lookback, returns }) { color: colors.at(i, allPeriods.length), costBasis: isLumpSum ? lookback[key] : dca.period.costBasis[key], returns: isLumpSum - ? dca.period.lumpSumReturn[key].ratio - : dca.period.return[key].ratio, + ? dca.period.lumpSumReturn[key] + : dca.period.return[key], stack: isLumpSum ? dca.period.lumpSumStack[key] : dca.period.stack[key], @@ -361,7 +355,7 @@ function createPeriodSection({ dca, lookback, returns }) { const buildLongEntry = (key, i) => withCagr( buildBaseEntry(key, i), - isLumpSum ? returns.cagr[key].ratio : dca.period.cagr[key].ratio, + isLumpSum ? returns.cagr[key] : dca.period.cagr[key], ); /** @param {BaseEntryItem} entry */ diff --git a/website/scripts/options/market.js b/website/scripts/options/market.js index d408c8d51..4fd87e1aa 100644 --- a/website/scripts/options/market.js +++ b/website/scripts/options/market.js @@ -122,21 +122,18 @@ function returnsSubSection(name, periods) { { name: "Compare", title: `${name} Returns`, - bottom: periods.map((p) => - baseline({ - metric: p.returns, + bottom: periods.flatMap((p) => + percentRatioBaseline({ + pattern: p.returns, name: p.id, color: p.color, - unit: Unit.percentage, }), ), }, ...periods.map((p) => ({ name: periodIdToName(p.id, true), title: `${periodIdToName(p.id, true)} Returns`, - bottom: [ - baseline({ metric: p.returns, name: "Total", unit: Unit.percentage }), - ], + bottom: percentRatioBaseline({ pattern: p.returns, name: "Total" }), })), ], }; @@ -153,12 +150,11 @@ function returnsSubSectionWithCagr(name, periods) { { name: "Compare", title: `${name} Returns`, - bottom: periods.map((p) => - baseline({ - metric: p.returns, + bottom: periods.flatMap((p) => + percentRatioBaseline({ + pattern: p.returns, name: p.id, color: p.color, - unit: Unit.percentage, }), ), }, @@ -166,8 +162,8 @@ function returnsSubSectionWithCagr(name, periods) { name: periodIdToName(p.id, true), title: `${periodIdToName(p.id, true)} Returns`, bottom: [ - baseline({ metric: p.returns, name: "Total", unit: Unit.percentage }), - baseline({ metric: p.cagr, name: "annual", unit: Unit.cagr }), + ...percentRatioBaseline({ pattern: p.returns, name: "Total" }), + ...percentRatioBaseline({ pattern: p.cagr, name: "annual" }), ], })), ], @@ -216,70 +212,70 @@ export function createMarketSection() { } = market; const shortPeriodsBase = [ - { id: "24h", returns: returns.periods._24h.ratio, lookback: lookback._24h }, - { id: "1w", returns: returns.periods._1w.ratio, lookback: lookback._1w }, - { id: "1m", returns: returns.periods._1m.ratio, lookback: lookback._1m }, + { id: "24h", returns: returns.periods._24h, lookback: lookback._24h }, + { id: "1w", returns: returns.periods._1w, lookback: lookback._1w }, + { id: "1m", returns: returns.periods._1m, lookback: lookback._1m }, { id: "3m", - returns: returns.periods._3m.ratio, + returns: returns.periods._3m, lookback: lookback._3m, defaultActive: false, }, { id: "6m", - returns: returns.periods._6m.ratio, + returns: returns.periods._6m, lookback: lookback._6m, defaultActive: false, }, - { id: "1y", returns: returns.periods._1y.ratio, lookback: lookback._1y }, + { id: "1y", returns: returns.periods._1y, lookback: lookback._1y }, ]; const longPeriodsBase = [ { id: "2y", - returns: returns.periods._2y.ratio, - cagr: returns.cagr._2y.ratio, + returns: returns.periods._2y, + cagr: returns.cagr._2y, lookback: lookback._2y, defaultActive: false, }, { id: "3y", - returns: returns.periods._3y.ratio, - cagr: returns.cagr._3y.ratio, + returns: returns.periods._3y, + cagr: returns.cagr._3y, lookback: lookback._3y, defaultActive: false, }, { id: "4y", - returns: returns.periods._4y.ratio, - cagr: returns.cagr._4y.ratio, + returns: returns.periods._4y, + cagr: returns.cagr._4y, lookback: lookback._4y, }, { id: "5y", - returns: returns.periods._5y.ratio, - cagr: returns.cagr._5y.ratio, + returns: returns.periods._5y, + cagr: returns.cagr._5y, lookback: lookback._5y, defaultActive: false, }, { id: "6y", - returns: returns.periods._6y.ratio, - cagr: returns.cagr._6y.ratio, + returns: returns.periods._6y, + cagr: returns.cagr._6y, lookback: lookback._6y, defaultActive: false, }, { id: "8y", - returns: returns.periods._8y.ratio, - cagr: returns.cagr._8y.ratio, + returns: returns.periods._8y, + cagr: returns.cagr._8y, lookback: lookback._8y, defaultActive: false, }, { id: "10y", - returns: returns.periods._10y.ratio, - cagr: returns.cagr._10y.ratio, + returns: returns.periods._10y, + cagr: returns.cagr._10y, lookback: lookback._10y, defaultActive: false, }, @@ -426,11 +422,10 @@ export function createMarketSection() { name: "Growth Rate", title: "Capitalization Growth Rate", bottom: [ - line({ - metric: supply.marketCap.delta.rate._24h.percent, + ...percentRatio({ + pattern: supply.marketCap.delta.rate._24h, name: "Market Cap (24h)", color: colors.bitcoin, - unit: Unit.percentage, }), baseline({ metric: supply.marketMinusRealizedCapGrowthRate._24h, @@ -493,12 +488,11 @@ export function createMarketSection() { { name: "Compare", title: "Returns Comparison", - bottom: [...shortPeriods, ...longPeriods].map((p) => - baseline({ - metric: p.returns, + bottom: [...shortPeriods, ...longPeriods].flatMap((p) => + percentRatioBaseline({ + pattern: p.returns, name: p.id, color: p.color, - unit: Unit.percentage, defaultActive: p.defaultActive, }), ), diff --git a/website/scripts/options/mining.js b/website/scripts/options/mining.js index 18fcf9f3d..2b5350c2a 100644 --- a/website/scripts/options/mining.js +++ b/website/scripts/options/mining.js @@ -320,7 +320,7 @@ export function createMiningSection() { title: "Mining Difficulty", bottom: [ line({ - metric: blocks.difficulty.raw, + metric: blocks.difficulty.value, name: "Difficulty", unit: Unit.difficulty, }), diff --git a/website/scripts/options/network.js b/website/scripts/options/network.js index 1ee18d645..300e7bb20 100644 --- a/website/scripts/options/network.js +++ b/website/scripts/options/network.js @@ -58,9 +58,9 @@ export function createNetworkSection() { const nonAddressableTypes = /** @type {const} */ ([ { key: "p2ms", name: "P2MS", color: st.p2ms, defaultActive: false }, { - key: "opreturn", + key: "opReturn", name: "OP_RETURN", - color: st.opreturn, + color: st.opReturn, defaultActive: false, }, { @@ -568,7 +568,7 @@ export function createNetworkSection() { name: "Base", title: "OP_RETURN Burned", bottom: satsBtcUsd({ - pattern: supply.burned.opreturn.base, + pattern: supply.burned.opReturn.base, name: "sum", }), }, @@ -580,7 +580,7 @@ export function createNetworkSection() { title: "OP_RETURN Burned Rolling", bottom: ROLLING_WINDOWS.flatMap((w) => satsBtcUsd({ - pattern: supply.burned.opreturn.sum[w.key], + pattern: supply.burned.opReturn.sum[w.key], name: w.name, color: w.color, }), @@ -590,7 +590,7 @@ export function createNetworkSection() { name: w.name, title: `OP_RETURN Burned ${w.name}`, bottom: satsBtcUsd({ - pattern: supply.burned.opreturn.sum[w.key], + pattern: supply.burned.opReturn.sum[w.key], name: w.name, color: w.color, }), @@ -601,7 +601,7 @@ export function createNetworkSection() { name: "Cumulative", title: "OP_RETURN Burned (Total)", bottom: satsBtcUsd({ - pattern: supply.burned.opreturn.cumulative, + pattern: supply.burned.opReturn.cumulative, name: "all-time", }), }, @@ -1035,7 +1035,7 @@ export function createNetworkSection() { title: "Mining Difficulty", bottom: [ line({ - metric: blocks.difficulty.base, + metric: blocks.difficulty.value, name: "Difficulty", unit: Unit.count, }), diff --git a/website/scripts/options/series.js b/website/scripts/options/series.js index 6ea5fc08c..e2ec14125 100644 --- a/website/scripts/options/series.js +++ b/website/scripts/options/series.js @@ -640,7 +640,7 @@ export function percentRatioDots({ pattern, name, color, defaultActive }) { * @param {Object} args * @param {{ percent: AnyMetricPattern, ratio: AnyMetricPattern }} args.pattern * @param {string} args.name - * @param {Color} [args.color] + * @param {Color | [Color, Color]} [args.color] * @param {boolean} [args.defaultActive] * @returns {AnyFetchedSeriesBlueprint[]} */ diff --git a/website/scripts/utils/colors.js b/website/scripts/utils/colors.js index 706ed0f24..05fd2cb25 100644 --- a/website/scripts/utils/colors.js +++ b/website/scripts/utils/colors.js @@ -254,7 +254,7 @@ export const colors = { p2wsh: palette.yellow, p2tr: palette.cyan, p2a: palette.indigo, - opreturn: palette.purple, + opReturn: palette.purple, unknown: palette.violet, empty: palette.fuchsia, },