blockchain: minor changes: avoid using into iterators when call get_all

This commit is contained in:
ghassmo
2022-05-04 02:46:15 +03:00
parent b58058bf31
commit 197568f544
5 changed files with 28 additions and 34 deletions

View File

@@ -82,11 +82,10 @@ impl BlockStore {
pub fn get_all(&self) -> Result<Vec<(blake3::Hash, Block)>> {
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<Vec<(u64, blake3::Hash)>> {
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));

View File

@@ -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<Vec<(blake3::Hash, StreamletMetadata)>> {
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)
}
}

View File

@@ -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<Vec<Nullifier>> {
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)
}
}

View File

@@ -43,10 +43,9 @@ impl RootStore {
pub fn get_all(&self) -> Result<Vec<MerkleNode>> {
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);
}

View File

@@ -75,11 +75,10 @@ impl TxStore {
pub fn get_all(&self) -> Result<Vec<(blake3::Hash, Transaction)>> {
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));
}