diff --git a/script/research/blockchain-explorer/src/blocks.rs b/script/research/blockchain-explorer/src/blocks.rs
index 697443c26..f8ae654c8 100644
--- a/script/research/blockchain-explorer/src/blocks.rs
+++ b/script/research/blockchain-explorer/src/blocks.rs
@@ -16,7 +16,8 @@
* along with this program. If not, see .
*/
-use log::{debug, info};
+use log::{debug, warn};
+use sled_overlay::sled::{transaction::ConflictableTransactionError, Transactional};
use tinyjson::JsonValue;
use darkfi::{
@@ -27,7 +28,7 @@ use darkfi::{
util::time::Timestamp,
Error, Result,
};
-use darkfi_sdk::crypto::schnorr::Signature;
+use darkfi_sdk::{crypto::schnorr::Signature, tx::TransactionHash};
use crate::ExplorerService;
@@ -95,7 +96,7 @@ impl ExplorerService {
let tree = db.open_tree(tree_name)?;
tree.clear()?;
let tree_name_str = std::str::from_utf8(tree_name)?;
- info!(target: "blockchain-explorer::blocks", "Successfully reset block tree: {tree_name_str}");
+ debug!(target: "blockchain-explorer::blocks", "Successfully reset block tree: {tree_name_str}");
}
Ok(())
@@ -167,7 +168,7 @@ impl ExplorerService {
// Fetch block by hash and handle encountered errors
match self.db.blockchain.get_blocks_by_hash(&[header_hash]) {
- Ok(blocks) => Ok(Some(BlockRecord::from(&blocks[0]))),
+ Ok(blocks) => Ok(blocks.first().map(BlockRecord::from)),
Err(Error::BlockNotFound(_)) => Ok(None),
Err(e) => Err(Error::DatabaseError(format!(
"[get_block_by_hash] Block retrieval failed: {e:?}"
@@ -175,6 +176,18 @@ impl ExplorerService {
}
}
+ /// Fetch a block given its height from the database.
+ pub fn get_block_by_height(&self, height: u32) -> Result