diff --git a/zebra-state/src/in_memory.rs b/zebra-state/src/in_memory.rs index f2898db0..81ae72c2 100644 --- a/zebra-state/src/in_memory.rs +++ b/zebra-state/src/in_memory.rs @@ -30,8 +30,10 @@ impl Service for ZebraState { fn call(&mut self, req: Request) -> Self::Future { match req { Request::AddBlock { block } => { - let hash = block.as_ref().into(); - let result = self.index.insert(block).map(|_| Response::Added { hash }); + let result = self + .index + .insert(block) + .map(|hash| Response::Added { hash }); async { result }.boxed() } @@ -48,7 +50,6 @@ impl Service for ZebraState { let result = self .index .get_tip() - .map(|block| block.as_ref().into()) .map(|hash| Response::Tip { hash }) .ok_or_else(|| "zebra-state contains no blocks".into()); diff --git a/zebra-state/src/in_memory/block_index.rs b/zebra-state/src/in_memory/block_index.rs index 87a0c1de..885b24af 100644 --- a/zebra-state/src/in_memory/block_index.rs +++ b/zebra-state/src/in_memory/block_index.rs @@ -17,7 +17,7 @@ impl BlockIndex { pub(super) fn insert( &mut self, block: impl Into>, - ) -> Result<(), Box> { + ) -> Result> { let block = block.into(); let hash = block.as_ref().into(); let height = block.coinbase_height().unwrap(); @@ -26,7 +26,7 @@ impl BlockIndex { Entry::Vacant(entry) => { let _ = entry.insert(block.clone()); let _ = self.by_hash.insert(hash, block); - Ok(()) + Ok(hash) } Entry::Occupied(_) => Err("forks in the chain aren't supported yet")?, } @@ -40,12 +40,12 @@ impl BlockIndex { .cloned() } - pub(super) fn get_tip(&self) -> Option> { + pub(super) fn get_tip(&self) -> Option { self.by_height .iter() .next_back() .map(|(_key, value)| value) - .cloned() + .map(|block| block.as_ref().into()) } }