Skip to content

Commit

Permalink
feat: change CLI get_block to search orphans (#6153)
Browse files Browse the repository at this point in the history
Description
---
Allows the get_block command, to search for the block in the orphan db
as well.

Motivation and Context
---
From the CI we need to be able to see how reorged blocks look.
  • Loading branch information
SWvheerden authored Feb 20, 2024
1 parent ac6997a commit ae1e379
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions applications/minotari_node/src/commands/command/get_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ impl HandleCommand<Args> for CommandContext {
enum ArgsError {
#[error("Block not found at height {height}")]
NotFoundAt { height: u64 },
#[error("Block not found")]
NotFound,
#[error("Serializing/Deserializing error: `{0}`")]
MessageFormatError(String),
}
Expand Down Expand Up @@ -101,20 +99,32 @@ impl CommandContext {
}

pub async fn get_block_by_hash(&self, hash: HashOutput, format: Format) -> Result<(), Error> {
let block = self
.blockchain_db
.fetch_block_by_hash(hash, false)
.await?
.ok_or(ArgsError::NotFound)?;
match format {
Format::Text => println!("{}", block),
Format::Json => println!(
"{}",
block
.to_json()
.map_err(|e| ArgsError::MessageFormatError(format!("{}", e)))?
),
}
let block = self.blockchain_db.fetch_block_by_hash(hash, false).await?;
match block {
Some(block) => match format {
Format::Text => println!("{}", block),
Format::Json => println!(
"{}",
block
.to_json()
.map_err(|e| ArgsError::MessageFormatError(format!("{}", e)))?
),
},
None => {
let block = self.blockchain_db.fetch_orphan(hash).await?;
println!("Found in orphan database");
match format {
Format::Text => println!("{}", block),
Format::Json => println!(
"{}",
block
.to_json()
.map_err(|e| ArgsError::MessageFormatError(format!("{}", e)))?
),
}
},
};

Ok(())
}
}

0 comments on commit ae1e379

Please sign in to comment.