Skip to content

Commit ae1e379

Browse files
authored
feat: change CLI get_block to search orphans (#6153)
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.
1 parent ac6997a commit ae1e379

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

applications/minotari_node/src/commands/command/get_block.rs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ impl HandleCommand<Args> for CommandContext {
6262
enum ArgsError {
6363
#[error("Block not found at height {height}")]
6464
NotFoundAt { height: u64 },
65-
#[error("Block not found")]
66-
NotFound,
6765
#[error("Serializing/Deserializing error: `{0}`")]
6866
MessageFormatError(String),
6967
}
@@ -101,20 +99,32 @@ impl CommandContext {
10199
}
102100

103101
pub async fn get_block_by_hash(&self, hash: HashOutput, format: Format) -> Result<(), Error> {
104-
let block = self
105-
.blockchain_db
106-
.fetch_block_by_hash(hash, false)
107-
.await?
108-
.ok_or(ArgsError::NotFound)?;
109-
match format {
110-
Format::Text => println!("{}", block),
111-
Format::Json => println!(
112-
"{}",
113-
block
114-
.to_json()
115-
.map_err(|e| ArgsError::MessageFormatError(format!("{}", e)))?
116-
),
117-
}
102+
let block = self.blockchain_db.fetch_block_by_hash(hash, false).await?;
103+
match block {
104+
Some(block) => match format {
105+
Format::Text => println!("{}", block),
106+
Format::Json => println!(
107+
"{}",
108+
block
109+
.to_json()
110+
.map_err(|e| ArgsError::MessageFormatError(format!("{}", e)))?
111+
),
112+
},
113+
None => {
114+
let block = self.blockchain_db.fetch_orphan(hash).await?;
115+
println!("Found in orphan database");
116+
match format {
117+
Format::Text => println!("{}", block),
118+
Format::Json => println!(
119+
"{}",
120+
block
121+
.to_json()
122+
.map_err(|e| ArgsError::MessageFormatError(format!("{}", e)))?
123+
),
124+
}
125+
},
126+
};
127+
118128
Ok(())
119129
}
120130
}

0 commit comments

Comments
 (0)