From 197568f544826eeef7420a5ad34cfc60e57d12ac Mon Sep 17 00:00:00 2001 From: ghassmo Date: Wed, 4 May 2022 02:46:15 +0300 Subject: [PATCH] blockchain: minor changes: avoid using into iterators when call get_all --- src/blockchain/blockstore.rs | 18 ++++++++---------- src/blockchain/metadatastore.rs | 15 +++++++-------- src/blockchain/nfstore.rs | 13 ++++++------- src/blockchain/rootstore.rs | 7 +++---- src/blockchain/txstore.rs | 9 ++++----- 5 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/blockchain/blockstore.rs b/src/blockchain/blockstore.rs index 8e7d0cccc..965e0e656 100644 --- a/src/blockchain/blockstore.rs +++ b/src/blockchain/blockstore.rs @@ -82,11 +82,10 @@ impl BlockStore { pub fn get_all(&self) -> Result> { let mut blocks = vec![]; - let iterator = self.0.into_iter().enumerate(); - for (_, r) in iterator { - let (k, v) = r.unwrap(); - let hash_bytes: [u8; 32] = k.as_ref().try_into().unwrap(); - let block = deserialize(&v)?; + for block in self.0.iter() { + let (key, value) = block.unwrap(); + let hash_bytes: [u8; 32] = key.as_ref().try_into().unwrap(); + let block = deserialize(&value)?; blocks.push((hash_bytes.into(), block)); } @@ -165,11 +164,10 @@ impl BlockOrderStore { pub fn get_all(&self) -> Result> { let mut slots = vec![]; - let iterator = self.0.into_iter().enumerate(); - for (_, r) in iterator { - let (k, v) = r.unwrap(); - let slot_bytes: [u8; 8] = k.as_ref().try_into().unwrap(); - let hash_bytes: [u8; 32] = v.as_ref().try_into().unwrap(); + for slot in self.0.iter() { + let (key, value) = slot.unwrap(); + let slot_bytes: [u8; 8] = key.as_ref().try_into().unwrap(); + let hash_bytes: [u8; 32] = value.as_ref().try_into().unwrap(); let slot = u64::from_be_bytes(slot_bytes); let hash = blake3::Hash::from(hash_bytes); slots.push((slot, hash)); diff --git a/src/blockchain/metadatastore.rs b/src/blockchain/metadatastore.rs index aa6ab3aec..42d120f40 100644 --- a/src/blockchain/metadatastore.rs +++ b/src/blockchain/metadatastore.rs @@ -88,16 +88,15 @@ impl StreamletMetadataStore { /// (`hash`, `metadata`). /// Be careful as this will try to load everything in memory. pub fn get_all(&self) -> Result> { - let mut ret = vec![]; + let mut hashes = vec![]; - let iterator = self.0.into_iter().enumerate(); - for (_, r) in iterator { - let (k, v) = r.unwrap(); - let hash_bytes: [u8; 32] = k.as_ref().try_into().unwrap(); - let m = deserialize(&v)?; - ret.push((hash_bytes.into(), m)); + for hash in self.0.iter() { + let (key, value) = hash.unwrap(); + let hash_bytes: [u8; 32] = key.as_ref().try_into().unwrap(); + let m = deserialize(&value)?; + hashes.push((hash_bytes.into(), m)); } - Ok(ret) + Ok(hashes) } } diff --git a/src/blockchain/nfstore.rs b/src/blockchain/nfstore.rs index 3b4d1059f..001fb2c94 100644 --- a/src/blockchain/nfstore.rs +++ b/src/blockchain/nfstore.rs @@ -42,15 +42,14 @@ impl NullifierStore { /// Retrieve all nullifiers from the store. /// Be careful as this will try to load everything in memory. pub fn get_all(&self) -> Result> { - let mut nfs = vec![]; + let mut nullifiers = vec![]; - let iterator = self.0.into_iter().enumerate(); - for (_, r) in iterator { - let (k, _) = r.unwrap(); - let nullifier = deserialize(&k)?; - nfs.push(nullifier); + for nullifier in self.0.iter() { + let (key, _) = nullifier.unwrap(); + let nullifier = deserialize(&key)?; + nullifiers.push(nullifier); } - Ok(nfs) + Ok(nullifiers) } } diff --git a/src/blockchain/rootstore.rs b/src/blockchain/rootstore.rs index 6b89e23de..ff227b3cc 100644 --- a/src/blockchain/rootstore.rs +++ b/src/blockchain/rootstore.rs @@ -43,10 +43,9 @@ impl RootStore { pub fn get_all(&self) -> Result> { let mut roots = vec![]; - let iterator = self.0.into_iter().enumerate(); - for (_, r) in iterator { - let (k, _) = r.unwrap(); - let root = deserialize(&k)?; + for root in self.0.iter() { + let (key, _) = root.unwrap(); + let root = deserialize(&key)?; roots.push(root); } diff --git a/src/blockchain/txstore.rs b/src/blockchain/txstore.rs index c7ac8edac..8ba0e35fe 100644 --- a/src/blockchain/txstore.rs +++ b/src/blockchain/txstore.rs @@ -75,11 +75,10 @@ impl TxStore { pub fn get_all(&self) -> Result> { let mut txs = vec![]; - let iterator = self.0.into_iter().enumerate(); - for (_, r) in iterator { - let (k, v) = r.unwrap(); - let hash_bytes: [u8; 32] = k.as_ref().try_into().unwrap(); - let tx = deserialize(&v)?; + for tx in self.0.iter() { + let (key, value) = tx.unwrap(); + let hash_bytes: [u8; 32] = key.as_ref().try_into().unwrap(); + let tx = deserialize(&value)?; txs.push((hash_bytes.into(), tx)); }