From dc86514329e6232e03e022e6fb8e49037ea35e9b Mon Sep 17 00:00:00 2001 From: nym21 Date: Tue, 25 Nov 2025 17:21:07 +0100 Subject: [PATCH] global: snapshot --- Cargo.lock | 18 +- Cargo.toml | 3 +- crates/brk_computer/Cargo.toml | 1 - crates/brk_computer/src/blks.rs | 19 +- crates/brk_computer/src/grouped/computed.rs | 6 +- crates/brk_computer/src/stateful/range_map.rs | 14 +- .../src/states/price_to_amount.rs | 10 +- crates/brk_computer/src/states/supply.rs | 3 +- crates/brk_error/Cargo.toml | 1 - crates/brk_error/src/lib.rs | 14 -- crates/brk_indexer/src/lib.rs | 52 ++--- crates/brk_indexer/src/vecs.rs | 204 +++++++++--------- crates/brk_traversable/Cargo.toml | 4 + crates/brk_traversable/src/lib.rs | 79 ++++--- crates/brk_types/Cargo.toml | 1 - crates/brk_types/src/addresshash.rs | 22 +- crates/brk_types/src/addressindexoutpoint.rs | 10 +- crates/brk_types/src/addressindextxindex.rs | 29 +-- crates/brk_types/src/anyaddressindex.rs | 14 +- crates/brk_types/src/bitcoin.rs | 5 +- crates/brk_types/src/blkposition.rs | 3 +- crates/brk_types/src/blockhash.rs | 7 +- crates/brk_types/src/blockhashprefix.rs | 23 +- crates/brk_types/src/bytes.rs | 87 +------- crates/brk_types/src/cents.rs | 18 +- crates/brk_types/src/date.rs | 16 +- crates/brk_types/src/dateindex.rs | 18 +- crates/brk_types/src/decadeindex.rs | 17 +- crates/brk_types/src/difficultyepoch.rs | 17 +- crates/brk_types/src/dollars.rs | 17 +- crates/brk_types/src/emptyaddressdata.rs | 3 +- crates/brk_types/src/emptyaddressindex.rs | 19 +- crates/brk_types/src/emptyoutputindex.rs | 18 +- crates/brk_types/src/feerate.rs | 3 +- crates/brk_types/src/halvingepoch.rs | 17 +- crates/brk_types/src/height.rs | 15 +- crates/brk_types/src/lib.rs | 41 ---- crates/brk_types/src/loadedaddressdata.rs | 3 +- crates/brk_types/src/loadedaddressindex.rs | 19 +- crates/brk_types/src/monthindex.rs | 17 +- crates/brk_types/src/ohlc.rs | 75 +------ crates/brk_types/src/opreturnindex.rs | 18 +- crates/brk_types/src/outpoint.rs | 18 +- crates/brk_types/src/outputtype.rs | 44 ++-- crates/brk_types/src/p2aaddressindex.rs | 18 +- crates/brk_types/src/p2abytes.rs | 19 +- crates/brk_types/src/p2msoutputindex.rs | 18 +- crates/brk_types/src/p2pk33addressindex.rs | 18 +- crates/brk_types/src/p2pk33bytes.rs | 19 +- crates/brk_types/src/p2pk65addressindex.rs | 18 +- crates/brk_types/src/p2pk65bytes.rs | 19 +- crates/brk_types/src/p2pkhaddressindex.rs | 18 +- crates/brk_types/src/p2pkhbytes.rs | 19 +- crates/brk_types/src/p2shaddressindex.rs | 18 +- crates/brk_types/src/p2shbytes.rs | 19 +- crates/brk_types/src/p2traddressindex.rs | 18 +- crates/brk_types/src/p2trbytes.rs | 19 +- crates/brk_types/src/p2wpkhaddressindex.rs | 18 +- crates/brk_types/src/p2wpkhbytes.rs | 19 +- crates/brk_types/src/p2wshaddressindex.rs | 18 +- crates/brk_types/src/p2wshbytes.rs | 19 +- crates/brk_types/src/poolid.rs | 5 - crates/brk_types/src/quarterindex.rs | 17 +- crates/brk_types/src/rawlocktime.rs | 5 +- crates/brk_types/src/sats.rs | 5 - crates/brk_types/src/semesterindex.rs | 17 +- crates/brk_types/src/stored_bool.rs | 19 +- crates/brk_types/src/stored_f32.rs | 5 +- crates/brk_types/src/stored_f64.rs | 5 +- crates/brk_types/src/stored_i16.rs | 19 +- crates/brk_types/src/stored_u16.rs | 19 +- crates/brk_types/src/stored_u32.rs | 19 +- crates/brk_types/src/stored_u64.rs | 19 +- crates/brk_types/src/stored_u8.rs | 18 +- crates/brk_types/src/timestamp.rs | 19 +- crates/brk_types/src/txid.rs | 17 +- crates/brk_types/src/txidprefix.rs | 23 +- crates/brk_types/src/txindex.rs | 16 +- crates/brk_types/src/txinindex.rs | 18 +- crates/brk_types/src/txoutindex.rs | 27 +-- crates/brk_types/src/txversion.rs | 19 +- crates/brk_types/src/typeindex.rs | 16 +- crates/brk_types/src/unknownoutputindex.rs | 18 +- crates/brk_types/src/vout.rs | 17 +- crates/brk_types/src/weekindex.rs | 17 +- crates/brk_types/src/weight.rs | 19 +- crates/brk_types/src/yearindex.rs | 17 +- 87 files changed, 335 insertions(+), 1436 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b04b15b5a..62d9c67a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -633,7 +633,6 @@ dependencies = [ "serde", "smallvec", "vecdb", - "zerocopy", ] [[package]] @@ -649,7 +648,6 @@ dependencies = [ "serde_json", "tokio", "vecdb", - "zerocopy", ] [[package]] @@ -1296,7 +1294,6 @@ dependencies = [ "serde_json", "strum", "vecdb", - "zerocopy", ] [[package]] @@ -2121,7 +2118,7 @@ dependencies = [ "flume", "log", "lsm-tree 3.0.0-rc.0", - "lz4_flex", + "lz4_flex 0.11.5", "tempfile", "xxhash-rust", ] @@ -2998,7 +2995,7 @@ dependencies = [ "guardian", "interval-heap", "log", - "lz4_flex", + "lz4_flex 0.11.5", "path-absolutize", "quick_cache", "rustc-hash", @@ -3021,7 +3018,7 @@ dependencies = [ "enum_dispatch", "interval-heap", "log", - "lz4_flex", + "lz4_flex 0.11.5", "quick_cache", "rustc-hash", "self_cell", @@ -3040,6 +3037,12 @@ dependencies = [ "twox-hash", ] +[[package]] +name = "lz4_flex" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab6473172471198271ff72e9379150e9dfd70d8e533e0752a27e515b48dd375e" + [[package]] name = "matchit" version = "0.8.4" @@ -5440,6 +5443,7 @@ version = "0.3.20" dependencies = [ "ctrlc", "log", + "lz4_flex 0.12.0", "parking_lot", "pco", "rawdb", @@ -5447,6 +5451,8 @@ dependencies = [ "serde_json", "thiserror 2.0.17", "vecdb_derive", + "zerocopy", + "zstd", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index e8158b45a..5252eb710 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,7 +56,7 @@ brk_rpc = { version = "0.0.111", path = "crates/brk_rpc" } brk_server = { version = "0.0.111", path = "crates/brk_server" } brk_store = { version = "0.0.111", path = "crates/brk_store" } brk_types = { version = "0.0.111", path = "crates/brk_types" } -brk_traversable = { version = "0.0.111", path = "crates/brk_traversable", features = ["derive"] } +brk_traversable = { version = "0.0.111", path = "crates/brk_traversable", features = ["pco", "derive"] } brk_traversable_derive = { version = "0.0.111", path = "crates/brk_traversable_derive" } byteview = "=0.6.1" # byteview = "~0.8.0" @@ -81,7 +81,6 @@ serde_json = { version = "1.0.145", features = ["float_roundtrip"] } tokio = { version = "1.48.0", features = ["rt-multi-thread"] } vecdb = { path = "../anydb/crates/vecdb", features = ["derive", "serde_json", "pco"] } # vecdb = { version = "0.3.20", features = ["derive"] } -zerocopy = { version = "0.8.30", features = ["derive"] } [workspace.metadata.release] shared-version = true diff --git a/crates/brk_computer/Cargo.toml b/crates/brk_computer/Cargo.toml index eb8db8122..25873accd 100644 --- a/crates/brk_computer/Cargo.toml +++ b/crates/brk_computer/Cargo.toml @@ -31,4 +31,3 @@ rustc-hash = { workspace = true } serde = { workspace = true } smallvec = "1.15.1" vecdb = { workspace = true } -zerocopy = { workspace = true } diff --git a/crates/brk_computer/src/blks.rs b/crates/brk_computer/src/blks.rs index f0bcb6ebe..92629c0b1 100644 --- a/crates/brk_computer/src/blks.rs +++ b/crates/brk_computer/src/blks.rs @@ -6,8 +6,7 @@ use brk_reader::Reader; use brk_traversable::Traversable; use brk_types::{BlkPosition, Height, TxIndex, Version}; use vecdb::{ - AnyStoredVec, AnyVec, CompressedVec, Database, Exit, GenericStoredVec, PAGE_SIZE, - TypedVecIterator, + AnyStoredVec, AnyVec, Database, Exit, GenericStoredVec, PAGE_SIZE, PcoVec, TypedVecIterator, }; use super::Indexes; @@ -16,8 +15,8 @@ use super::Indexes; pub struct Vecs { db: Database, - pub height_to_position: CompressedVec, - pub txindex_to_position: CompressedVec, + pub height_to_position: PcoVec, + pub txindex_to_position: PcoVec, } impl Vecs { @@ -28,16 +27,8 @@ impl Vecs { let version = parent_version + Version::ZERO; let this = Self { - height_to_position: CompressedVec::forced_import( - &db, - "position", - version + Version::TWO, - )?, - txindex_to_position: CompressedVec::forced_import( - &db, - "position", - version + Version::TWO, - )?, + height_to_position: PcoVec::forced_import(&db, "position", version + Version::TWO)?, + txindex_to_position: PcoVec::forced_import(&db, "position", version + Version::TWO)?, db, }; diff --git a/crates/brk_computer/src/grouped/computed.rs b/crates/brk_computer/src/grouped/computed.rs index 564e35039..9b15558d3 100644 --- a/crates/brk_computer/src/grouped/computed.rs +++ b/crates/brk_computer/src/grouped/computed.rs @@ -1,10 +1,10 @@ use std::ops::{Add, AddAssign, Div}; -use vecdb::{Formattable, Pco}; +use vecdb::{Formattable, PcoVecValue}; pub trait ComputedVecValue where - Self: Pco + Self: PcoVecValue + From + Div + Add @@ -14,7 +14,7 @@ where { } impl ComputedVecValue for T where - T: Pco + T: PcoVecValue + From + Div + Add diff --git a/crates/brk_computer/src/stateful/range_map.rs b/crates/brk_computer/src/stateful/range_map.rs index 379ace61e..87076dc32 100644 --- a/crates/brk_computer/src/stateful/range_map.rs +++ b/crates/brk_computer/src/stateful/range_map.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use vecdb::{CompressedVec, Pco, RawVec, VecIndex, VecValue}; +use vecdb::{BytesVec, BytesVecValue, PcoVec, PcoVecValue, VecIndex}; #[derive(Debug)] pub struct RangeMap(BTreeMap); @@ -20,13 +20,13 @@ where } } -impl From<&RawVec> for RangeMap +impl From<&BytesVec> for RangeMap where I: VecIndex, - T: VecIndex + VecValue, + T: VecIndex + BytesVecValue, { #[inline] - fn from(vec: &RawVec) -> Self { + fn from(vec: &BytesVec) -> Self { Self( vec.into_iter() .enumerate() @@ -36,13 +36,13 @@ where } } -impl From<&CompressedVec> for RangeMap +impl From<&PcoVec> for RangeMap where I: VecIndex, - T: VecIndex + Pco, + T: VecIndex + PcoVecValue, { #[inline] - fn from(vec: &CompressedVec) -> Self { + fn from(vec: &PcoVec) -> Self { Self( vec.into_iter() .enumerate() diff --git a/crates/brk_computer/src/states/price_to_amount.rs b/crates/brk_computer/src/states/price_to_amount.rs index 177e9bf4a..995fedad2 100644 --- a/crates/brk_computer/src/states/price_to_amount.rs +++ b/crates/brk_computer/src/states/price_to_amount.rs @@ -9,7 +9,7 @@ use brk_types::{Dollars, Height, Sats}; use derive_deref::{Deref, DerefMut}; use pco::standalone::{simple_decompress, simpler_compress}; use serde::{Deserialize, Serialize}; -use zerocopy::{FromBytes, IntoBytes}; +use vecdb::Bytes; use crate::states::SupplyState; @@ -143,8 +143,8 @@ impl State { let compressed_values = simpler_compress(&values, COMPRESSION_LEVEL)?; let mut buffer = Vec::new(); - buffer.extend(keys.len().as_bytes()); - buffer.extend(compressed_keys.len().as_bytes()); + buffer.extend(keys.len().to_bytes()); + buffer.extend(compressed_keys.len().to_bytes()); buffer.extend(compressed_keys); buffer.extend(compressed_values); @@ -152,8 +152,8 @@ impl State { } fn deserialize(data: &[u8]) -> vecdb::Result { - let entry_count = usize::read_from_bytes(&data[0..8])?; - let keys_len = usize::read_from_bytes(&data[8..16])?; + let entry_count = usize::from_bytes(&data[0..8])?; + let keys_len = usize::from_bytes(&data[8..16])?; let keys: Vec = simple_decompress(&data[16..16 + keys_len])?; let values: Vec = simple_decompress(&data[16 + keys_len..])?; diff --git a/crates/brk_computer/src/states/supply.rs b/crates/brk_computer/src/states/supply.rs index 99abddfcf..d9aa61cf1 100644 --- a/crates/brk_computer/src/states/supply.rs +++ b/crates/brk_computer/src/states/supply.rs @@ -3,9 +3,8 @@ use std::ops::{Add, AddAssign, SubAssign}; use brk_types::{CheckedSub, LoadedAddressData, Sats}; use serde::Serialize; use vecdb::Formattable; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; -#[derive(Debug, Default, Clone, FromBytes, Immutable, IntoBytes, KnownLayout, Serialize)] +#[derive(Debug, Default, Clone, Serialize)] pub struct SupplyState { pub utxo_count: u64, pub value: Sats, diff --git a/crates/brk_error/Cargo.toml b/crates/brk_error/Cargo.toml index 9256ba948..7afb14222 100644 --- a/crates/brk_error/Cargo.toml +++ b/crates/brk_error/Cargo.toml @@ -19,4 +19,3 @@ minreq = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true } vecdb = { workspace = true } -zerocopy = { workspace = true } diff --git a/crates/brk_error/src/lib.rs b/crates/brk_error/src/lib.rs index 075b17958..713edb4ce 100644 --- a/crates/brk_error/src/lib.rs +++ b/crates/brk_error/src/lib.rs @@ -163,20 +163,6 @@ impl From<&'static str> for Error { } } -impl From> for Error { - #[inline] - fn from(_: zerocopy::error::ConvertError) -> Self { - Self::ZeroCopyError - } -} - -impl From> for Error { - #[inline] - fn from(_: zerocopy::error::SizeError) -> Self { - Self::ZeroCopyError - } -} - impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { diff --git a/crates/brk_indexer/src/lib.rs b/crates/brk_indexer/src/lib.rs index ac0f150ed..f75bfe851 100644 --- a/crates/brk_indexer/src/lib.rs +++ b/crates/brk_indexer/src/lib.rs @@ -756,47 +756,39 @@ enum InputSource<'a> { } struct Readers { - txindex_to_first_txoutindex: Reader<'static>, - txoutindex_to_outputtype: Reader<'static>, - txoutindex_to_typeindex: Reader<'static>, - p2pk65addressindex_to_p2pk65bytes: Reader<'static>, - p2pk33addressindex_to_p2pk33bytes: Reader<'static>, - p2pkhaddressindex_to_p2pkhbytes: Reader<'static>, - p2shaddressindex_to_p2shbytes: Reader<'static>, - p2wpkhaddressindex_to_p2wpkhbytes: Reader<'static>, - p2wshaddressindex_to_p2wshbytes: Reader<'static>, - p2traddressindex_to_p2trbytes: Reader<'static>, - p2aaddressindex_to_p2abytes: Reader<'static>, + txindex_to_first_txoutindex: Reader, + txoutindex_to_outputtype: Reader, + txoutindex_to_typeindex: Reader, + p2pk65addressindex_to_p2pk65bytes: Reader, + p2pk33addressindex_to_p2pk33bytes: Reader, + p2pkhaddressindex_to_p2pkhbytes: Reader, + p2shaddressindex_to_p2shbytes: Reader, + p2wpkhaddressindex_to_p2wpkhbytes: Reader, + p2wshaddressindex_to_p2wshbytes: Reader, + p2traddressindex_to_p2trbytes: Reader, + p2aaddressindex_to_p2abytes: Reader, } impl Readers { fn new(vecs: &Vecs) -> Self { Self { - txindex_to_first_txoutindex: vecs.txindex_to_first_txoutindex.create_static_reader(), - txoutindex_to_outputtype: vecs.txoutindex_to_outputtype.create_static_reader(), - txoutindex_to_typeindex: vecs.txoutindex_to_typeindex.create_static_reader(), + txindex_to_first_txoutindex: vecs.txindex_to_first_txoutindex.create_reader(), + txoutindex_to_outputtype: vecs.txoutindex_to_outputtype.create_reader(), + txoutindex_to_typeindex: vecs.txoutindex_to_typeindex.create_reader(), p2pk65addressindex_to_p2pk65bytes: vecs .p2pk65addressindex_to_p2pk65bytes - .create_static_reader(), + .create_reader(), p2pk33addressindex_to_p2pk33bytes: vecs .p2pk33addressindex_to_p2pk33bytes - .create_static_reader(), - p2pkhaddressindex_to_p2pkhbytes: vecs - .p2pkhaddressindex_to_p2pkhbytes - .create_static_reader(), - p2shaddressindex_to_p2shbytes: vecs - .p2shaddressindex_to_p2shbytes - .create_static_reader(), + .create_reader(), + p2pkhaddressindex_to_p2pkhbytes: vecs.p2pkhaddressindex_to_p2pkhbytes.create_reader(), + p2shaddressindex_to_p2shbytes: vecs.p2shaddressindex_to_p2shbytes.create_reader(), p2wpkhaddressindex_to_p2wpkhbytes: vecs .p2wpkhaddressindex_to_p2wpkhbytes - .create_static_reader(), - p2wshaddressindex_to_p2wshbytes: vecs - .p2wshaddressindex_to_p2wshbytes - .create_static_reader(), - p2traddressindex_to_p2trbytes: vecs - .p2traddressindex_to_p2trbytes - .create_static_reader(), - p2aaddressindex_to_p2abytes: vecs.p2aaddressindex_to_p2abytes.create_static_reader(), + .create_reader(), + p2wshaddressindex_to_p2wshbytes: vecs.p2wshaddressindex_to_p2wshbytes.create_reader(), + p2traddressindex_to_p2trbytes: vecs.p2traddressindex_to_p2trbytes.create_reader(), + p2aaddressindex_to_p2abytes: vecs.p2aaddressindex_to_p2abytes.create_reader(), } } } diff --git a/crates/brk_indexer/src/vecs.rs b/crates/brk_indexer/src/vecs.rs index 9fcaa40a2..3cf04f84c 100644 --- a/crates/brk_indexer/src/vecs.rs +++ b/crates/brk_indexer/src/vecs.rs @@ -11,7 +11,9 @@ use brk_types::{ TxOutIndex, TxVersion, Txid, TypeIndex, UnknownOutputIndex, Version, Weight, }; use rayon::prelude::*; -use vecdb::{AnyStoredVec, CompressedVec, Database, GenericStoredVec, PAGE_SIZE, RawVec, Stamp}; +use vecdb::{ + AnyStoredVec, BytesVec, Database, GenericStoredVec, Importable, PAGE_SIZE, PcoVec, Stamp, +}; use crate::Indexes; @@ -19,53 +21,53 @@ use crate::Indexes; pub struct Vecs { db: Database, - pub emptyoutputindex_to_txindex: CompressedVec, - pub height_to_blockhash: RawVec, - pub height_to_difficulty: CompressedVec, - pub height_to_first_emptyoutputindex: CompressedVec, - pub height_to_first_opreturnindex: CompressedVec, - pub height_to_first_p2aaddressindex: CompressedVec, - pub height_to_first_p2msoutputindex: CompressedVec, - pub height_to_first_p2pk33addressindex: CompressedVec, - pub height_to_first_p2pk65addressindex: CompressedVec, - pub height_to_first_p2pkhaddressindex: CompressedVec, - pub height_to_first_p2shaddressindex: CompressedVec, - pub height_to_first_p2traddressindex: CompressedVec, - pub height_to_first_p2wpkhaddressindex: CompressedVec, - pub height_to_first_p2wshaddressindex: CompressedVec, - pub height_to_first_txindex: CompressedVec, - pub height_to_first_txinindex: CompressedVec, - pub height_to_first_txoutindex: CompressedVec, - pub height_to_first_unknownoutputindex: CompressedVec, + pub emptyoutputindex_to_txindex: PcoVec, + pub height_to_blockhash: BytesVec, + pub height_to_difficulty: PcoVec, + pub height_to_first_emptyoutputindex: PcoVec, + pub height_to_first_opreturnindex: PcoVec, + pub height_to_first_p2aaddressindex: PcoVec, + pub height_to_first_p2msoutputindex: PcoVec, + pub height_to_first_p2pk33addressindex: PcoVec, + pub height_to_first_p2pk65addressindex: PcoVec, + pub height_to_first_p2pkhaddressindex: PcoVec, + pub height_to_first_p2shaddressindex: PcoVec, + pub height_to_first_p2traddressindex: PcoVec, + pub height_to_first_p2wpkhaddressindex: PcoVec, + pub height_to_first_p2wshaddressindex: PcoVec, + pub height_to_first_txindex: PcoVec, + pub height_to_first_txinindex: PcoVec, + pub height_to_first_txoutindex: PcoVec, + pub height_to_first_unknownoutputindex: PcoVec, /// Doesn't guarantee continuity due to possible reorgs and more generally the nature of mining - pub height_to_timestamp: CompressedVec, - pub height_to_total_size: CompressedVec, - pub height_to_weight: CompressedVec, - pub opreturnindex_to_txindex: CompressedVec, - pub p2aaddressindex_to_p2abytes: RawVec, - pub p2msoutputindex_to_txindex: CompressedVec, - pub p2pk33addressindex_to_p2pk33bytes: RawVec, - pub p2pk65addressindex_to_p2pk65bytes: RawVec, - pub p2pkhaddressindex_to_p2pkhbytes: RawVec, - pub p2shaddressindex_to_p2shbytes: RawVec, - pub p2traddressindex_to_p2trbytes: RawVec, - pub p2wpkhaddressindex_to_p2wpkhbytes: RawVec, - pub p2wshaddressindex_to_p2wshbytes: RawVec, - pub txindex_to_base_size: CompressedVec, - pub txindex_to_first_txinindex: CompressedVec, - pub txindex_to_first_txoutindex: RawVec, - pub txindex_to_height: CompressedVec, - pub txindex_to_is_explicitly_rbf: CompressedVec, - pub txindex_to_rawlocktime: CompressedVec, - pub txindex_to_total_size: CompressedVec, - pub txindex_to_txid: RawVec, - pub txindex_to_txversion: CompressedVec, - pub txinindex_to_outpoint: CompressedVec, - pub txoutindex_to_outputtype: RawVec, - pub txoutindex_to_txindex: CompressedVec, - pub txoutindex_to_typeindex: RawVec, - pub txoutindex_to_value: RawVec, - pub unknownoutputindex_to_txindex: CompressedVec, + pub height_to_timestamp: PcoVec, + pub height_to_total_size: PcoVec, + pub height_to_weight: PcoVec, + pub opreturnindex_to_txindex: PcoVec, + pub p2aaddressindex_to_p2abytes: BytesVec, + pub p2msoutputindex_to_txindex: PcoVec, + pub p2pk33addressindex_to_p2pk33bytes: BytesVec, + pub p2pk65addressindex_to_p2pk65bytes: BytesVec, + pub p2pkhaddressindex_to_p2pkhbytes: BytesVec, + pub p2shaddressindex_to_p2shbytes: BytesVec, + pub p2traddressindex_to_p2trbytes: BytesVec, + pub p2wpkhaddressindex_to_p2wpkhbytes: BytesVec, + pub p2wshaddressindex_to_p2wshbytes: BytesVec, + pub txindex_to_base_size: PcoVec, + pub txindex_to_first_txinindex: PcoVec, + pub txindex_to_first_txoutindex: BytesVec, + pub txindex_to_height: PcoVec, + pub txindex_to_is_explicitly_rbf: PcoVec, + pub txindex_to_rawlocktime: PcoVec, + pub txindex_to_total_size: PcoVec, + pub txindex_to_txid: BytesVec, + pub txindex_to_txversion: PcoVec, + pub txinindex_to_outpoint: PcoVec, + pub txoutindex_to_outputtype: BytesVec, + pub txoutindex_to_txindex: PcoVec, + pub txoutindex_to_typeindex: BytesVec, + pub txoutindex_to_value: BytesVec, + pub unknownoutputindex_to_txindex: PcoVec, } impl Vecs { @@ -74,116 +76,112 @@ impl Vecs { db.set_min_len(PAGE_SIZE * 50_000_000)?; let this = Self { - emptyoutputindex_to_txindex: CompressedVec::forced_import(&db, "txindex", version)?, - height_to_blockhash: RawVec::forced_import(&db, "blockhash", version)?, - height_to_difficulty: CompressedVec::forced_import(&db, "difficulty", version)?, - height_to_first_emptyoutputindex: CompressedVec::forced_import( + emptyoutputindex_to_txindex: PcoVec::forced_import(&db, "txindex", version)?, + height_to_blockhash: BytesVec::forced_import(&db, "blockhash", version)?, + height_to_difficulty: PcoVec::forced_import(&db, "difficulty", version)?, + height_to_first_emptyoutputindex: PcoVec::forced_import( &db, "first_emptyoutputindex", version, )?, - height_to_first_txinindex: CompressedVec::forced_import( - &db, - "first_txinindex", - version, - )?, - height_to_first_opreturnindex: CompressedVec::forced_import( + height_to_first_txinindex: PcoVec::forced_import(&db, "first_txinindex", version)?, + height_to_first_opreturnindex: PcoVec::forced_import( &db, "first_opreturnindex", version, )?, - height_to_first_txoutindex: CompressedVec::forced_import( - &db, - "first_txoutindex", - version, - )?, - height_to_first_p2aaddressindex: CompressedVec::forced_import( + height_to_first_txoutindex: PcoVec::forced_import(&db, "first_txoutindex", version)?, + height_to_first_p2aaddressindex: PcoVec::forced_import( &db, "first_p2aaddressindex", version, )?, - height_to_first_p2msoutputindex: CompressedVec::forced_import( + height_to_first_p2msoutputindex: PcoVec::forced_import( &db, "first_p2msoutputindex", version, )?, - height_to_first_p2pk33addressindex: CompressedVec::forced_import( + height_to_first_p2pk33addressindex: PcoVec::forced_import( &db, "first_p2pk33addressindex", version, )?, - height_to_first_p2pk65addressindex: CompressedVec::forced_import( + height_to_first_p2pk65addressindex: PcoVec::forced_import( &db, "first_p2pk65addressindex", version, )?, - height_to_first_p2pkhaddressindex: CompressedVec::forced_import( + height_to_first_p2pkhaddressindex: PcoVec::forced_import( &db, "first_p2pkhaddressindex", version, )?, - height_to_first_p2shaddressindex: CompressedVec::forced_import( + height_to_first_p2shaddressindex: PcoVec::forced_import( &db, "first_p2shaddressindex", version, )?, - height_to_first_p2traddressindex: CompressedVec::forced_import( + height_to_first_p2traddressindex: PcoVec::forced_import( &db, "first_p2traddressindex", version, )?, - height_to_first_p2wpkhaddressindex: CompressedVec::forced_import( + height_to_first_p2wpkhaddressindex: PcoVec::forced_import( &db, "first_p2wpkhaddressindex", version, )?, - height_to_first_p2wshaddressindex: CompressedVec::forced_import( + height_to_first_p2wshaddressindex: PcoVec::forced_import( &db, "first_p2wshaddressindex", version, )?, - height_to_first_txindex: CompressedVec::forced_import(&db, "first_txindex", version)?, - height_to_first_unknownoutputindex: CompressedVec::forced_import( + height_to_first_txindex: PcoVec::forced_import(&db, "first_txindex", version)?, + height_to_first_unknownoutputindex: PcoVec::forced_import( &db, "first_unknownoutputindex", version, )?, - height_to_timestamp: CompressedVec::forced_import(&db, "timestamp", version)?, - height_to_total_size: CompressedVec::forced_import(&db, "total_size", version)?, - height_to_weight: CompressedVec::forced_import(&db, "weight", version)?, - opreturnindex_to_txindex: CompressedVec::forced_import(&db, "txindex", version)?, - p2aaddressindex_to_p2abytes: RawVec::forced_import(&db, "p2abytes", version)?, - p2msoutputindex_to_txindex: CompressedVec::forced_import(&db, "txindex", version)?, - p2pk33addressindex_to_p2pk33bytes: RawVec::forced_import(&db, "p2pk33bytes", version)?, - p2pk65addressindex_to_p2pk65bytes: RawVec::forced_import(&db, "p2pk65bytes", version)?, - p2pkhaddressindex_to_p2pkhbytes: RawVec::forced_import(&db, "p2pkhbytes", version)?, - p2shaddressindex_to_p2shbytes: RawVec::forced_import(&db, "p2shbytes", version)?, - p2traddressindex_to_p2trbytes: RawVec::forced_import(&db, "p2trbytes", version)?, - p2wpkhaddressindex_to_p2wpkhbytes: RawVec::forced_import(&db, "p2wpkhbytes", version)?, - p2wshaddressindex_to_p2wshbytes: RawVec::forced_import(&db, "p2wshbytes", version)?, - txindex_to_base_size: CompressedVec::forced_import(&db, "base_size", version)?, - txindex_to_height: CompressedVec::forced_import(&db, "height", version)?, - txindex_to_first_txinindex: CompressedVec::forced_import( + height_to_timestamp: PcoVec::forced_import(&db, "timestamp", version)?, + height_to_total_size: PcoVec::forced_import(&db, "total_size", version)?, + height_to_weight: PcoVec::forced_import(&db, "weight", version)?, + opreturnindex_to_txindex: PcoVec::forced_import(&db, "txindex", version)?, + p2aaddressindex_to_p2abytes: BytesVec::forced_import(&db, "p2abytes", version)?, + p2msoutputindex_to_txindex: PcoVec::forced_import(&db, "txindex", version)?, + p2pk33addressindex_to_p2pk33bytes: BytesVec::forced_import( &db, - "first_txinindex", + "p2pk33bytes", version, )?, - txindex_to_first_txoutindex: RawVec::forced_import(&db, "first_txoutindex", version)?, - txindex_to_is_explicitly_rbf: CompressedVec::forced_import( + p2pk65addressindex_to_p2pk65bytes: BytesVec::forced_import( &db, - "is_explicitly_rbf", + "p2pk65bytes", version, )?, - txindex_to_rawlocktime: CompressedVec::forced_import(&db, "rawlocktime", version)?, - txindex_to_total_size: CompressedVec::forced_import(&db, "total_size", version)?, - txindex_to_txid: RawVec::forced_import(&db, "txid", version)?, - txindex_to_txversion: CompressedVec::forced_import(&db, "txversion", version)?, - txinindex_to_outpoint: CompressedVec::forced_import(&db, "outpoint", version)?, - txoutindex_to_outputtype: RawVec::forced_import(&db, "outputtype", version)?, - txoutindex_to_txindex: CompressedVec::forced_import(&db, "txindex", version)?, - txoutindex_to_typeindex: RawVec::forced_import(&db, "typeindex", version)?, - txoutindex_to_value: RawVec::forced_import(&db, "value", version)?, - unknownoutputindex_to_txindex: CompressedVec::forced_import(&db, "txindex", version)?, + p2pkhaddressindex_to_p2pkhbytes: BytesVec::forced_import(&db, "p2pkhbytes", version)?, + p2shaddressindex_to_p2shbytes: BytesVec::forced_import(&db, "p2shbytes", version)?, + p2traddressindex_to_p2trbytes: BytesVec::forced_import(&db, "p2trbytes", version)?, + p2wpkhaddressindex_to_p2wpkhbytes: BytesVec::forced_import( + &db, + "p2wpkhbytes", + version, + )?, + p2wshaddressindex_to_p2wshbytes: BytesVec::forced_import(&db, "p2wshbytes", version)?, + txindex_to_base_size: PcoVec::forced_import(&db, "base_size", version)?, + txindex_to_height: PcoVec::forced_import(&db, "height", version)?, + txindex_to_first_txinindex: PcoVec::forced_import(&db, "first_txinindex", version)?, + txindex_to_first_txoutindex: BytesVec::forced_import(&db, "first_txoutindex", version)?, + txindex_to_is_explicitly_rbf: PcoVec::forced_import(&db, "is_explicitly_rbf", version)?, + txindex_to_rawlocktime: PcoVec::forced_import(&db, "rawlocktime", version)?, + txindex_to_total_size: PcoVec::forced_import(&db, "total_size", version)?, + txindex_to_txid: BytesVec::forced_import(&db, "txid", version)?, + txindex_to_txversion: PcoVec::forced_import(&db, "txversion", version)?, + txinindex_to_outpoint: PcoVec::forced_import(&db, "outpoint", version)?, + txoutindex_to_outputtype: BytesVec::forced_import(&db, "outputtype", version)?, + txoutindex_to_txindex: PcoVec::forced_import(&db, "txindex", version)?, + txoutindex_to_typeindex: BytesVec::forced_import(&db, "typeindex", version)?, + txoutindex_to_value: BytesVec::forced_import(&db, "value", version)?, + unknownoutputindex_to_txindex: PcoVec::forced_import(&db, "txindex", version)?, db, }; diff --git a/crates/brk_traversable/Cargo.toml b/crates/brk_traversable/Cargo.toml index e1c8b5f45..c5a848bd5 100644 --- a/crates/brk_traversable/Cargo.toml +++ b/crates/brk_traversable/Cargo.toml @@ -11,6 +11,10 @@ build = "build.rs" [features] derive = ["brk_traversable_derive"] +pco = ["vecdb/pco"] +zerocopy = ["vecdb/zerocopy"] +lz4 = ["vecdb/lz4"] +zstd = ["vecdb/zstd"] [dependencies] brk_types = { workspace = true } diff --git a/crates/brk_traversable/src/lib.rs b/crates/brk_traversable/src/lib.rs index c9b198839..03e864754 100644 --- a/crates/brk_traversable/src/lib.rs +++ b/crates/brk_traversable/src/lib.rs @@ -5,8 +5,8 @@ pub use brk_types::TreeNode; #[cfg(feature = "derive")] pub use brk_traversable_derive::Traversable; use vecdb::{ - AnyVec, AnyWritableVec, CompressedVec, ComputedVec, EagerVec, Formattable, LazyVecFrom1, - LazyVecFrom2, LazyVecFrom3, Pco, RawVec, StoredVec, VecIndex, VecValue, + AnyVec, AnyWritableVec, BytesVec, BytesVecValue, EagerVec, Formattable, LazyVecFrom1, + LazyVecFrom2, LazyVecFrom3, StoredVec, VecIndex, VecValue, }; pub trait Traversable { @@ -14,10 +14,11 @@ pub trait Traversable { fn iter_any_writable(&self) -> impl Iterator; } -impl Traversable for RawVec +// BytesVec implementation +impl Traversable for BytesVec where I: VecIndex, - T: VecValue + Formattable, + T: BytesVecValue + Formattable, { fn iter_any_writable(&self) -> impl Iterator { std::iter::once(self as &dyn AnyWritableVec) @@ -28,10 +29,12 @@ where } } -impl Traversable for CompressedVec +// ZeroCopyVec implementation (only if zerocopy feature enabled) +#[cfg(feature = "zerocopy")] +impl Traversable for vecdb::ZeroCopyVec where I: VecIndex, - T: Pco + Formattable, + T: vecdb::ZeroCopyVecValue + Formattable, { fn iter_any_writable(&self) -> impl Iterator { std::iter::once(self as &dyn AnyWritableVec) @@ -42,10 +45,12 @@ where } } -impl Traversable for StoredVec +// PcoVec implementation (only if pco feature enabled) +#[cfg(feature = "pco")] +impl Traversable for vecdb::PcoVec where I: VecIndex, - T: Pco + Formattable, + T: vecdb::PcoVecValue + Formattable, { fn iter_any_writable(&self) -> impl Iterator { std::iter::once(self as &dyn AnyWritableVec) @@ -56,10 +61,43 @@ where } } -impl Traversable for EagerVec +// LZ4Vec implementation (only if lz4 feature enabled) +#[cfg(feature = "lz4")] +impl Traversable for vecdb::LZ4Vec where I: VecIndex, - T: Pco + Formattable, + T: vecdb::LZ4VecValue + Formattable, +{ + fn iter_any_writable(&self) -> impl Iterator { + std::iter::once(self as &dyn AnyWritableVec) + } + + fn to_tree_node(&self) -> TreeNode { + TreeNode::Leaf(self.name().to_string()) + } +} + +// ZstdVec implementation (only if zstd feature enabled) +#[cfg(feature = "zstd")] +impl Traversable for vecdb::ZstdVec +where + I: VecIndex, + T: vecdb::ZstdVecValue + Formattable, +{ + fn iter_any_writable(&self) -> impl Iterator { + std::iter::once(self as &dyn AnyWritableVec) + } + + fn to_tree_node(&self) -> TreeNode { + TreeNode::Leaf(self.name().to_string()) + } +} + +// EagerVec implementation (wraps any stored vector) +impl Traversable for EagerVec +where + V: StoredVec, + V::T: Formattable, { fn iter_any_writable(&self) -> impl Iterator { std::iter::once(self as &dyn AnyWritableVec) @@ -125,27 +163,6 @@ where } } -impl Traversable - for ComputedVec -where - I: VecIndex, - T: Pco + Formattable, - S1I: VecIndex, - S1T: Pco, - S2I: VecIndex, - S2T: Pco, - S3I: VecIndex, - S3T: Pco, -{ - fn iter_any_writable(&self) -> impl Iterator { - std::iter::once(self as &dyn AnyWritableVec) - } - - fn to_tree_node(&self) -> TreeNode { - TreeNode::Leaf(self.name().to_string()) - } -} - impl Traversable for Box { fn to_tree_node(&self) -> TreeNode { (**self).to_tree_node() diff --git a/crates/brk_types/Cargo.toml b/crates/brk_types/Cargo.toml index 816c0218e..68942520a 100644 --- a/crates/brk_types/Cargo.toml +++ b/crates/brk_types/Cargo.toml @@ -25,7 +25,6 @@ serde_json = { workspace = true } serde_bytes = { workspace = true } strum = { version = "0.27", features = ["derive"] } vecdb = { workspace = true } -zerocopy = { workspace = true } [package.metadata.cargo-machete] ignored = ["serde_bytes"] diff --git a/crates/brk_types/src/addresshash.rs b/crates/brk_types/src/addresshash.rs index e110db30c..6ec3e74d7 100644 --- a/crates/brk_types/src/addresshash.rs +++ b/crates/brk_types/src/addresshash.rs @@ -1,26 +1,10 @@ use byteview::ByteView; use derive_deref::Deref; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; - -use crate::copy_first_8bytes; +use vecdb::Bytes; use super::AddressBytes; -#[derive( - Debug, - Deref, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Hash, -)] +#[derive(Debug, Deref, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Bytes, Hash)] pub struct AddressHash(u64); impl From<&AddressBytes> for AddressHash { @@ -33,7 +17,7 @@ impl From<&AddressBytes> for AddressHash { impl From for AddressHash { #[inline] fn from(value: ByteView) -> Self { - Self(u64::from_be_bytes(copy_first_8bytes(&value).unwrap())) + Self(u64::from_be_bytes((&*value).try_into().unwrap())) } } diff --git a/crates/brk_types/src/addressindexoutpoint.rs b/crates/brk_types/src/addressindexoutpoint.rs index e8eb84de6..ade546040 100644 --- a/crates/brk_types/src/addressindexoutpoint.rs +++ b/crates/brk_types/src/addressindexoutpoint.rs @@ -2,7 +2,7 @@ use std::hash::{Hash, Hasher}; use byteview::ByteView; use serde::Serialize; -use zerocopy::IntoBytes; +use vecdb::Bytes; use crate::{AddressIndexTxIndex, Vout}; @@ -18,8 +18,8 @@ pub struct AddressIndexOutPoint { impl Hash for AddressIndexOutPoint { fn hash(&self, state: &mut H) { let mut buf = [0u8; 10]; - buf[0..8].copy_from_slice(self.addressindextxindex.as_bytes()); - buf[8..].copy_from_slice(self.vout.as_bytes()); + buf[0..8].copy_from_slice(&self.addressindextxindex.to_bytes()); + buf[8..].copy_from_slice(&self.vout.to_bytes()); state.write(&buf); } } @@ -38,8 +38,8 @@ impl From for AddressIndexOutPoint { #[inline] fn from(value: ByteView) -> Self { Self { - addressindextxindex: AddressIndexTxIndex::from(&value[0..8]), - vout: Vout::from(&value[8..]), + addressindextxindex: AddressIndexTxIndex::from_bytes(&value[0..8]).unwrap(), + vout: Vout::from_bytes(&value[8..]).unwrap(), } } } diff --git a/crates/brk_types/src/addressindextxindex.rs b/crates/brk_types/src/addressindextxindex.rs index 84dfcd679..eef14b0ae 100644 --- a/crates/brk_types/src/addressindextxindex.rs +++ b/crates/brk_types/src/addressindextxindex.rs @@ -2,27 +2,11 @@ use std::hash::Hash; use byteview::ByteView; use serde::Serialize; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; - -use crate::copy_first_8bytes; +use vecdb::Bytes; use super::{TxIndex, TypeIndex}; -#[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Serialize, - FromBytes, - IntoBytes, - Immutable, - KnownLayout, - Hash, -)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Serialize, Bytes, Hash)] pub struct AddressIndexTxIndex(u64); impl AddressIndexTxIndex { @@ -45,14 +29,7 @@ impl From<(TypeIndex, TxIndex)> for AddressIndexTxIndex { impl From for AddressIndexTxIndex { #[inline] fn from(value: ByteView) -> Self { - Self::from(&*value) - } -} - -impl From<&[u8]> for AddressIndexTxIndex { - #[inline] - fn from(value: &[u8]) -> Self { - Self(u64::from_be_bytes(copy_first_8bytes(value).unwrap())) + Self(u64::from_be_bytes((&*value).try_into().unwrap())) } } diff --git a/crates/brk_types/src/anyaddressindex.rs b/crates/brk_types/src/anyaddressindex.rs index 33249fff4..fdff6eb19 100644 --- a/crates/brk_types/src/anyaddressindex.rs +++ b/crates/brk_types/src/anyaddressindex.rs @@ -1,14 +1,11 @@ use serde::Serialize; use vecdb::Formattable; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{EmptyAddressIndex, LoadedAddressIndex, TypeIndex}; const MIN_EMPTY_INDEX: u32 = u32::MAX - 4_000_000_000; -#[derive( - Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout, -)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] pub struct AnyAddressIndex(TypeIndex); impl AnyAddressIndex { @@ -74,12 +71,3 @@ impl From for AnyAddressDataIndexEnum { } } } - -// impl std::fmt::Display for AnyAddressDataIndexEnum { -// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { -// match self { - -// } -// self.0.fmt(f) -// } -// } diff --git a/crates/brk_types/src/bitcoin.rs b/crates/brk_types/src/bitcoin.rs index b20b23314..a6783f3a4 100644 --- a/crates/brk_types/src/bitcoin.rs +++ b/crates/brk_types/src/bitcoin.rs @@ -5,13 +5,10 @@ use std::{ use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{Sats, StoredF64}; -#[derive( - Debug, Default, Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout, Serialize, Pco, -)] +#[derive(Debug, Default, Clone, Copy, Serialize, Pco)] pub struct Bitcoin(f64); impl Add for Bitcoin { diff --git a/crates/brk_types/src/blkposition.rs b/crates/brk_types/src/blkposition.rs index 06a1bb7c7..641ee18eb 100644 --- a/crates/brk_types/src/blkposition.rs +++ b/crates/brk_types/src/blkposition.rs @@ -2,9 +2,8 @@ use std::ops::Add; use serde::Serialize; use vecdb::{Formattable, Pco}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; -#[derive(Debug, Clone, Copy, Serialize, FromBytes, Immutable, IntoBytes, KnownLayout, Pco)] +#[derive(Debug, Clone, Copy, Serialize, Pco)] pub struct BlkPosition(u64); impl BlkPosition { diff --git a/crates/brk_types/src/blockhash.rs b/crates/brk_types/src/blockhash.rs index 3db545758..2aa665b55 100644 --- a/crates/brk_types/src/blockhash.rs +++ b/crates/brk_types/src/blockhash.rs @@ -5,13 +5,10 @@ use brk_error::Error; use derive_deref::Deref; use schemars::JsonSchema; use serde::{Serialize, Serializer}; -use vecdb::Formattable; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; +use vecdb::{Bytes, Formattable}; /// Block hash -#[derive( - Debug, Deref, Clone, PartialEq, Eq, Immutable, IntoBytes, KnownLayout, FromBytes, JsonSchema, -)] +#[derive(Debug, Deref, Clone, PartialEq, Eq, Bytes, JsonSchema)] #[repr(C)] pub struct BlockHash([u8; 32]); diff --git a/crates/brk_types/src/blockhashprefix.rs b/crates/brk_types/src/blockhashprefix.rs index e5a2115b9..5fb6c42ce 100644 --- a/crates/brk_types/src/blockhashprefix.rs +++ b/crates/brk_types/src/blockhashprefix.rs @@ -1,26 +1,9 @@ use byteview::ByteView; use derive_deref::Deref; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; - -use crate::copy_first_8bytes; use super::BlockHash; -#[derive( - Debug, - Deref, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Hash, -)] +#[derive(Debug, Deref, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct BlockHashPrefix(u64); impl From for BlockHashPrefix { @@ -33,14 +16,14 @@ impl From for BlockHashPrefix { impl From<&BlockHash> for BlockHashPrefix { #[inline] fn from(value: &BlockHash) -> Self { - Self(u64::from_ne_bytes(copy_first_8bytes(&value[..]).unwrap())) + Self(u64::from_ne_bytes(value.as_slice().try_into().unwrap())) } } impl From for BlockHashPrefix { #[inline] fn from(value: ByteView) -> Self { - Self(u64::from_be_bytes(copy_first_8bytes(&value).unwrap())) + Self(u64::from_be_bytes((&*value).try_into().unwrap())) } } diff --git a/crates/brk_types/src/bytes.rs b/crates/brk_types/src/bytes.rs index c6769e70b..420e6208b 100644 --- a/crates/brk_types/src/bytes.rs +++ b/crates/brk_types/src/bytes.rs @@ -1,23 +1,8 @@ use derive_deref::{Deref, DerefMut}; use serde::Serialize; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; +use vecdb::Bytes; -#[derive( - Debug, - Clone, - Deref, - DerefMut, - PartialEq, - Eq, - PartialOrd, - Ord, - Immutable, - IntoBytes, - KnownLayout, - FromBytes, - Serialize, - Hash, -)] +#[derive(Debug, Clone, Deref, DerefMut, PartialEq, Eq, PartialOrd, Ord, Serialize, Bytes, Hash)] pub struct U8x2([u8; 2]); impl From<&[u8]> for U8x2 { #[inline] @@ -28,22 +13,7 @@ impl From<&[u8]> for U8x2 { } } -#[derive( - Debug, - Clone, - Deref, - DerefMut, - PartialEq, - Eq, - PartialOrd, - Ord, - Immutable, - IntoBytes, - KnownLayout, - FromBytes, - Serialize, - Hash, -)] +#[derive(Debug, Clone, Deref, DerefMut, PartialEq, Eq, PartialOrd, Ord, Serialize, Bytes, Hash)] pub struct U8x20([u8; 20]); impl From<&[u8]> for U8x20 { #[inline] @@ -54,22 +24,7 @@ impl From<&[u8]> for U8x20 { } } -#[derive( - Debug, - Clone, - Deref, - DerefMut, - PartialEq, - Eq, - PartialOrd, - Ord, - Immutable, - IntoBytes, - KnownLayout, - FromBytes, - Serialize, - Hash, -)] +#[derive(Debug, Clone, Deref, DerefMut, PartialEq, Eq, PartialOrd, Ord, Serialize, Bytes, Hash)] pub struct U8x32([u8; 32]); impl From<&[u8]> for U8x32 { #[inline] @@ -80,22 +35,7 @@ impl From<&[u8]> for U8x32 { } } -#[derive( - Debug, - Clone, - Deref, - DerefMut, - PartialEq, - Eq, - PartialOrd, - Ord, - Immutable, - IntoBytes, - KnownLayout, - FromBytes, - Serialize, - Hash, -)] +#[derive(Debug, Clone, Deref, DerefMut, PartialEq, Eq, PartialOrd, Ord, Serialize, Bytes, Hash)] pub struct U8x33(#[serde(with = "serde_bytes")] [u8; 33]); impl From<&[u8]> for U8x33 { #[inline] @@ -106,22 +46,7 @@ impl From<&[u8]> for U8x33 { } } -#[derive( - Debug, - Clone, - Deref, - DerefMut, - PartialEq, - Eq, - PartialOrd, - Ord, - Immutable, - IntoBytes, - KnownLayout, - FromBytes, - Serialize, - Hash, -)] +#[derive(Debug, Clone, Deref, DerefMut, PartialEq, Eq, PartialOrd, Ord, Serialize, Bytes, Hash)] pub struct U8x65(#[serde(with = "serde_bytes")] [u8; 65]); impl From<&[u8]> for U8x65 { #[inline] diff --git a/crates/brk_types/src/cents.rs b/crates/brk_types/src/cents.rs index d15b1dd86..7692f7e6f 100644 --- a/crates/brk_types/src/cents.rs +++ b/crates/brk_types/src/cents.rs @@ -2,26 +2,10 @@ use std::ops::{Add, Div, Mul}; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::Dollars; -#[derive( - Debug, - Default, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, -)] +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Pco)] pub struct Cents(i64); impl Cents { diff --git a/crates/brk_types/src/date.rs b/crates/brk_types/src/date.rs index 576463d6c..12df41c73 100644 --- a/crates/brk_types/src/date.rs +++ b/crates/brk_types/src/date.rs @@ -1,26 +1,12 @@ use jiff::{Span, Zoned, civil::Date as Date_, tz::TimeZone}; use serde::{Serialize, Serializer}; use vecdb::{Formattable, Pco}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::ONE_DAY_IN_SEC_F64; use super::{DateIndex, Timestamp}; -#[derive( - Debug, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Pco, -)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Pco)] pub struct Date(u32); impl Date { diff --git a/crates/brk_types/src/dateindex.rs b/crates/brk_types/src/dateindex.rs index e24a19158..f79b70c92 100644 --- a/crates/brk_types/src/dateindex.rs +++ b/crates/brk_types/src/dateindex.rs @@ -4,28 +4,12 @@ use brk_error::Error; use jiff::Span; use serde::Serialize; use vecdb::{CheckedSub, Formattable, FromCoarserIndex, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{DecadeIndex, MonthIndex, QuarterIndex, SemesterIndex, WeekIndex, YearIndex}; use super::Date; -#[derive( - Debug, - Default, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, -)] +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Pco)] pub struct DateIndex(u16); impl DateIndex { diff --git a/crates/brk_types/src/decadeindex.rs b/crates/brk_types/src/decadeindex.rs index 941037f52..064ded0b9 100644 --- a/crates/brk_types/src/decadeindex.rs +++ b/crates/brk_types/src/decadeindex.rs @@ -5,26 +5,11 @@ use std::{ use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{Date, DateIndex, YearIndex}; #[derive( - Debug, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Default, - Serialize, - Deserialize, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Pco, + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize, Pco, )] pub struct DecadeIndex(u16); diff --git a/crates/brk_types/src/difficultyepoch.rs b/crates/brk_types/src/difficultyepoch.rs index 05dffbc56..e5b73ff28 100644 --- a/crates/brk_types/src/difficultyepoch.rs +++ b/crates/brk_types/src/difficultyepoch.rs @@ -5,28 +5,13 @@ use std::{ use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::Height; pub const BLOCKS_PER_DIFF_EPOCHS: u32 = 2016; #[derive( - Debug, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Default, - Serialize, - Deserialize, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Pco, + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize, Pco, )] pub struct DifficultyEpoch(u16); diff --git a/crates/brk_types/src/dollars.rs b/crates/brk_types/src/dollars.rs index 754cd9f49..aec17b5f5 100644 --- a/crates/brk_types/src/dollars.rs +++ b/crates/brk_types/src/dollars.rs @@ -9,27 +9,12 @@ use derive_deref::Deref; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, Formattable, Pco}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{Low, Open}; use super::{Bitcoin, Cents, Close, High, Sats, StoredF32, StoredF64}; -#[derive( - Debug, - Default, - Clone, - Copy, - Deref, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Deserialize, - Pco, - JsonSchema, -)] +#[derive(Debug, Default, Clone, Copy, Deref, Serialize, Deserialize, Pco, JsonSchema)] pub struct Dollars(f64); impl Dollars { diff --git a/crates/brk_types/src/emptyaddressdata.rs b/crates/brk_types/src/emptyaddressdata.rs index a9e0e20bb..a2fd4c996 100644 --- a/crates/brk_types/src/emptyaddressdata.rs +++ b/crates/brk_types/src/emptyaddressdata.rs @@ -1,11 +1,10 @@ use serde::Serialize; use vecdb::Formattable; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{LoadedAddressData, Sats}; /// Data of an empty address -#[derive(Debug, Default, Clone, FromBytes, Immutable, IntoBytes, KnownLayout, Serialize)] +#[derive(Debug, Default, Clone, Serialize)] #[repr(C)] pub struct EmptyAddressData { /// Total transaction count diff --git a/crates/brk_types/src/emptyaddressindex.rs b/crates/brk_types/src/emptyaddressindex.rs index cda0f06be..b6e995faf 100644 --- a/crates/brk_types/src/emptyaddressindex.rs +++ b/crates/brk_types/src/emptyaddressindex.rs @@ -3,27 +3,10 @@ use std::ops::Add; use derive_deref::Deref; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; -#[derive( - Debug, - Default, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Deref, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, -)] +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Deref, Serialize, Pco)] pub struct EmptyAddressIndex(TypeIndex); impl From for EmptyAddressIndex { diff --git a/crates/brk_types/src/emptyoutputindex.rs b/crates/brk_types/src/emptyoutputindex.rs index 3b11f23df..6420ebf7e 100644 --- a/crates/brk_types/src/emptyoutputindex.rs +++ b/crates/brk_types/src/emptyoutputindex.rs @@ -3,27 +3,11 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; #[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Deref, - DerefMut, - Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Default, Serialize, Pco, )] pub struct EmptyOutputIndex(TypeIndex); impl From for EmptyOutputIndex { diff --git a/crates/brk_types/src/feerate.rs b/crates/brk_types/src/feerate.rs index bcdedc049..81c8542fc 100644 --- a/crates/brk_types/src/feerate.rs +++ b/crates/brk_types/src/feerate.rs @@ -5,11 +5,10 @@ use std::{ use serde::Serialize; use vecdb::{Formattable, Pco}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{Sats, StoredU64}; -#[derive(Debug, Clone, Copy, Serialize, FromBytes, Immutable, IntoBytes, KnownLayout, Pco)] +#[derive(Debug, Clone, Copy, Serialize, Pco)] pub struct FeeRate(f64); impl From<(Sats, StoredU64)> for FeeRate { diff --git a/crates/brk_types/src/halvingepoch.rs b/crates/brk_types/src/halvingepoch.rs index a73bcc3e3..ae46b2b65 100644 --- a/crates/brk_types/src/halvingepoch.rs +++ b/crates/brk_types/src/halvingepoch.rs @@ -5,28 +5,13 @@ use std::{ use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::Height; pub const BLOCKS_PER_HALVING: u32 = 210_000; #[derive( - Debug, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Default, - Serialize, - Deserialize, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Pco, + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize, Pco, )] pub struct HalvingEpoch(u16); diff --git a/crates/brk_types/src/height.rs b/crates/brk_types/src/height.rs index 179f7ce3f..08e5e5322 100644 --- a/crates/brk_types/src/height.rs +++ b/crates/brk_types/src/height.rs @@ -7,10 +7,9 @@ use byteview::ByteView; use derive_deref::Deref; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex, Stamp}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; +use vecdb::{Bytes, CheckedSub, Formattable, Pco, PrintableIndex, Stamp}; -use crate::{BLOCKS_PER_DIFF_EPOCHS, BLOCKS_PER_HALVING, copy_first_4bytes}; +use crate::{BLOCKS_PER_DIFF_EPOCHS, BLOCKS_PER_HALVING}; use super::StoredU64; @@ -27,10 +26,6 @@ use super::StoredU64; Default, Serialize, Deserialize, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, Pco, JsonSchema, Hash, @@ -46,7 +41,7 @@ impl Height { } pub fn write(&self, path: &std::path::Path) -> Result<(), std::io::Error> { - std::fs::write(path, self.as_bytes()) + std::fs::write(path, self.to_bytes()) } pub fn increment(&mut self) { @@ -227,14 +222,14 @@ impl From for Height { impl TryFrom<&std::path::Path> for Height { type Error = brk_error::Error; fn try_from(value: &std::path::Path) -> Result { - Ok(Self::read_from_bytes(std::fs::read(value)?.as_slice())?.to_owned()) + Ok(Self::from_bytes(std::fs::read(value)?.as_slice())?.to_owned()) } } impl From for Height { #[inline] fn from(value: ByteView) -> Self { - Self(u32::from_be_bytes(copy_first_4bytes(&value).unwrap())) + Self(u32::from_be_bytes((&*value).try_into().unwrap())) } } diff --git a/crates/brk_types/src/lib.rs b/crates/brk_types/src/lib.rs index d41cdfd5a..6a5dabd70 100644 --- a/crates/brk_types/src/lib.rs +++ b/crates/brk_types/src/lib.rs @@ -2,8 +2,6 @@ pub use vecdb::{CheckedSub, Exit, PrintableIndex, Version}; -use brk_error::{Error, Result}; - mod address; mod addressbytes; mod addresschainstats; @@ -199,42 +197,3 @@ pub use vout::*; pub use weekindex::*; pub use weight::*; pub use yearindex::*; - -#[allow(clippy::result_unit_err)] -pub fn copy_first_2bytes(slice: &[u8]) -> Result<[u8; 2]> { - let mut buf: [u8; 2] = [0; 2]; - let buf_len = buf.len(); - if slice.len() < buf_len { - return Err(Error::Str("Buffer is too small to convert to 8 bytes")); - } - slice.iter().take(buf_len).enumerate().for_each(|(i, r)| { - buf[i] = *r; - }); - Ok(buf) -} - -#[allow(clippy::result_unit_err)] -pub fn copy_first_4bytes(slice: &[u8]) -> Result<[u8; 4]> { - let mut buf: [u8; 4] = [0; 4]; - let buf_len = buf.len(); - if slice.len() < buf_len { - return Err(Error::Str("Buffer is too small to convert to 8 bytes")); - } - slice.iter().take(buf_len).enumerate().for_each(|(i, r)| { - buf[i] = *r; - }); - Ok(buf) -} - -#[allow(clippy::result_unit_err)] -pub fn copy_first_8bytes(slice: &[u8]) -> Result<[u8; 8]> { - let mut buf: [u8; 8] = [0; 8]; - let buf_len = buf.len(); - if slice.len() < buf_len { - return Err(Error::Str("Buffer is too small to convert to 8 bytes")); - } - slice.iter().take(buf_len).enumerate().for_each(|(i, r)| { - buf[i] = *r; - }); - Ok(buf) -} diff --git a/crates/brk_types/src/loadedaddressdata.rs b/crates/brk_types/src/loadedaddressdata.rs index 41f5f2c6f..444f24759 100644 --- a/crates/brk_types/src/loadedaddressdata.rs +++ b/crates/brk_types/src/loadedaddressdata.rs @@ -1,12 +1,11 @@ use brk_error::{Error, Result}; use serde::Serialize; use vecdb::{CheckedSub, Formattable}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{Bitcoin, Dollars, EmptyAddressData, Sats}; /// Data for a loaded (non-empty) address with current balance -#[derive(Debug, Default, Clone, Serialize, FromBytes, Immutable, IntoBytes, KnownLayout)] +#[derive(Debug, Default, Clone, Serialize)] #[repr(C)] pub struct LoadedAddressData { /// Total transaction count diff --git a/crates/brk_types/src/loadedaddressindex.rs b/crates/brk_types/src/loadedaddressindex.rs index a1cf0170f..83f928ab2 100644 --- a/crates/brk_types/src/loadedaddressindex.rs +++ b/crates/brk_types/src/loadedaddressindex.rs @@ -3,27 +3,10 @@ use std::ops::Add; use derive_deref::Deref; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; -#[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Deref, - Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, -)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, Default, Serialize, Pco)] pub struct LoadedAddressIndex(TypeIndex); impl From for LoadedAddressIndex { diff --git a/crates/brk_types/src/monthindex.rs b/crates/brk_types/src/monthindex.rs index b7d820690..83f847ccc 100644 --- a/crates/brk_types/src/monthindex.rs +++ b/crates/brk_types/src/monthindex.rs @@ -5,26 +5,11 @@ use std::{ use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{Date, DateIndex, YearIndex}; #[derive( - Debug, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Default, - Serialize, - Deserialize, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Pco, + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize, Pco, )] pub struct MonthIndex(u16); diff --git a/crates/brk_types/src/ohlc.rs b/crates/brk_types/src/ohlc.rs index 9d51a32bb..1fb2ff5f7 100644 --- a/crates/brk_types/src/ohlc.rs +++ b/crates/brk_types/src/ohlc.rs @@ -7,13 +7,12 @@ use std::{ use derive_deref::{Deref, DerefMut}; use serde::{Serialize, Serializer, ser::SerializeTuple}; use vecdb::{Formattable, Pco, TransparentPco}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::StoredF64; use super::{Cents, Dollars, Sats}; -#[derive(Debug, Default, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)] +#[derive(Debug, Default, Clone)] #[repr(C)] pub struct OHLCCents { pub open: Open, @@ -77,7 +76,7 @@ impl Formattable for OHLCCents { } } -#[derive(Debug, Default, Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)] +#[derive(Debug, Default, Clone, Copy)] #[repr(C)] pub struct OHLCDollars { pub open: Open, @@ -167,7 +166,7 @@ impl Formattable for OHLCDollars { } } -#[derive(Debug, Default, Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)] +#[derive(Debug, Default, Clone, Copy)] #[repr(C)] pub struct OHLCSats { pub open: Open, @@ -239,22 +238,7 @@ impl Formattable for OHLCSats { } #[derive( - Debug, - Default, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Deref, - DerefMut, - Serialize, - Pco, + Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Deref, DerefMut, Serialize, Pco, )] #[repr(transparent)] pub struct Open(T); @@ -371,22 +355,7 @@ where } #[derive( - Debug, - Default, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Deref, - DerefMut, - Serialize, - Pco, + Debug, Default, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Serialize, Pco, )] #[repr(transparent)] pub struct High(T); @@ -503,22 +472,7 @@ where } #[derive( - Debug, - Default, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Deref, - DerefMut, - Serialize, - Pco, + Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Deref, DerefMut, Serialize, Pco, )] #[repr(transparent)] pub struct Low(T); @@ -635,22 +589,7 @@ where } #[derive( - Debug, - Default, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Deref, - DerefMut, - Serialize, - Pco, + Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Deref, DerefMut, Serialize, Pco, )] #[repr(transparent)] pub struct Close(T); diff --git a/crates/brk_types/src/opreturnindex.rs b/crates/brk_types/src/opreturnindex.rs index 39ba741c7..842dc4b0d 100644 --- a/crates/brk_types/src/opreturnindex.rs +++ b/crates/brk_types/src/opreturnindex.rs @@ -3,27 +3,11 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; #[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Deref, - DerefMut, - Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Default, Serialize, Pco, )] pub struct OpReturnIndex(TypeIndex); diff --git a/crates/brk_types/src/outpoint.rs b/crates/brk_types/src/outpoint.rs index 08c93693f..4e5836ba9 100644 --- a/crates/brk_types/src/outpoint.rs +++ b/crates/brk_types/src/outpoint.rs @@ -1,27 +1,11 @@ use schemars::JsonSchema; use serde::Serialize; use vecdb::{Formattable, Pco}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{TxIndex, Vout}; #[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - JsonSchema, - Hash, - Pco, + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Serialize, JsonSchema, Hash, Pco, )] pub struct OutPoint(u64); diff --git a/crates/brk_types/src/outputtype.rs b/crates/brk_types/src/outputtype.rs index 674610ab8..2a2a73728 100644 --- a/crates/brk_types/src/outputtype.rs +++ b/crates/brk_types/src/outputtype.rs @@ -3,25 +3,10 @@ use brk_error::Error; use schemars::JsonSchema; use serde::Serialize; use strum::Display; -use vecdb::Formattable; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; +use vecdb::{Bytes, Formattable}; #[derive( - Debug, - Clone, - Copy, - Display, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - JsonSchema, - Hash, + Debug, Clone, Copy, Display, PartialEq, Eq, PartialOrd, Ord, Serialize, JsonSchema, Hash, )] #[serde(rename_all = "lowercase")] #[strum(serialize_all = "lowercase")] @@ -909,16 +894,27 @@ impl TryFrom for AddressType { } } -impl From<&[u8]> for OutputType { - #[inline] - fn from(value: &[u8]) -> Self { - Self::read_from_bytes(value).unwrap() - } -} - impl Formattable for OutputType { #[inline(always)] fn may_need_escaping() -> bool { false } } + +impl Bytes for OutputType { + #[inline] + fn to_bytes(&self) -> Vec { + vec![*self as u8] + } + + #[inline] + fn from_bytes(bytes: &[u8]) -> vecdb::Result { + if bytes.len() != 1 { + return Err(vecdb::Error::WrongLength); + } + // SAFETY: OutputType is repr(u8) and we're transmuting from u8 + // All values 0-255 are valid (includes dummy variants) + let s: Self = unsafe { std::mem::transmute(bytes[0]) }; + Ok(s) + } +} diff --git a/crates/brk_types/src/p2aaddressindex.rs b/crates/brk_types/src/p2aaddressindex.rs index 422ce6cd5..ffd4cea76 100644 --- a/crates/brk_types/src/p2aaddressindex.rs +++ b/crates/brk_types/src/p2aaddressindex.rs @@ -3,27 +3,11 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; #[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Deref, - DerefMut, - Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Default, Serialize, Pco, )] pub struct P2AAddressIndex(TypeIndex); impl From for P2AAddressIndex { diff --git a/crates/brk_types/src/p2abytes.rs b/crates/brk_types/src/p2abytes.rs index 50e27bd46..8c5f9d021 100644 --- a/crates/brk_types/src/p2abytes.rs +++ b/crates/brk_types/src/p2abytes.rs @@ -2,26 +2,11 @@ use std::fmt; use derive_deref::Deref; use serde::Serialize; -use vecdb::Formattable; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; +use vecdb::{Bytes, Formattable}; use crate::U8x2; -#[derive( - Debug, - Clone, - Deref, - PartialEq, - Eq, - PartialOrd, - Ord, - Immutable, - IntoBytes, - KnownLayout, - FromBytes, - Serialize, - Hash, -)] +#[derive(Debug, Clone, Deref, PartialEq, Eq, PartialOrd, Ord, Serialize, Bytes, Hash)] pub struct P2ABytes(U8x2); impl From<&[u8]> for P2ABytes { diff --git a/crates/brk_types/src/p2msoutputindex.rs b/crates/brk_types/src/p2msoutputindex.rs index b5028711e..d34a58a1d 100644 --- a/crates/brk_types/src/p2msoutputindex.rs +++ b/crates/brk_types/src/p2msoutputindex.rs @@ -3,27 +3,11 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; #[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Deref, - DerefMut, - Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Default, Serialize, Pco, )] pub struct P2MSOutputIndex(TypeIndex); impl From for P2MSOutputIndex { diff --git a/crates/brk_types/src/p2pk33addressindex.rs b/crates/brk_types/src/p2pk33addressindex.rs index d5fde8f31..c4a708081 100644 --- a/crates/brk_types/src/p2pk33addressindex.rs +++ b/crates/brk_types/src/p2pk33addressindex.rs @@ -3,27 +3,11 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; #[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Deref, - DerefMut, - Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Default, Serialize, Pco, )] pub struct P2PK33AddressIndex(TypeIndex); impl From for P2PK33AddressIndex { diff --git a/crates/brk_types/src/p2pk33bytes.rs b/crates/brk_types/src/p2pk33bytes.rs index d0036de1e..559753dc6 100644 --- a/crates/brk_types/src/p2pk33bytes.rs +++ b/crates/brk_types/src/p2pk33bytes.rs @@ -2,26 +2,11 @@ use std::fmt; use derive_deref::Deref; use serde::Serialize; -use vecdb::Formattable; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; +use vecdb::{Bytes, Formattable}; use crate::U8x33; -#[derive( - Debug, - Clone, - Deref, - PartialEq, - Eq, - PartialOrd, - Ord, - Immutable, - IntoBytes, - KnownLayout, - FromBytes, - Serialize, - Hash, -)] +#[derive(Debug, Clone, Deref, PartialEq, Eq, PartialOrd, Ord, Serialize, Bytes, Hash)] pub struct P2PK33Bytes(U8x33); impl From<&[u8]> for P2PK33Bytes { diff --git a/crates/brk_types/src/p2pk65addressindex.rs b/crates/brk_types/src/p2pk65addressindex.rs index 650e3f4f4..73b8f433b 100644 --- a/crates/brk_types/src/p2pk65addressindex.rs +++ b/crates/brk_types/src/p2pk65addressindex.rs @@ -3,27 +3,11 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; #[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Deref, - DerefMut, - Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Default, Serialize, Pco, )] pub struct P2PK65AddressIndex(TypeIndex); impl From for P2PK65AddressIndex { diff --git a/crates/brk_types/src/p2pk65bytes.rs b/crates/brk_types/src/p2pk65bytes.rs index b5492abb1..1e665353d 100644 --- a/crates/brk_types/src/p2pk65bytes.rs +++ b/crates/brk_types/src/p2pk65bytes.rs @@ -2,26 +2,11 @@ use std::fmt; use derive_deref::Deref; use serde::Serialize; -use vecdb::Formattable; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; +use vecdb::{Bytes, Formattable}; use crate::U8x65; -#[derive( - Debug, - Clone, - Deref, - PartialEq, - Eq, - PartialOrd, - Ord, - Immutable, - IntoBytes, - KnownLayout, - FromBytes, - Serialize, - Hash, -)] +#[derive(Debug, Clone, Deref, PartialEq, Eq, PartialOrd, Ord, Serialize, Bytes, Hash)] pub struct P2PK65Bytes(U8x65); impl From<&[u8]> for P2PK65Bytes { diff --git a/crates/brk_types/src/p2pkhaddressindex.rs b/crates/brk_types/src/p2pkhaddressindex.rs index d6c0dbf1a..0f9307719 100644 --- a/crates/brk_types/src/p2pkhaddressindex.rs +++ b/crates/brk_types/src/p2pkhaddressindex.rs @@ -3,27 +3,11 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; #[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Deref, - DerefMut, - Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Default, Serialize, Pco, )] pub struct P2PKHAddressIndex(TypeIndex); impl From for P2PKHAddressIndex { diff --git a/crates/brk_types/src/p2pkhbytes.rs b/crates/brk_types/src/p2pkhbytes.rs index 98e6a0f0e..e4161105b 100644 --- a/crates/brk_types/src/p2pkhbytes.rs +++ b/crates/brk_types/src/p2pkhbytes.rs @@ -2,26 +2,11 @@ use std::fmt; use derive_deref::Deref; use serde::Serialize; -use vecdb::Formattable; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; +use vecdb::{Bytes, Formattable}; use crate::U8x20; -#[derive( - Debug, - Clone, - Deref, - PartialEq, - Eq, - PartialOrd, - Ord, - Immutable, - IntoBytes, - KnownLayout, - FromBytes, - Serialize, - Hash, -)] +#[derive(Debug, Clone, Deref, PartialEq, Eq, PartialOrd, Ord, Serialize, Bytes, Hash)] pub struct P2PKHBytes(U8x20); impl From<&[u8]> for P2PKHBytes { diff --git a/crates/brk_types/src/p2shaddressindex.rs b/crates/brk_types/src/p2shaddressindex.rs index 19934fc74..8d63a8c44 100644 --- a/crates/brk_types/src/p2shaddressindex.rs +++ b/crates/brk_types/src/p2shaddressindex.rs @@ -3,27 +3,11 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; #[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Deref, - DerefMut, - Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Default, Serialize, Pco, )] pub struct P2SHAddressIndex(TypeIndex); impl From for P2SHAddressIndex { diff --git a/crates/brk_types/src/p2shbytes.rs b/crates/brk_types/src/p2shbytes.rs index 4b3fa5147..7dd05fcc6 100644 --- a/crates/brk_types/src/p2shbytes.rs +++ b/crates/brk_types/src/p2shbytes.rs @@ -2,26 +2,11 @@ use std::fmt; use derive_deref::Deref; use serde::Serialize; -use vecdb::Formattable; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; +use vecdb::{Bytes, Formattable}; use crate::U8x20; -#[derive( - Debug, - Clone, - Deref, - PartialEq, - Eq, - PartialOrd, - Ord, - Immutable, - IntoBytes, - KnownLayout, - FromBytes, - Serialize, - Hash, -)] +#[derive(Debug, Clone, Deref, PartialEq, Eq, PartialOrd, Ord, Serialize, Bytes, Hash)] pub struct P2SHBytes(U8x20); impl From<&[u8]> for P2SHBytes { diff --git a/crates/brk_types/src/p2traddressindex.rs b/crates/brk_types/src/p2traddressindex.rs index 51c013724..00de4ac46 100644 --- a/crates/brk_types/src/p2traddressindex.rs +++ b/crates/brk_types/src/p2traddressindex.rs @@ -3,27 +3,11 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; #[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Deref, - DerefMut, - Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Default, Serialize, Pco, )] pub struct P2TRAddressIndex(TypeIndex); impl From for P2TRAddressIndex { diff --git a/crates/brk_types/src/p2trbytes.rs b/crates/brk_types/src/p2trbytes.rs index a643bf3dc..4fc7f23a1 100644 --- a/crates/brk_types/src/p2trbytes.rs +++ b/crates/brk_types/src/p2trbytes.rs @@ -2,26 +2,11 @@ use std::fmt; use derive_deref::Deref; use serde::Serialize; -use vecdb::Formattable; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; +use vecdb::{Bytes, Formattable}; use crate::U8x32; -#[derive( - Debug, - Clone, - Deref, - PartialEq, - Eq, - PartialOrd, - Ord, - Immutable, - IntoBytes, - KnownLayout, - FromBytes, - Serialize, - Hash, -)] +#[derive(Debug, Clone, Deref, PartialEq, Eq, PartialOrd, Ord, Serialize, Bytes, Hash)] pub struct P2TRBytes(U8x32); impl From<&[u8]> for P2TRBytes { diff --git a/crates/brk_types/src/p2wpkhaddressindex.rs b/crates/brk_types/src/p2wpkhaddressindex.rs index f1f13ae1e..f6aea3650 100644 --- a/crates/brk_types/src/p2wpkhaddressindex.rs +++ b/crates/brk_types/src/p2wpkhaddressindex.rs @@ -3,27 +3,11 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; #[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Deref, - DerefMut, - Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Default, Serialize, Pco, )] pub struct P2WPKHAddressIndex(TypeIndex); impl From for P2WPKHAddressIndex { diff --git a/crates/brk_types/src/p2wpkhbytes.rs b/crates/brk_types/src/p2wpkhbytes.rs index ad41e5f93..b9ce86195 100644 --- a/crates/brk_types/src/p2wpkhbytes.rs +++ b/crates/brk_types/src/p2wpkhbytes.rs @@ -2,26 +2,11 @@ use std::fmt; use derive_deref::Deref; use serde::Serialize; -use vecdb::Formattable; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; +use vecdb::{Bytes, Formattable}; use crate::U8x20; -#[derive( - Debug, - Clone, - Deref, - PartialEq, - Eq, - PartialOrd, - Ord, - Immutable, - IntoBytes, - KnownLayout, - FromBytes, - Serialize, - Hash, -)] +#[derive(Debug, Clone, Deref, PartialEq, Eq, PartialOrd, Ord, Serialize, Bytes, Hash)] pub struct P2WPKHBytes(U8x20); impl From<&[u8]> for P2WPKHBytes { diff --git a/crates/brk_types/src/p2wshaddressindex.rs b/crates/brk_types/src/p2wshaddressindex.rs index 15c77a014..b4009e401 100644 --- a/crates/brk_types/src/p2wshaddressindex.rs +++ b/crates/brk_types/src/p2wshaddressindex.rs @@ -3,27 +3,11 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; #[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Deref, - DerefMut, - Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Default, Serialize, Pco, )] pub struct P2WSHAddressIndex(TypeIndex); impl From for P2WSHAddressIndex { diff --git a/crates/brk_types/src/p2wshbytes.rs b/crates/brk_types/src/p2wshbytes.rs index 38f3b045d..c37c2d742 100644 --- a/crates/brk_types/src/p2wshbytes.rs +++ b/crates/brk_types/src/p2wshbytes.rs @@ -2,26 +2,11 @@ use std::fmt; use derive_deref::Deref; use serde::Serialize; -use vecdb::Formattable; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; +use vecdb::{Bytes, Formattable}; use crate::U8x32; -#[derive( - Debug, - Clone, - Deref, - PartialEq, - Eq, - PartialOrd, - Ord, - Immutable, - IntoBytes, - KnownLayout, - FromBytes, - Serialize, - Hash, -)] +#[derive(Debug, Clone, Deref, PartialEq, Eq, PartialOrd, Ord, Serialize, Bytes, Hash)] pub struct P2WSHBytes(U8x32); impl From<&[u8]> for P2WSHBytes { diff --git a/crates/brk_types/src/poolid.rs b/crates/brk_types/src/poolid.rs index 08141c721..f90d01c1f 100644 --- a/crates/brk_types/src/poolid.rs +++ b/crates/brk_types/src/poolid.rs @@ -2,7 +2,6 @@ use num_enum::{FromPrimitive, IntoPrimitive}; use serde::{Deserialize, Serialize}; use strum::Display; use vecdb::Formattable; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; // Created from the list in `pools.rs` // Can be used as index for said list @@ -20,10 +19,6 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; Deserialize, FromPrimitive, IntoPrimitive, - FromBytes, - IntoBytes, - Immutable, - KnownLayout, )] #[serde(rename_all = "lowercase")] #[strum(serialize_all = "lowercase")] diff --git a/crates/brk_types/src/quarterindex.rs b/crates/brk_types/src/quarterindex.rs index 042eb8b8c..23c7c6108 100644 --- a/crates/brk_types/src/quarterindex.rs +++ b/crates/brk_types/src/quarterindex.rs @@ -5,26 +5,11 @@ use std::{ use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::MonthIndex; #[derive( - Debug, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Default, - Serialize, - Deserialize, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Pco, + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize, Pco, )] pub struct QuarterIndex(u16); diff --git a/crates/brk_types/src/rawlocktime.rs b/crates/brk_types/src/rawlocktime.rs index f9c0efd23..901cd561b 100644 --- a/crates/brk_types/src/rawlocktime.rs +++ b/crates/brk_types/src/rawlocktime.rs @@ -2,12 +2,9 @@ use bitcoin::{absolute::LockTime, locktime::absolute::LOCK_TIME_THRESHOLD}; use schemars::JsonSchema; use serde::Serialize; use vecdb::{Formattable, Pco}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; /// Transaction locktime -#[derive( - Debug, Immutable, Clone, Copy, IntoBytes, KnownLayout, FromBytes, Serialize, Pco, JsonSchema, -)] +#[derive(Debug, Clone, Copy, Serialize, Pco, JsonSchema)] pub struct RawLockTime(u32); impl From for RawLockTime { diff --git a/crates/brk_types/src/sats.rs b/crates/brk_types/src/sats.rs index 20bda82e4..b30cdae94 100644 --- a/crates/brk_types/src/sats.rs +++ b/crates/brk_types/src/sats.rs @@ -8,7 +8,6 @@ use derive_deref::Deref; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, Formattable, Pco, SaturatingAdd}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::StoredF64; @@ -25,10 +24,6 @@ use super::{Bitcoin, Cents, Dollars, Height}; Copy, Deref, Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, Serialize, Deserialize, Pco, diff --git a/crates/brk_types/src/semesterindex.rs b/crates/brk_types/src/semesterindex.rs index cd3d0ccc2..316cef7f4 100644 --- a/crates/brk_types/src/semesterindex.rs +++ b/crates/brk_types/src/semesterindex.rs @@ -5,26 +5,11 @@ use std::{ use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::MonthIndex; #[derive( - Debug, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Default, - Serialize, - Deserialize, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Pco, + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize, Pco, )] pub struct SemesterIndex(u16); diff --git a/crates/brk_types/src/stored_bool.rs b/crates/brk_types/src/stored_bool.rs index 494507cbf..940d10d23 100644 --- a/crates/brk_types/src/stored_bool.rs +++ b/crates/brk_types/src/stored_bool.rs @@ -1,25 +1,8 @@ use derive_deref::Deref; use serde::Serialize; use vecdb::{Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; -#[derive( - Debug, - Deref, - Clone, - Default, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, -)] +#[derive(Debug, Deref, Clone, Default, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Pco)] pub struct StoredBool(u16); impl StoredBool { diff --git a/crates/brk_types/src/stored_f32.rs b/crates/brk_types/src/stored_f32.rs index 3db8021b5..b8b795845 100644 --- a/crates/brk_types/src/stored_f32.rs +++ b/crates/brk_types/src/stored_f32.rs @@ -9,15 +9,12 @@ use std::{ use derive_deref::Deref; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{Close, StoredU32}; use super::{Dollars, StoredF64}; -#[derive( - Debug, Deref, Default, Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout, Serialize, Pco, -)] +#[derive(Debug, Deref, Default, Clone, Copy, Serialize, Pco)] pub struct StoredF32(f32); impl StoredF32 { diff --git a/crates/brk_types/src/stored_f64.rs b/crates/brk_types/src/stored_f64.rs index 2e7cd3433..29ea38f87 100644 --- a/crates/brk_types/src/stored_f64.rs +++ b/crates/brk_types/src/stored_f64.rs @@ -8,13 +8,10 @@ use std::{ use derive_deref::Deref; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{Bitcoin, Dollars}; -#[derive( - Debug, Deref, Default, Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout, Serialize, Pco, -)] +#[derive(Debug, Deref, Default, Clone, Copy, Serialize, Pco)] pub struct StoredF64(f64); impl StoredF64 { diff --git a/crates/brk_types/src/stored_i16.rs b/crates/brk_types/src/stored_i16.rs index 0a2cfaaff..b583ea862 100644 --- a/crates/brk_types/src/stored_i16.rs +++ b/crates/brk_types/src/stored_i16.rs @@ -3,25 +3,8 @@ use std::ops::{Add, AddAssign, Div}; use derive_deref::Deref; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; -#[derive( - Debug, - Deref, - Clone, - Default, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, -)] +#[derive(Debug, Deref, Clone, Default, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Pco)] pub struct StoredI16(i16); impl StoredI16 { diff --git a/crates/brk_types/src/stored_u16.rs b/crates/brk_types/src/stored_u16.rs index 67bf151d2..359416021 100644 --- a/crates/brk_types/src/stored_u16.rs +++ b/crates/brk_types/src/stored_u16.rs @@ -3,7 +3,6 @@ use std::ops::{Add, AddAssign, Div}; use derive_deref::Deref; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{ EmptyOutputIndex, OpReturnIndex, P2AAddressIndex, P2MSOutputIndex, P2PK33AddressIndex, @@ -11,23 +10,7 @@ use super::{ P2WSHAddressIndex, UnknownOutputIndex, }; -#[derive( - Debug, - Deref, - Clone, - Default, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, -)] +#[derive(Debug, Deref, Clone, Default, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Pco)] pub struct StoredU16(u16); impl StoredU16 { diff --git a/crates/brk_types/src/stored_u32.rs b/crates/brk_types/src/stored_u32.rs index fb9b249b4..9f9993f40 100644 --- a/crates/brk_types/src/stored_u32.rs +++ b/crates/brk_types/src/stored_u32.rs @@ -3,7 +3,6 @@ use std::ops::{Add, AddAssign, Div, Mul}; use derive_deref::Deref; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{ EmptyOutputIndex, OpReturnIndex, P2AAddressIndex, P2MSOutputIndex, P2PK33AddressIndex, @@ -11,23 +10,7 @@ use super::{ P2WSHAddressIndex, UnknownOutputIndex, }; -#[derive( - Debug, - Deref, - Clone, - Default, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, -)] +#[derive(Debug, Deref, Clone, Default, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Pco)] pub struct StoredU32(u32); impl StoredU32 { diff --git a/crates/brk_types/src/stored_u64.rs b/crates/brk_types/src/stored_u64.rs index ac3a1987a..2cf65aa32 100644 --- a/crates/brk_types/src/stored_u64.rs +++ b/crates/brk_types/src/stored_u64.rs @@ -3,7 +3,6 @@ use std::ops::{Add, AddAssign, Div}; use derive_deref::Deref; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{ DateIndex, EmptyOutputIndex, Height, MonthIndex, OpReturnIndex, P2AAddressIndex, @@ -12,23 +11,7 @@ use super::{ UnknownOutputIndex, YearIndex, }; -#[derive( - Debug, - Default, - Deref, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, -)] +#[derive(Debug, Default, Deref, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Pco)] pub struct StoredU64(u64); impl StoredU64 { diff --git a/crates/brk_types/src/stored_u8.rs b/crates/brk_types/src/stored_u8.rs index 82cc757b5..ab25af748 100644 --- a/crates/brk_types/src/stored_u8.rs +++ b/crates/brk_types/src/stored_u8.rs @@ -3,26 +3,10 @@ use std::ops::{Add, AddAssign, Div}; use derive_deref::Deref; use serde::Serialize; use vecdb::{CheckedSub, Formattable, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; pub type StoredPhantom = StoredU8; -#[derive( - Default, - Debug, - Deref, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, -)] +#[derive(Default, Debug, Deref, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize)] pub struct StoredU8(u8); impl StoredU8 { diff --git a/crates/brk_types/src/timestamp.rs b/crates/brk_types/src/timestamp.rs index ce912d335..2cf497399 100644 --- a/crates/brk_types/src/timestamp.rs +++ b/crates/brk_types/src/timestamp.rs @@ -5,28 +5,11 @@ use jiff::{civil::date, tz::TimeZone}; use schemars::JsonSchema; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::Date; /// Timestamp -#[derive( - Debug, - Deref, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, - JsonSchema, -)] +#[derive(Debug, Deref, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Pco, JsonSchema)] pub struct Timestamp(u32); pub const ONE_HOUR_IN_SEC: u32 = 60 * 60; diff --git a/crates/brk_types/src/txid.rs b/crates/brk_types/src/txid.rs index 1117c04d8..44ca4a990 100644 --- a/crates/brk_types/src/txid.rs +++ b/crates/brk_types/src/txid.rs @@ -4,23 +4,10 @@ use bitcoin::hashes::Hash; use derive_deref::Deref; use schemars::JsonSchema; use serde::{Serialize, Serializer}; -use vecdb::Formattable; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; +use vecdb::{Bytes, Formattable}; /// Transaction ID (hash) -#[derive( - Debug, - Deref, - Clone, - PartialEq, - Eq, - Immutable, - IntoBytes, - KnownLayout, - FromBytes, - JsonSchema, - Hash, -)] +#[derive(Debug, Deref, Clone, PartialEq, Eq, JsonSchema, Bytes, Hash)] #[schemars( example = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b", example = "2bb85f4b004be6da54f766c17c1e855187327112c231ef2ff35ebad0ea67c69e", diff --git a/crates/brk_types/src/txidprefix.rs b/crates/brk_types/src/txidprefix.rs index e6e644575..8d58354a2 100644 --- a/crates/brk_types/src/txidprefix.rs +++ b/crates/brk_types/src/txidprefix.rs @@ -1,26 +1,9 @@ use byteview::ByteView; use derive_deref::Deref; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; - -use crate::copy_first_8bytes; use super::Txid; -#[derive( - Debug, - Deref, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Hash, -)] +#[derive(Debug, Deref, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct TxidPrefix(u64); impl From for TxidPrefix { @@ -33,14 +16,14 @@ impl From for TxidPrefix { impl From<&Txid> for TxidPrefix { #[inline] fn from(value: &Txid) -> Self { - Self(u64::from_ne_bytes(copy_first_8bytes(&value[..]).unwrap())) + Self(u64::from_ne_bytes(value.as_slice().try_into().unwrap())) } } impl From for TxidPrefix { #[inline] fn from(value: ByteView) -> Self { - Self(u64::from_be_bytes(copy_first_8bytes(&value).unwrap())) + Self(u64::from_be_bytes((&*value).try_into().unwrap())) } } diff --git a/crates/brk_types/src/txindex.rs b/crates/brk_types/src/txindex.rs index eb17fe04d..b6cbe5e5c 100644 --- a/crates/brk_types/src/txindex.rs +++ b/crates/brk_types/src/txindex.rs @@ -5,9 +5,6 @@ use derive_deref::{Deref, DerefMut}; use schemars::JsonSchema; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; - -use crate::copy_first_4bytes; use super::StoredU32; @@ -22,10 +19,6 @@ use super::StoredU32; Deref, DerefMut, Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, Serialize, Pco, JsonSchema, @@ -123,7 +116,7 @@ impl From for usize { impl From for TxIndex { #[inline] fn from(value: ByteView) -> Self { - Self(u32::from_be_bytes(copy_first_4bytes(&value).unwrap())) + Self(u32::from_be_bytes((&*value).try_into().unwrap())) } } impl From for ByteView { @@ -140,13 +133,6 @@ impl From for StoredU32 { } } -impl From<&[u8]> for TxIndex { - #[inline] - fn from(value: &[u8]) -> Self { - Self(u32::from_be_bytes(copy_first_4bytes(value).unwrap())) - } -} - impl PrintableIndex for TxIndex { fn to_string() -> &'static str { "txindex" diff --git a/crates/brk_types/src/txinindex.rs b/crates/brk_types/src/txinindex.rs index b087743b6..2032954fe 100644 --- a/crates/brk_types/src/txinindex.rs +++ b/crates/brk_types/src/txinindex.rs @@ -3,27 +3,11 @@ use std::ops::{Add, AddAssign}; use derive_deref::{Deref, DerefMut}; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::Vin; #[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Deref, - DerefMut, - Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Default, Serialize, Pco, )] pub struct TxInIndex(u64); diff --git a/crates/brk_types/src/txoutindex.rs b/crates/brk_types/src/txoutindex.rs index 92116bbd2..3c1367785 100644 --- a/crates/brk_types/src/txoutindex.rs +++ b/crates/brk_types/src/txoutindex.rs @@ -3,29 +3,11 @@ use std::ops::{Add, AddAssign}; use derive_deref::{Deref, DerefMut}; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; - -use crate::copy_first_8bytes; use super::Vout; #[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Deref, - DerefMut, - Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Default, Serialize, Pco, )] pub struct TxOutIndex(u64); @@ -116,13 +98,6 @@ impl From for usize { } } -impl From<&[u8]> for TxOutIndex { - #[inline] - fn from(value: &[u8]) -> Self { - Self(u64::from_be_bytes(copy_first_8bytes(value).unwrap())) - } -} - impl PrintableIndex for TxOutIndex { fn to_string() -> &'static str { "txoutindex" diff --git a/crates/brk_types/src/txversion.rs b/crates/brk_types/src/txversion.rs index e9aaacc13..380159610 100644 --- a/crates/brk_types/src/txversion.rs +++ b/crates/brk_types/src/txversion.rs @@ -2,28 +2,11 @@ use derive_deref::Deref; use schemars::JsonSchema; use serde::Serialize; use vecdb::{Formattable, Pco}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::StoredU16; /// Transaction version number -#[derive( - Debug, - Deref, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Immutable, - IntoBytes, - KnownLayout, - FromBytes, - Serialize, - Pco, - JsonSchema, -)] +#[derive(Debug, Deref, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Pco, JsonSchema)] pub struct TxVersion(u16); impl TxVersion { diff --git a/crates/brk_types/src/typeindex.rs b/crates/brk_types/src/typeindex.rs index c6e10fb73..1264e0529 100644 --- a/crates/brk_types/src/typeindex.rs +++ b/crates/brk_types/src/typeindex.rs @@ -4,9 +4,6 @@ use byteview::ByteView; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, Formattable, Pco}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; - -use crate::copy_first_4bytes; /// Index within its type (e.g., 0 for first P2WPKH address) #[derive( @@ -18,10 +15,6 @@ use crate::copy_first_4bytes; Clone, Copy, Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, Serialize, Deserialize, Pco, @@ -117,17 +110,10 @@ impl Add for TypeIndex { } } -impl From<&[u8]> for TypeIndex { - #[inline] - fn from(value: &[u8]) -> Self { - Self(u32::from_be_bytes(copy_first_4bytes(value).unwrap())) - } -} - impl From for TypeIndex { #[inline] fn from(value: ByteView) -> Self { - Self::from(value.as_bytes()) + Self::from(u32::from_be_bytes((&*value).try_into().unwrap())) } } impl From for ByteView { diff --git a/crates/brk_types/src/unknownoutputindex.rs b/crates/brk_types/src/unknownoutputindex.rs index b0383ab1b..e596b6372 100644 --- a/crates/brk_types/src/unknownoutputindex.rs +++ b/crates/brk_types/src/unknownoutputindex.rs @@ -3,27 +3,11 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; #[derive( - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Clone, - Copy, - Deref, - DerefMut, - Default, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Serialize, - Pco, + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Deref, DerefMut, Default, Serialize, Pco, )] pub struct UnknownOutputIndex(TypeIndex); diff --git a/crates/brk_types/src/vout.rs b/crates/brk_types/src/vout.rs index aa6e8a11f..7d573dc0c 100644 --- a/crates/brk_types/src/vout.rs +++ b/crates/brk_types/src/vout.rs @@ -1,10 +1,7 @@ use derive_deref::Deref; use schemars::JsonSchema; use serde::Serialize; -use vecdb::Formattable; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; - -use crate::copy_first_2bytes; +use vecdb::{Bytes, Formattable}; /// Index of the output being spent in the previous transaction #[derive( @@ -17,12 +14,9 @@ use crate::copy_first_2bytes; Eq, PartialOrd, Ord, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, Serialize, JsonSchema, + Bytes, Hash, )] pub struct Vout(u16); @@ -94,13 +88,6 @@ impl From for usize { } } -impl From<&[u8]> for Vout { - #[inline] - fn from(value: &[u8]) -> Self { - Self(u16::from_be_bytes(copy_first_2bytes(value).unwrap())) - } -} - impl std::fmt::Display for Vout { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.0.fmt(f) diff --git a/crates/brk_types/src/weekindex.rs b/crates/brk_types/src/weekindex.rs index 6ff531604..4a8233cc2 100644 --- a/crates/brk_types/src/weekindex.rs +++ b/crates/brk_types/src/weekindex.rs @@ -5,26 +5,11 @@ use std::{ use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{Date, DateIndex}; #[derive( - Debug, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Default, - Serialize, - Deserialize, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Pco, + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize, Pco, )] pub struct WeekIndex(u16); diff --git a/crates/brk_types/src/weight.rs b/crates/brk_types/src/weight.rs index 2ff3eaf09..3ae37c0eb 100644 --- a/crates/brk_types/src/weight.rs +++ b/crates/brk_types/src/weight.rs @@ -4,25 +4,8 @@ use derive_deref::Deref; use schemars::JsonSchema; use serde::Serialize; use vecdb::{Formattable, Pco}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; -#[derive( - Debug, - Deref, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Immutable, - IntoBytes, - KnownLayout, - FromBytes, - Serialize, - Pco, - JsonSchema, -)] +#[derive(Debug, Deref, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Pco, JsonSchema)] pub struct Weight(u64); impl From for Weight { diff --git a/crates/brk_types/src/yearindex.rs b/crates/brk_types/src/yearindex.rs index 095454f5d..b587878d7 100644 --- a/crates/brk_types/src/yearindex.rs +++ b/crates/brk_types/src/yearindex.rs @@ -5,26 +5,11 @@ use std::{ use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{Date, DateIndex, MonthIndex}; #[derive( - Debug, - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Default, - Serialize, - Deserialize, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - Pco, + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize, Pco, )] pub struct YearIndex(u16);