From 254af116f4eb0e49dbc3e66afe855fc021269f59 Mon Sep 17 00:00:00 2001 From: skoupidi Date: Mon, 1 Apr 2024 13:14:45 +0300 Subject: [PATCH] blockchain/*: minore code look cleanup --- src/blockchain/block_store.rs | 54 +++++++++++++++++----------------- src/blockchain/header_store.rs | 24 +++++++-------- src/blockchain/tx_store.rs | 42 +++++++++++++------------- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/blockchain/block_store.rs b/src/blockchain/block_store.rs index 304d9b26d..e1795b962 100644 --- a/src/blockchain/block_store.rs +++ b/src/blockchain/block_store.rs @@ -196,13 +196,13 @@ impl BlockStore { if let Some(found) = self.0.get(hash.as_bytes())? { let block = deserialize(&found)?; ret.push(Some(block)); - } else { - if strict { - let s = hash.to_hex().as_str().to_string(); - return Err(Error::BlockNotFound(s)) - } - ret.push(None); + continue } + if strict { + let s = hash.to_hex().as_str().to_string(); + return Err(Error::BlockNotFound(s)) + } + ret.push(None); } Ok(ret) @@ -261,13 +261,13 @@ impl BlockStoreOverlay { if let Some(found) = lock.get(SLED_BLOCK_TREE, hash.as_bytes())? { let block = deserialize(&found)?; ret.push(Some(block)); - } else { - if strict { - let s = hash.to_hex().as_str().to_string(); - return Err(Error::BlockNotFound(s)) - } - ret.push(None); + continue } + if strict { + let s = hash.to_hex().as_str().to_string(); + return Err(Error::BlockNotFound(s)) + } + ret.push(None); } Ok(ret) @@ -340,12 +340,12 @@ impl BlockOrderStore { if let Some(found) = self.0.get(number.to_be_bytes())? { let block_hash = deserialize(&found)?; ret.push(Some(block_hash)); - } else { - if strict { - return Err(Error::BlockNumberNotFound(*number)) - } - ret.push(None); + continue } + if strict { + return Err(Error::BlockNumberNotFound(*number)) + } + ret.push(None); } Ok(ret) @@ -457,12 +457,12 @@ impl BlockOrderStoreOverlay { if let Some(found) = lock.get(SLED_BLOCK_ORDER_TREE, &number.to_be_bytes())? { let block_hash = deserialize(&found)?; ret.push(Some(block_hash)); - } else { - if strict { - return Err(Error::BlockNumberNotFound(*number)) - } - ret.push(None); + continue } + if strict { + return Err(Error::BlockNumberNotFound(*number)) + } + ret.push(None); } Ok(ret) @@ -661,12 +661,12 @@ impl BlockDifficultyStore { if let Some(found) = self.0.get(height.to_be_bytes())? { let block_difficulty = deserialize(&found)?; ret.push(Some(block_difficulty)); - } else { - if strict { - return Err(Error::BlockDifficultyNotFound(*height)) - } - ret.push(None); + continue } + if strict { + return Err(Error::BlockDifficultyNotFound(*height)) + } + ret.push(None); } Ok(ret) diff --git a/src/blockchain/header_store.rs b/src/blockchain/header_store.rs index 59f8d8d89..e45e6cabb 100644 --- a/src/blockchain/header_store.rs +++ b/src/blockchain/header_store.rs @@ -130,13 +130,13 @@ impl HeaderStore { if let Some(found) = self.0.get(hash.as_bytes())? { let header = deserialize(&found)?; ret.push(Some(header)); - } else { - if strict { - let s = hash.to_hex().as_str().to_string(); - return Err(Error::HeaderNotFound(s)) - } - ret.push(None); + continue } + if strict { + let s = hash.to_hex().as_str().to_string(); + return Err(Error::HeaderNotFound(s)) + } + ret.push(None); } Ok(ret) @@ -195,13 +195,13 @@ impl HeaderStoreOverlay { if let Some(found) = lock.get(SLED_HEADER_TREE, hash.as_bytes())? { let header = deserialize(&found)?; ret.push(Some(header)); - } else { - if strict { - let s = hash.to_hex().as_str().to_string(); - return Err(Error::HeaderNotFound(s)) - } - ret.push(None); + continue } + if strict { + let s = hash.to_hex().as_str().to_string(); + return Err(Error::HeaderNotFound(s)) + } + ret.push(None); } Ok(ret) diff --git a/src/blockchain/tx_store.rs b/src/blockchain/tx_store.rs index 31dd95c07..675e42595 100644 --- a/src/blockchain/tx_store.rs +++ b/src/blockchain/tx_store.rs @@ -81,7 +81,7 @@ impl TxStore { /// The resulting vector contains `Option`, which is `Some` if the tx /// was found in the txstore, and otherwise it is `None`, if it has not. /// The second parameter is a boolean which tells the function to fail in - /// case at least one block was not found. + /// case at least one tx was not found. pub fn get( &self, tx_hashes: &[blake3::Hash], @@ -93,13 +93,13 @@ impl TxStore { if let Some(found) = self.0.get(tx_hash.as_bytes())? { let tx = deserialize(&found)?; ret.push(Some(tx)); - } else { - if strict { - let s = tx_hash.to_hex().as_str().to_string(); - return Err(Error::TransactionNotFound(s)) - } - ret.push(None); + continue } + if strict { + let s = tx_hash.to_hex().as_str().to_string(); + return Err(Error::TransactionNotFound(s)) + } + ret.push(None); } Ok(ret) @@ -160,7 +160,7 @@ impl TxStoreOverlay { /// The resulting vector contains `Option`, which is `Some` if the tx /// was found in the overlay, and otherwise it is `None`, if it has not. /// The second parameter is a boolean which tells the function to fail in - /// case at least one block was not found. + /// case at least one tx was not found. pub fn get( &self, tx_hashes: &[blake3::Hash], @@ -173,13 +173,13 @@ impl TxStoreOverlay { if let Some(found) = lock.get(SLED_TX_TREE, tx_hash.as_bytes())? { let tx = deserialize(&found)?; ret.push(Some(tx)); - } else { - if strict { - let s = tx_hash.to_hex().as_str().to_string(); - return Err(Error::TransactionNotFound(s)) - } - ret.push(None); + continue } + if strict { + let s = tx_hash.to_hex().as_str().to_string(); + return Err(Error::TransactionNotFound(s)) + } + ret.push(None); } Ok(ret) @@ -239,7 +239,7 @@ impl PendingTxStore { /// The resulting vector contains `Option`, which is `Some` if the tx /// was found in the pending tx store, and otherwise it is `None`, if it has not. /// The second parameter is a boolean which tells the function to fail in - /// case at least one block was not found. + /// case at least one tx was not found. pub fn get( &self, tx_hashes: &[blake3::Hash], @@ -251,13 +251,13 @@ impl PendingTxStore { if let Some(found) = self.0.get(tx_hash.as_bytes())? { let tx = deserialize(&found)?; ret.push(Some(tx)); - } else { - if strict { - let s = tx_hash.to_hex().as_str().to_string(); - return Err(Error::TransactionNotFound(s)) - } - ret.push(None); + continue } + if strict { + let s = tx_hash.to_hex().as_str().to_string(); + return Err(Error::TransactionNotFound(s)) + } + ret.push(None); } Ok(ret)