Skip to content

Commit

Permalink
bump bitcoin_slices 0.9.2 -> 0.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RCasatta committed Jan 19, 2025
1 parent ce8625d commit 7c0c7d6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ clap = { workspace = true, optional = true, features = ["derive"] }
log = { workspace = true }
glob = "0.3.0"
fxhash = "0.2.1"
bitcoin_slices = { version = "0.9.0", features = ["sha2", "bitcoin"] }
bitcoin_slices = { version = "0.10.0", features = ["sha2", "bitcoin"] }

rand = { version = "0.8.4", optional = true }
rocksdb = { version = "0.22.0", optional = true, default-features = false }
Expand Down
50 changes: 21 additions & 29 deletions lib/src/bsl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bitcoin_slices::bsl::parse_len;
use bitcoin_slices::bsl::scan_len;
use bitcoin_slices::number::{read_u32, read_u8};
use bitcoin_slices::{bsl, Parse, ParseResult};
use bitcoin_slices::{number::U32, number::U8, read_slice, SResult, Visit, Visitor};
use bitcoin_slices::{SResult, Visit, Visitor};

struct BlockExtra<'a> {
slice: &'a [u8],
Expand All @@ -14,67 +15,58 @@ impl<'a> AsRef<[u8]> for BlockExtra<'a> {

impl<'a> Visit<'a> for BlockExtra<'a> {
fn visit<'b, V: Visitor>(slice: &'a [u8], visit: &'b mut V) -> SResult<'a, Self> {
let version = U8::parse(slice)?;
let version_int: u8 = version.parsed().into();
dbg!(version_int);
let version = read_u8(slice)?;
let mut consumed = 1;

let block_size = if version_int == 0 {
let block_size = if version == 0 {
let block = bsl::Block::visit(&slice[consumed..], visit)?;
consumed += block.consumed();
None
} else if version_int == 1 {
let block_size = U32::parse(&slice[consumed..])?;
} else if version == 1 {
let block_size = read_u32(&slice[consumed..])?;
consumed += 4;
let block = bsl::Block::visit(&slice[consumed..], visit)?;
consumed += block.consumed();
Some(block_size)
} else {
panic!("invalid version")
};
dbg!(consumed);

let block_hash = read_slice(&slice[consumed..], 32)?;
let _block_hash = slice
.get(consumed..consumed + 32)
.ok_or(bitcoin_slices::Error::MoreBytesNeeded)?;
consumed += 32;

if block_size.is_none() {
let _ = U32::parse(block_hash.remaining())?;
let _ = read_u32(&slice[consumed..])?;
consumed += 4;
}

dbg!(consumed);
let next_len = parse_len(&slice[consumed..])?;
consumed += next_len.consumed();
let next_len = scan_len(&slice[consumed..], &mut consumed)? as usize;
consumed += 32 * next_len;

for _ in 0..next_len.n() {
let _ = read_slice(&slice[consumed..], 32)?;
consumed += 32;
}

let _ = U32::parse(&slice[consumed..])?;
let _ = read_u32(&slice[consumed..])?;
consumed += 4;

let map_len = U32::parse(&slice[consumed..])?;
let map_len = read_u32(&slice[consumed..])?;
consumed += 4;

for _ in 0u32..map_len.parsed().into() {
for _ in 0u32..map_len {
// add visit extra call
let outpoint = bsl::OutPoint::parse(&slice[consumed..])?;
consumed += outpoint.consumed();
let txout = bsl::TxOut::parse(&slice[consumed..])?;
consumed += txout.consumed();
}
let _ = U32::parse(&slice[consumed..])?;
let _ = read_u32(&slice[consumed..])?;
consumed += 4;
let _ = U32::parse(&slice[consumed..])?;
let _ = read_u32(&slice[consumed..])?;
consumed += 4;
let txids_len = U32::parse(&slice[consumed..])?;
let txids_len = read_u32(&slice[consumed..])? as usize;
consumed += 4;

for _ in 0u32..txids_len.parsed().into() {
let _ = read_slice(&slice[consumed..], 32)?;
consumed += 32;
}
consumed += 32 * txids_len;

let (slice, remaining) = slice.split_at(consumed);
let block_extra = BlockExtra { slice };
Ok(ParseResult::new(remaining, block_extra))
Expand Down

0 comments on commit 7c0c7d6

Please sign in to comment.