Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change CLI get_block to search orphans #6153

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
}
}
Loading