global: snapshot

This commit is contained in:
nym21
2025-11-25 17:21:07 +01:00
parent c644781d18
commit dc86514329
87 changed files with 335 additions and 1436 deletions

18
Cargo.lock generated
View File

@@ -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]]

View File

@@ -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

View File

@@ -31,4 +31,3 @@ rustc-hash = { workspace = true }
serde = { workspace = true }
smallvec = "1.15.1"
vecdb = { workspace = true }
zerocopy = { workspace = true }

View File

@@ -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<Height, BlkPosition>,
pub txindex_to_position: CompressedVec<TxIndex, BlkPosition>,
pub height_to_position: PcoVec<Height, BlkPosition>,
pub txindex_to_position: PcoVec<TxIndex, BlkPosition>,
}
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,
};

View File

@@ -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<usize>
+ Div<usize, Output = Self>
+ Add<Output = Self>
@@ -14,7 +14,7 @@ where
{
}
impl<T> ComputedVecValue for T where
T: Pco
T: PcoVecValue
+ From<usize>
+ Div<usize, Output = Self>
+ Add<Output = Self>

View File

@@ -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<I, T>(BTreeMap<I, T>);
@@ -20,13 +20,13 @@ where
}
}
impl<I, T> From<&RawVec<I, T>> for RangeMap<T, I>
impl<I, T> From<&BytesVec<I, T>> for RangeMap<T, I>
where
I: VecIndex,
T: VecIndex + VecValue,
T: VecIndex + BytesVecValue,
{
#[inline]
fn from(vec: &RawVec<I, T>) -> Self {
fn from(vec: &BytesVec<I, T>) -> Self {
Self(
vec.into_iter()
.enumerate()
@@ -36,13 +36,13 @@ where
}
}
impl<I, T> From<&CompressedVec<I, T>> for RangeMap<T, I>
impl<I, T> From<&PcoVec<I, T>> for RangeMap<T, I>
where
I: VecIndex,
T: VecIndex + Pco,
T: VecIndex + PcoVecValue,
{
#[inline]
fn from(vec: &CompressedVec<I, T>) -> Self {
fn from(vec: &PcoVec<I, T>) -> Self {
Self(
vec.into_iter()
.enumerate()

View File

@@ -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<Self> {
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<f64> = simple_decompress(&data[16..16 + keys_len])?;
let values: Vec<u64> = simple_decompress(&data[16 + keys_len..])?;

View File

@@ -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,

View File

@@ -19,4 +19,3 @@ minreq = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true }
vecdb = { workspace = true }
zerocopy = { workspace = true }

View File

@@ -163,20 +163,6 @@ impl From<&'static str> for Error {
}
}
impl<A, B, C> From<zerocopy::error::ConvertError<A, B, C>> for Error {
#[inline]
fn from(_: zerocopy::error::ConvertError<A, B, C>) -> Self {
Self::ZeroCopyError
}
}
impl<A, B> From<zerocopy::error::SizeError<A, B>> for Error {
#[inline]
fn from(_: zerocopy::error::SizeError<A, B>) -> Self {
Self::ZeroCopyError
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {

View File

@@ -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(),
}
}
}

View File

@@ -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<EmptyOutputIndex, TxIndex>,
pub height_to_blockhash: RawVec<Height, BlockHash>,
pub height_to_difficulty: CompressedVec<Height, StoredF64>,
pub height_to_first_emptyoutputindex: CompressedVec<Height, EmptyOutputIndex>,
pub height_to_first_opreturnindex: CompressedVec<Height, OpReturnIndex>,
pub height_to_first_p2aaddressindex: CompressedVec<Height, P2AAddressIndex>,
pub height_to_first_p2msoutputindex: CompressedVec<Height, P2MSOutputIndex>,
pub height_to_first_p2pk33addressindex: CompressedVec<Height, P2PK33AddressIndex>,
pub height_to_first_p2pk65addressindex: CompressedVec<Height, P2PK65AddressIndex>,
pub height_to_first_p2pkhaddressindex: CompressedVec<Height, P2PKHAddressIndex>,
pub height_to_first_p2shaddressindex: CompressedVec<Height, P2SHAddressIndex>,
pub height_to_first_p2traddressindex: CompressedVec<Height, P2TRAddressIndex>,
pub height_to_first_p2wpkhaddressindex: CompressedVec<Height, P2WPKHAddressIndex>,
pub height_to_first_p2wshaddressindex: CompressedVec<Height, P2WSHAddressIndex>,
pub height_to_first_txindex: CompressedVec<Height, TxIndex>,
pub height_to_first_txinindex: CompressedVec<Height, TxInIndex>,
pub height_to_first_txoutindex: CompressedVec<Height, TxOutIndex>,
pub height_to_first_unknownoutputindex: CompressedVec<Height, UnknownOutputIndex>,
pub emptyoutputindex_to_txindex: PcoVec<EmptyOutputIndex, TxIndex>,
pub height_to_blockhash: BytesVec<Height, BlockHash>,
pub height_to_difficulty: PcoVec<Height, StoredF64>,
pub height_to_first_emptyoutputindex: PcoVec<Height, EmptyOutputIndex>,
pub height_to_first_opreturnindex: PcoVec<Height, OpReturnIndex>,
pub height_to_first_p2aaddressindex: PcoVec<Height, P2AAddressIndex>,
pub height_to_first_p2msoutputindex: PcoVec<Height, P2MSOutputIndex>,
pub height_to_first_p2pk33addressindex: PcoVec<Height, P2PK33AddressIndex>,
pub height_to_first_p2pk65addressindex: PcoVec<Height, P2PK65AddressIndex>,
pub height_to_first_p2pkhaddressindex: PcoVec<Height, P2PKHAddressIndex>,
pub height_to_first_p2shaddressindex: PcoVec<Height, P2SHAddressIndex>,
pub height_to_first_p2traddressindex: PcoVec<Height, P2TRAddressIndex>,
pub height_to_first_p2wpkhaddressindex: PcoVec<Height, P2WPKHAddressIndex>,
pub height_to_first_p2wshaddressindex: PcoVec<Height, P2WSHAddressIndex>,
pub height_to_first_txindex: PcoVec<Height, TxIndex>,
pub height_to_first_txinindex: PcoVec<Height, TxInIndex>,
pub height_to_first_txoutindex: PcoVec<Height, TxOutIndex>,
pub height_to_first_unknownoutputindex: PcoVec<Height, UnknownOutputIndex>,
/// Doesn't guarantee continuity due to possible reorgs and more generally the nature of mining
pub height_to_timestamp: CompressedVec<Height, Timestamp>,
pub height_to_total_size: CompressedVec<Height, StoredU64>,
pub height_to_weight: CompressedVec<Height, Weight>,
pub opreturnindex_to_txindex: CompressedVec<OpReturnIndex, TxIndex>,
pub p2aaddressindex_to_p2abytes: RawVec<P2AAddressIndex, P2ABytes>,
pub p2msoutputindex_to_txindex: CompressedVec<P2MSOutputIndex, TxIndex>,
pub p2pk33addressindex_to_p2pk33bytes: RawVec<P2PK33AddressIndex, P2PK33Bytes>,
pub p2pk65addressindex_to_p2pk65bytes: RawVec<P2PK65AddressIndex, P2PK65Bytes>,
pub p2pkhaddressindex_to_p2pkhbytes: RawVec<P2PKHAddressIndex, P2PKHBytes>,
pub p2shaddressindex_to_p2shbytes: RawVec<P2SHAddressIndex, P2SHBytes>,
pub p2traddressindex_to_p2trbytes: RawVec<P2TRAddressIndex, P2TRBytes>,
pub p2wpkhaddressindex_to_p2wpkhbytes: RawVec<P2WPKHAddressIndex, P2WPKHBytes>,
pub p2wshaddressindex_to_p2wshbytes: RawVec<P2WSHAddressIndex, P2WSHBytes>,
pub txindex_to_base_size: CompressedVec<TxIndex, StoredU32>,
pub txindex_to_first_txinindex: CompressedVec<TxIndex, TxInIndex>,
pub txindex_to_first_txoutindex: RawVec<TxIndex, TxOutIndex>,
pub txindex_to_height: CompressedVec<TxIndex, Height>,
pub txindex_to_is_explicitly_rbf: CompressedVec<TxIndex, StoredBool>,
pub txindex_to_rawlocktime: CompressedVec<TxIndex, RawLockTime>,
pub txindex_to_total_size: CompressedVec<TxIndex, StoredU32>,
pub txindex_to_txid: RawVec<TxIndex, Txid>,
pub txindex_to_txversion: CompressedVec<TxIndex, TxVersion>,
pub txinindex_to_outpoint: CompressedVec<TxInIndex, OutPoint>,
pub txoutindex_to_outputtype: RawVec<TxOutIndex, OutputType>,
pub txoutindex_to_txindex: CompressedVec<TxOutIndex, TxIndex>,
pub txoutindex_to_typeindex: RawVec<TxOutIndex, TypeIndex>,
pub txoutindex_to_value: RawVec<TxOutIndex, Sats>,
pub unknownoutputindex_to_txindex: CompressedVec<UnknownOutputIndex, TxIndex>,
pub height_to_timestamp: PcoVec<Height, Timestamp>,
pub height_to_total_size: PcoVec<Height, StoredU64>,
pub height_to_weight: PcoVec<Height, Weight>,
pub opreturnindex_to_txindex: PcoVec<OpReturnIndex, TxIndex>,
pub p2aaddressindex_to_p2abytes: BytesVec<P2AAddressIndex, P2ABytes>,
pub p2msoutputindex_to_txindex: PcoVec<P2MSOutputIndex, TxIndex>,
pub p2pk33addressindex_to_p2pk33bytes: BytesVec<P2PK33AddressIndex, P2PK33Bytes>,
pub p2pk65addressindex_to_p2pk65bytes: BytesVec<P2PK65AddressIndex, P2PK65Bytes>,
pub p2pkhaddressindex_to_p2pkhbytes: BytesVec<P2PKHAddressIndex, P2PKHBytes>,
pub p2shaddressindex_to_p2shbytes: BytesVec<P2SHAddressIndex, P2SHBytes>,
pub p2traddressindex_to_p2trbytes: BytesVec<P2TRAddressIndex, P2TRBytes>,
pub p2wpkhaddressindex_to_p2wpkhbytes: BytesVec<P2WPKHAddressIndex, P2WPKHBytes>,
pub p2wshaddressindex_to_p2wshbytes: BytesVec<P2WSHAddressIndex, P2WSHBytes>,
pub txindex_to_base_size: PcoVec<TxIndex, StoredU32>,
pub txindex_to_first_txinindex: PcoVec<TxIndex, TxInIndex>,
pub txindex_to_first_txoutindex: BytesVec<TxIndex, TxOutIndex>,
pub txindex_to_height: PcoVec<TxIndex, Height>,
pub txindex_to_is_explicitly_rbf: PcoVec<TxIndex, StoredBool>,
pub txindex_to_rawlocktime: PcoVec<TxIndex, RawLockTime>,
pub txindex_to_total_size: PcoVec<TxIndex, StoredU32>,
pub txindex_to_txid: BytesVec<TxIndex, Txid>,
pub txindex_to_txversion: PcoVec<TxIndex, TxVersion>,
pub txinindex_to_outpoint: PcoVec<TxInIndex, OutPoint>,
pub txoutindex_to_outputtype: BytesVec<TxOutIndex, OutputType>,
pub txoutindex_to_txindex: PcoVec<TxOutIndex, TxIndex>,
pub txoutindex_to_typeindex: BytesVec<TxOutIndex, TypeIndex>,
pub txoutindex_to_value: BytesVec<TxOutIndex, Sats>,
pub unknownoutputindex_to_txindex: PcoVec<UnknownOutputIndex, TxIndex>,
}
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,
};

View File

@@ -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 }

View File

@@ -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<Item = &dyn AnyWritableVec>;
}
impl<I, T> Traversable for RawVec<I, T>
// BytesVec implementation
impl<I, T> Traversable for BytesVec<I, T>
where
I: VecIndex,
T: VecValue + Formattable,
T: BytesVecValue + Formattable,
{
fn iter_any_writable(&self) -> impl Iterator<Item = &dyn AnyWritableVec> {
std::iter::once(self as &dyn AnyWritableVec)
@@ -28,10 +29,12 @@ where
}
}
impl<I, T> Traversable for CompressedVec<I, T>
// ZeroCopyVec implementation (only if zerocopy feature enabled)
#[cfg(feature = "zerocopy")]
impl<I, T> Traversable for vecdb::ZeroCopyVec<I, T>
where
I: VecIndex,
T: Pco + Formattable,
T: vecdb::ZeroCopyVecValue + Formattable,
{
fn iter_any_writable(&self) -> impl Iterator<Item = &dyn AnyWritableVec> {
std::iter::once(self as &dyn AnyWritableVec)
@@ -42,10 +45,12 @@ where
}
}
impl<I, T> Traversable for StoredVec<I, T>
// PcoVec implementation (only if pco feature enabled)
#[cfg(feature = "pco")]
impl<I, T> Traversable for vecdb::PcoVec<I, T>
where
I: VecIndex,
T: Pco + Formattable,
T: vecdb::PcoVecValue + Formattable,
{
fn iter_any_writable(&self) -> impl Iterator<Item = &dyn AnyWritableVec> {
std::iter::once(self as &dyn AnyWritableVec)
@@ -56,10 +61,43 @@ where
}
}
impl<I, T> Traversable for EagerVec<I, T>
// LZ4Vec implementation (only if lz4 feature enabled)
#[cfg(feature = "lz4")]
impl<I, T> Traversable for vecdb::LZ4Vec<I, T>
where
I: VecIndex,
T: Pco + Formattable,
T: vecdb::LZ4VecValue + Formattable,
{
fn iter_any_writable(&self) -> impl Iterator<Item = &dyn AnyWritableVec> {
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<I, T> Traversable for vecdb::ZstdVec<I, T>
where
I: VecIndex,
T: vecdb::ZstdVecValue + Formattable,
{
fn iter_any_writable(&self) -> impl Iterator<Item = &dyn AnyWritableVec> {
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<V> Traversable for EagerVec<V>
where
V: StoredVec,
V::T: Formattable,
{
fn iter_any_writable(&self) -> impl Iterator<Item = &dyn AnyWritableVec> {
std::iter::once(self as &dyn AnyWritableVec)
@@ -125,27 +163,6 @@ where
}
}
impl<I, T, S1I, S1T, S2I, S2T, S3I, S3T> Traversable
for ComputedVec<I, T, S1I, S1T, S2I, S2T, S3I, S3T>
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<Item = &dyn AnyWritableVec> {
std::iter::once(self as &dyn AnyWritableVec)
}
fn to_tree_node(&self) -> TreeNode {
TreeNode::Leaf(self.name().to_string())
}
}
impl<T: Traversable + ?Sized> Traversable for Box<T> {
fn to_tree_node(&self) -> TreeNode {
(**self).to_tree_node()

View File

@@ -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"]

View File

@@ -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<ByteView> 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()))
}
}

View File

@@ -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<H: Hasher>(&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<ByteView> 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(),
}
}
}

View File

@@ -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<ByteView> 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()))
}
}

View File

@@ -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<AnyAddressIndex> 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)
// }
// }

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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]);

View File

@@ -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<BlockHash> for BlockHashPrefix {
@@ -33,14 +16,14 @@ impl From<BlockHash> 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<ByteView> 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()))
}
}

View File

@@ -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]

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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);

View File

@@ -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);

View File

@@ -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 {

View File

@@ -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

View File

@@ -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<TypeIndex> for EmptyAddressIndex {

View File

@@ -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<TypeIndex> for EmptyOutputIndex {

View File

@@ -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 {

View File

@@ -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);

View File

@@ -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<bitcoin::locktime::absolute::Height> for Height {
impl TryFrom<&std::path::Path> for Height {
type Error = brk_error::Error;
fn try_from(value: &std::path::Path) -> Result<Self, Self::Error> {
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<ByteView> 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()))
}
}

View File

@@ -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)
}

View File

@@ -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

View File

@@ -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<TypeIndex> for LoadedAddressIndex {

View File

@@ -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);

View File

@@ -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<Cents>,
@@ -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<Dollars>,
@@ -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<Sats>,
@@ -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>(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>(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>(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>(T);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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<OutputType> 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<u8> {
vec![*self as u8]
}
#[inline]
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
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)
}
}

View File

@@ -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<TypeIndex> for P2AAddressIndex {

View File

@@ -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 {

View File

@@ -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<TypeIndex> for P2MSOutputIndex {

View File

@@ -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<TypeIndex> for P2PK33AddressIndex {

View File

@@ -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 {

View File

@@ -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<TypeIndex> for P2PK65AddressIndex {

View File

@@ -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 {

View File

@@ -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<TypeIndex> for P2PKHAddressIndex {

View File

@@ -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 {

View File

@@ -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<TypeIndex> for P2SHAddressIndex {

View File

@@ -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 {

View File

@@ -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<TypeIndex> for P2TRAddressIndex {

View File

@@ -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 {

View File

@@ -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<TypeIndex> for P2WPKHAddressIndex {

View File

@@ -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 {

View File

@@ -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<TypeIndex> for P2WSHAddressIndex {

View File

@@ -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 {

View File

@@ -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")]

View File

@@ -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);

View File

@@ -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<LockTime> for RawLockTime {

View File

@@ -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,

View File

@@ -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);

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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",

View File

@@ -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<Txid> for TxidPrefix {
@@ -33,14 +16,14 @@ impl From<Txid> 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<ByteView> 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()))
}
}

View File

@@ -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<TxIndex> for usize {
impl From<ByteView> 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<TxIndex> for ByteView {
@@ -140,13 +133,6 @@ impl From<TxIndex> 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"

View File

@@ -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);

View File

@@ -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<TxOutIndex> 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"

View File

@@ -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 {

View File

@@ -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<TypeIndex> 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<ByteView> 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<TypeIndex> for ByteView {

View File

@@ -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);

View File

@@ -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<Vout> 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)

View File

@@ -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);

View File

@@ -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<bitcoin::Weight> for Weight {

View File

@@ -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);