mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-24 17:38:09 -07:00
global: fixes
This commit is contained in:
@@ -75,8 +75,8 @@ impl Bytes for SupplyState {
|
|||||||
|
|
||||||
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
|
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
utxo_count: u64::from_bytes(&bytes[0..])?,
|
utxo_count: u64::from_bytes(&bytes[0..8])?,
|
||||||
value: Sats::from_bytes(&bytes[8..])?,
|
value: Sats::from_bytes(&bytes[8..16])?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ pub enum Error {
|
|||||||
ZeroCopyError,
|
ZeroCopyError,
|
||||||
Vecs(vecdb::Error),
|
Vecs(vecdb::Error),
|
||||||
|
|
||||||
WrongLength,
|
WrongLength { expected: usize, received: usize },
|
||||||
WrongAddressType,
|
WrongAddressType,
|
||||||
UnindexableDate,
|
UnindexableDate,
|
||||||
QuickCacheError,
|
QuickCacheError,
|
||||||
@@ -184,8 +184,10 @@ impl fmt::Display for Error {
|
|||||||
Error::VecDB(error) => Display::fmt(&error, f),
|
Error::VecDB(error) => Display::fmt(&error, f),
|
||||||
Error::Vecs(error) => Display::fmt(&error, f),
|
Error::Vecs(error) => Display::fmt(&error, f),
|
||||||
Error::ZeroCopyError => write!(f, "ZeroCopy error"),
|
Error::ZeroCopyError => write!(f, "ZeroCopy error"),
|
||||||
|
Error::WrongLength { expected, received } => write!(
|
||||||
Error::WrongLength => write!(f, "Wrong length"),
|
f,
|
||||||
|
"Wrong length, expected: {expected}, received: {received}"
|
||||||
|
),
|
||||||
Error::QuickCacheError => write!(f, "Quick cache error"),
|
Error::QuickCacheError => write!(f, "Quick cache error"),
|
||||||
Error::WrongAddressType => write!(f, "Wrong address type"),
|
Error::WrongAddressType => write!(f, "Wrong address type"),
|
||||||
Error::UnindexableDate => write!(
|
Error::UnindexableDate => write!(
|
||||||
|
|||||||
@@ -54,9 +54,12 @@ impl TryFrom<(&ScriptBuf, OutputType)> for AddressBytes {
|
|||||||
let bytes = script.as_bytes();
|
let bytes = script.as_bytes();
|
||||||
let bytes = match bytes.len() {
|
let bytes = match bytes.len() {
|
||||||
67 => &bytes[1..66],
|
67 => &bytes[1..66],
|
||||||
_ => {
|
len => {
|
||||||
dbg!(bytes);
|
dbg!(bytes);
|
||||||
return Err(Error::WrongLength);
|
return Err(Error::WrongLength {
|
||||||
|
expected: 67,
|
||||||
|
received: len,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(Self::P2PK65(Box::new(P2PK65Bytes::from(bytes))))
|
Ok(Self::P2PK65(Box::new(P2PK65Bytes::from(bytes))))
|
||||||
@@ -65,9 +68,12 @@ impl TryFrom<(&ScriptBuf, OutputType)> for AddressBytes {
|
|||||||
let bytes = script.as_bytes();
|
let bytes = script.as_bytes();
|
||||||
let bytes = match bytes.len() {
|
let bytes = match bytes.len() {
|
||||||
35 => &bytes[1..34],
|
35 => &bytes[1..34],
|
||||||
_ => {
|
len => {
|
||||||
dbg!(bytes);
|
dbg!(bytes);
|
||||||
return Err(Error::WrongLength);
|
return Err(Error::WrongLength {
|
||||||
|
expected: 35,
|
||||||
|
received: len,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(Self::P2PK33(Box::new(P2PK33Bytes::from(bytes))))
|
Ok(Self::P2PK33(Box::new(P2PK33Bytes::from(bytes))))
|
||||||
|
|||||||
@@ -67,9 +67,9 @@ impl Bytes for EmptyAddressData {
|
|||||||
|
|
||||||
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
|
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
tx_count: u32::from_bytes(&bytes[0..])?,
|
tx_count: u32::from_bytes(&bytes[0..4])?,
|
||||||
funded_txo_count: u32::from_bytes(&bytes[4..])?,
|
funded_txo_count: u32::from_bytes(&bytes[4..8])?,
|
||||||
transfered: Sats::from_bytes(&bytes[8..])?,
|
transfered: Sats::from_bytes(&bytes[8..16])?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,13 +163,13 @@ impl Bytes for LoadedAddressData {
|
|||||||
|
|
||||||
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
|
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
tx_count: u32::from_bytes(&bytes[0..])?,
|
tx_count: u32::from_bytes(&bytes[0..4])?,
|
||||||
funded_txo_count: u32::from_bytes(&bytes[4..])?,
|
funded_txo_count: u32::from_bytes(&bytes[4..8])?,
|
||||||
spent_txo_count: u32::from_bytes(&bytes[8..])?,
|
spent_txo_count: u32::from_bytes(&bytes[8..12])?,
|
||||||
padding: u32::from_bytes(&bytes[12..])?,
|
padding: u32::from_bytes(&bytes[12..16])?,
|
||||||
received: Sats::from_bytes(&bytes[16..])?,
|
received: Sats::from_bytes(&bytes[16..24])?,
|
||||||
sent: Sats::from_bytes(&bytes[24..])?,
|
sent: Sats::from_bytes(&bytes[24..32])?,
|
||||||
realized_cap: Dollars::from_bytes(&bytes[32..])?,
|
realized_cap: Dollars::from_bytes(&bytes[32..40])?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,10 +90,10 @@ impl Bytes for OHLCCents {
|
|||||||
|
|
||||||
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
|
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
open: Open::<Cents>::from_bytes(&bytes[0..])?,
|
open: Open::<Cents>::from_bytes(&bytes[0..8])?,
|
||||||
high: High::<Cents>::from_bytes(&bytes[8..])?,
|
high: High::<Cents>::from_bytes(&bytes[8..16])?,
|
||||||
low: Low::<Cents>::from_bytes(&bytes[16..])?,
|
low: Low::<Cents>::from_bytes(&bytes[16..24])?,
|
||||||
close: Close::<Cents>::from_bytes(&bytes[24..])?,
|
close: Close::<Cents>::from_bytes(&bytes[24..32])?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,10 +202,10 @@ impl Bytes for OHLCDollars {
|
|||||||
|
|
||||||
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
|
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
open: Open::<Dollars>::from_bytes(&bytes[0..])?,
|
open: Open::<Dollars>::from_bytes(&bytes[0..8])?,
|
||||||
high: High::<Dollars>::from_bytes(&bytes[8..])?,
|
high: High::<Dollars>::from_bytes(&bytes[8..16])?,
|
||||||
low: Low::<Dollars>::from_bytes(&bytes[16..])?,
|
low: Low::<Dollars>::from_bytes(&bytes[16..24])?,
|
||||||
close: Close::<Dollars>::from_bytes(&bytes[24..])?,
|
close: Close::<Dollars>::from_bytes(&bytes[24..32])?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -295,10 +295,10 @@ impl Bytes for OHLCSats {
|
|||||||
|
|
||||||
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
|
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
open: Open::<Sats>::from_bytes(&bytes[0..])?,
|
open: Open::<Sats>::from_bytes(&bytes[0..8])?,
|
||||||
high: High::<Sats>::from_bytes(&bytes[8..])?,
|
high: High::<Sats>::from_bytes(&bytes[8..16])?,
|
||||||
low: Low::<Sats>::from_bytes(&bytes[16..])?,
|
low: Low::<Sats>::from_bytes(&bytes[16..24])?,
|
||||||
close: Close::<Sats>::from_bytes(&bytes[24..])?,
|
close: Close::<Sats>::from_bytes(&bytes[24..32])?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -911,9 +911,12 @@ impl Bytes for OutputType {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
|
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
|
||||||
if bytes.is_empty() {
|
if bytes.len() != size_of::<Self>() {
|
||||||
return Err(vecdb::Error::WrongLength);
|
return Err(vecdb::Error::WrongLength {
|
||||||
}
|
expected: size_of::<Self>(),
|
||||||
|
received: bytes.len(),
|
||||||
|
});
|
||||||
|
};
|
||||||
// SAFETY: OutputType is repr(u8) and we're transmuting from u8
|
// SAFETY: OutputType is repr(u8) and we're transmuting from u8
|
||||||
// All values 0-255 are valid (includes dummy variants)
|
// All values 0-255 are valid (includes dummy variants)
|
||||||
let s: Self = unsafe { std::mem::transmute(bytes[0]) };
|
let s: Self = unsafe { std::mem::transmute(bytes[0]) };
|
||||||
|
|||||||
@@ -300,9 +300,12 @@ impl Bytes for PoolId {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
|
fn from_bytes(bytes: &[u8]) -> vecdb::Result<Self> {
|
||||||
if bytes.is_empty() {
|
if bytes.len() != size_of::<Self>() {
|
||||||
return Err(vecdb::Error::WrongLength);
|
return Err(vecdb::Error::WrongLength {
|
||||||
}
|
expected: size_of::<Self>(),
|
||||||
|
received: bytes.len(),
|
||||||
|
});
|
||||||
|
};
|
||||||
// SAFETY: PoolId is repr(u8) and we're transmuting from u8
|
// SAFETY: PoolId is repr(u8) and we're transmuting from u8
|
||||||
// All values 0-255 are valid (includes dummy variants)
|
// All values 0-255 are valid (includes dummy variants)
|
||||||
let s: Self = unsafe { std::mem::transmute(bytes[0]) };
|
let s: Self = unsafe { std::mem::transmute(bytes[0]) };
|
||||||
|
|||||||
Reference in New Issue
Block a user