Use self/clone

pull/10/head
firejoust 2 years ago
parent ec97d1aa80
commit 1ae46eb09a

@ -23,14 +23,15 @@ impl Blocks {
Ok(blocks)
}
// Returns the references of blocks indexed by state ID
pub fn blocks_by_state_id<'a>(&self, blocks: &'a Vec<Block>) -> DataResult<HashMap<u32, &'a Block>> {
// Returns the blocks indexed by state ID
pub fn blocks_by_state_id(&self) -> DataResult<HashMap<u32, Block>> {
let blocks = self.blocks_array()?;
let mut blocks_map = HashMap::new();
blocks.iter().for_each(|b| {
let min_state_id = b.min_state_id.unwrap_or(b.id << 4);
let max_state_id = b.max_state_id.unwrap_or(min_state_id + 15);
(min_state_id..max_state_id).for_each(|s| {
blocks_map.insert(s, b);
blocks_map.insert(s, b.clone());
});
});

@ -17,8 +17,7 @@ pub fn test_blocks_by_state_id() {
for version in versions {
let api = get_api(version);
let blocks = api.blocks.blocks_array().unwrap();
let by_state = api.blocks.blocks_by_state_id(&blocks);
let by_state = api.blocks.blocks_by_state_id();
assert!(by_state.is_ok());
}
}

Loading…
Cancel
Save