Skip to content

Commit

Permalink
Allow parsing only the block header when the txs are not required
Browse files Browse the repository at this point in the history
  • Loading branch information
psgreco committed Oct 5, 2024
1 parent 8ecde42 commit 580aab1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/bin/hal/cmd/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ fn cmd_decode<'a>() -> clap::App<'a, 'a> {
fn exec_decode<'a>(args: &clap::ArgMatches<'a>) {
let hex_tx = util::arg_or_stdin(args, "raw-block");
let raw_tx = hex::decode(hex_tx.as_ref()).need("could not decode raw block hex");
let block: Block = deserialize(&raw_tx).need("invalid block format");

if args.is_present("txids") {
let block: Block = deserialize(&raw_tx).need("invalid block format");
let info = hal::block::BlockInfo {
header: hal::GetInfo::get_info(&block.header, args.network()),
bip34_block_height: block.bip34_block_height().ok(),
Expand All @@ -124,7 +124,14 @@ fn exec_decode<'a>(args: &clap::ArgMatches<'a>) {
};
args.print_output(&info)
} else {
let info = hal::GetInfo::get_info(&block, args.network());
let header: BlockHeader = match deserialize(&raw_tx) {
Ok(header) => header,
Err(_) => {
let block: Block = deserialize(&raw_tx).expect("invalid block format");
block.header
}
};
let info = hal::GetInfo::get_info(&header, args.network());
args.print_output(&info)
}
}

0 comments on commit 580aab1

Please sign in to comment.