computer: blk metadata fixes

This commit is contained in:
nym21
2025-09-19 16:45:57 +02:00
parent 43117825d7
commit 23f6397a97
18 changed files with 197 additions and 205 deletions

View File

@@ -11,7 +11,6 @@ build = "build.rs"
[dependencies]
allocative = { workspace = true }
allocative_derive = { workspace = true }
bitcoin = { workspace = true }
bitcoincore-rpc = { workspace = true }
brk_error = {workspace = true}

View File

@@ -0,0 +1,29 @@
use crate::BlkPosition;
#[derive(Debug)]
pub struct BlkMetadata {
position: BlkPosition,
len: u32,
}
impl BlkMetadata {
pub fn new(position: BlkPosition, len: u32) -> Self {
Self { position, len }
}
pub fn position(&self) -> BlkPosition {
self.position
}
pub fn blk_index(&self) -> u16 {
self.position.blk_index()
}
pub fn offset(&self) -> u32 {
self.position.offset()
}
#[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> u32 {
self.len
}
}

View File

@@ -1,3 +1,5 @@
use std::ops::Add;
use serde::Serialize;
use vecdb::StoredCompressed;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -13,10 +15,17 @@ impl BlkPosition {
}
pub fn blk_index(&self) -> u16 {
(self.0 >> 31) as u16
(self.0 >> 32) as u16
}
pub fn offset(&self) -> u32 {
self.0 as u32
}
}
impl Add<u32> for BlkPosition {
type Output = Self;
fn add(self, rhs: u32) -> Self::Output {
Self(self.0 + rhs as u64)
}
}

View File

@@ -1,6 +1,6 @@
use std::{borrow::Cow, ops::Deref};
use crate::BlkPosition;
use crate::BlkMetadata;
use super::{BlockHash, Height};
@@ -58,27 +58,27 @@ impl Deref for Block {
#[derive(Debug)]
pub struct ParsedBlock {
block: Block,
position: BlkPosition,
tx_positions: Vec<BlkPosition>,
metadata: BlkMetadata,
tx_metadata: Vec<BlkMetadata>,
}
impl From<(Block, BlkPosition, Vec<BlkPosition>)> for ParsedBlock {
fn from((block, position, tx_positions): (Block, BlkPosition, Vec<BlkPosition>)) -> Self {
impl From<(Block, BlkMetadata, Vec<BlkMetadata>)> for ParsedBlock {
fn from((block, metadata, tx_metadata): (Block, BlkMetadata, Vec<BlkMetadata>)) -> Self {
Self {
block,
position,
tx_positions,
metadata,
tx_metadata,
}
}
}
impl ParsedBlock {
pub fn position(&self) -> &BlkPosition {
&self.position
pub fn metadata(&self) -> &BlkMetadata {
&self.metadata
}
pub fn tx_positions(&self) -> &Vec<BlkPosition> {
&self.tx_positions
pub fn tx_metadata(&self) -> &Vec<BlkMetadata> {
&self.tx_metadata
}
}

View File

@@ -4,6 +4,7 @@ mod addressbytes;
mod addressbyteshash;
mod anyaddressindex;
mod bitcoin;
mod blkmetadata;
mod blkposition;
mod block;
mod blockhash;
@@ -69,6 +70,7 @@ pub use addressbytes::*;
pub use addressbyteshash::*;
pub use anyaddressindex::*;
pub use bitcoin::*;
pub use blkmetadata::*;
pub use blkposition::*;
pub use block::*;
pub use blockhash::*;