diff --git a/zingo-proxyd/src/server.rs b/zingo-proxyd/src/server.rs index 362b721..a52ae80 100644 --- a/zingo-proxyd/src/server.rs +++ b/zingo-proxyd/src/server.rs @@ -96,5 +96,5 @@ pub async fn spawn_server( .unwrap(); let server = ProxyServer::new(lwd_uri, zebra_uri); - server.serve(proxy_port.clone(), online) + server.serve(*proxy_port, online) } diff --git a/zingo-rpc/build.rs b/zingo-rpc/build.rs index 4dd60db..bc2cb1f 100644 --- a/zingo-rpc/build.rs +++ b/zingo-rpc/build.rs @@ -4,7 +4,7 @@ use std::process::Command; fn main() { // Fetch the commit hash let commit_hash = Command::new("git") - .args(&["rev-parse", "HEAD"]) + .args(["rev-parse", "HEAD"]) .output() .expect("Failed to get commit hash") .stdout; @@ -13,7 +13,7 @@ fn main() { // Fetch the current branch let branch = Command::new("git") - .args(&["rev-parse", "--abbrev-ref", "HEAD"]) + .args(["rev-parse", "--abbrev-ref", "HEAD"]) .output() .expect("Failed to get branch") .stdout; diff --git a/zingo-rpc/src/blockcache/block.rs b/zingo-rpc/src/blockcache/block.rs index a00fadc..024b4b7 100644 --- a/zingo-rpc/src/blockcache/block.rs +++ b/zingo-rpc/src/blockcache/block.rs @@ -101,12 +101,12 @@ impl ParseFromSlice for BlockHeaderData { txid: Option>>, tx_version: Option, ) -> Result<(&[u8], Self), ParseError> { - if txid != None { + if txid.is_some() { return Err(ParseError::InvalidData( "txid must be None for BlockHeaderData::parse_from_slice".to_string(), )); } - if tx_version != None { + if tx_version.is_some() { return Err(ParseError::InvalidData( "tx_version must be None for BlockHeaderData::parse_from_slice".to_string(), )); @@ -189,7 +189,7 @@ impl BlockHeaderData { let mut hasher = Sha256::new(); hasher.update(&serialized_header); let digest = hasher.finalize_reset(); - hasher.update(&digest); + hasher.update(digest); let final_digest = hasher.finalize(); Ok(final_digest.to_vec()) @@ -230,7 +230,7 @@ impl ParseFromSlice for FullBlock { let txid = txid.ok_or_else(|| { ParseError::InvalidData("txid must be used for FullBlock::parse_from_slice".to_string()) })?; - if tx_version != None { + if tx_version.is_some() { return Err(ParseError::InvalidData( "tx_version must be None for FullBlock::parse_from_slice".to_string(), )); @@ -252,9 +252,9 @@ impl ParseFromSlice for FullBlock { let mut remaining_data = &data[cursor.position() as usize..]; for txid_item in txid.iter() { if remaining_data.is_empty() { - return Err(ParseError::InvalidData(format!( - "parsing block transactions: not enough data for transaction.", - ))); + return Err(ParseError::InvalidData( + "parsing block transactions: not enough data for transaction.".to_string(), + )); } let (new_remaining_data, tx) = FullTransaction::parse_from_slice( &data[cursor.position() as usize..], @@ -290,7 +290,7 @@ const GENESIS_TARGET_DIFFICULTY: u32 = 520617983; impl FullBlock { /// Extracts the block height from the coinbase transaction. - pub fn get_block_height(transactions: &Vec) -> Result { + pub fn get_block_height(transactions: &[FullTransaction]) -> Result { let coinbase_script = transactions[0].raw_transaction.transparent_inputs[0] .script_sig .as_slice(); @@ -313,7 +313,7 @@ impl FullBlock { /// Decodes a hex encoded zcash full block into a FullBlock struct. pub fn parse_full_block(data: &[u8], txid: Option>>) -> Result { let (remaining_data, full_block) = Self::parse_from_slice(data, txid, None)?; - if remaining_data.len() != 0 { + if !remaining_data.is_empty() { return Err(ParseError::InvalidData(format!( "Error decoding full block - {} bytes of Remaining data. Compact Block Created: ({:?})", remaining_data.len(), @@ -370,8 +370,8 @@ impl FullBlock { sapling_commitment_tree_size: u32, orchard_commitment_tree_size: u32, ) -> Result { - Ok(Self::parse_full_block(data, txid)? - .to_compact(sapling_commitment_tree_size, orchard_commitment_tree_size)?) + Self::parse_full_block(data, txid)? + .to_compact(sapling_commitment_tree_size, orchard_commitment_tree_size) } } @@ -410,29 +410,21 @@ pub async fn get_block_from_node( time: _, tx: _, trees: _, - }) => { - return Err(ParseError::InvalidData( - "Received object block type, this should not be possible here.".to_string(), - )); - } + }) => Err(ParseError::InvalidData( + "Received object block type, this should not be possible here.".to_string(), + )), Ok(GetBlockResponse::Raw(block_hex)) => Ok(FullBlock::parse_to_compact( block_hex.as_ref(), Some(display_txids_to_server(tx)?), trees.sapling.size as u32, trees.orchard.size as u32, )?), - Err(e) => { - return Err(e.into()); - } + Err(e) => Err(e.into()), } } - Ok(GetBlockResponse::Raw(_)) => { - return Err(ParseError::InvalidData( - "Received raw block type, this should not be possible here.".to_string(), - )); - } - Err(e) => { - return Err(e.into()); - } + Ok(GetBlockResponse::Raw(_)) => Err(ParseError::InvalidData( + "Received raw block type, this should not be possible here.".to_string(), + )), + Err(e) => Err(e.into()), } } diff --git a/zingo-rpc/src/blockcache/mempool.rs b/zingo-rpc/src/blockcache/mempool.rs index 6bbb4ad..62f373d 100644 --- a/zingo-rpc/src/blockcache/mempool.rs +++ b/zingo-rpc/src/blockcache/mempool.rs @@ -25,6 +25,12 @@ pub enum MempoolError { JsonRpcError(#[from] JsonRpcConnectorError), } +impl Default for Mempool { + fn default() -> Self { + Self::new() + } +} + impl Mempool { /// Returns an empty mempool. pub fn new() -> Self { @@ -126,6 +132,6 @@ impl Mempool { &self, ) -> Result, MempoolError> { let best_block_hash = self.best_block_hash.read().await; - Ok(best_block_hash.clone()) + Ok(*best_block_hash) } } diff --git a/zingo-rpc/src/blockcache/transaction.rs b/zingo-rpc/src/blockcache/transaction.rs index 780167b..22a98cd 100644 --- a/zingo-rpc/src/blockcache/transaction.rs +++ b/zingo-rpc/src/blockcache/transaction.rs @@ -27,12 +27,12 @@ impl ParseFromSlice for TxIn { txid: Option>>, tx_version: Option, ) -> Result<(&[u8], Self), ParseError> { - if txid != None { + if txid.is_some() { return Err(ParseError::InvalidData( "txid must be None for TxIn::parse_from_slice".to_string(), )); } - if tx_version != None { + if tx_version.is_some() { return Err(ParseError::InvalidData( "tx_version must be None for TxIn::parse_from_slice".to_string(), )); @@ -71,12 +71,12 @@ impl ParseFromSlice for TxOut { txid: Option>>, tx_version: Option, ) -> Result<(&[u8], Self), ParseError> { - if txid != None { + if txid.is_some() { return Err(ParseError::InvalidData( "txid must be None for TxOut::parse_from_slice".to_string(), )); } - if tx_version != None { + if tx_version.is_some() { return Err(ParseError::InvalidData( "tx_version must be None for TxOut::parse_from_slice".to_string(), )); @@ -95,6 +95,7 @@ impl ParseFromSlice for TxOut { } } +#[allow(clippy::type_complexity)] fn parse_transparent(data: &[u8]) -> Result<(&[u8], Vec, Vec), ParseError> { let mut cursor = Cursor::new(data); @@ -139,7 +140,7 @@ impl ParseFromSlice for Spend { txid: Option>>, tx_version: Option, ) -> Result<(&[u8], Self), ParseError> { - if txid != None { + if txid.is_some() { return Err(ParseError::InvalidData( "txid must be None for Spend::parse_from_slice".to_string(), )); @@ -194,7 +195,7 @@ impl ParseFromSlice for Output { txid: Option>>, tx_version: Option, ) -> Result<(&[u8], Self), ParseError> { - if txid != None { + if txid.is_some() { return Err(ParseError::InvalidData( "txid must be None for Output::parse_from_slice".to_string(), )); @@ -251,12 +252,12 @@ impl ParseFromSlice for JoinSplit { txid: Option>>, tx_version: Option, ) -> Result<(&[u8], Self), ParseError> { - if txid != None { + if txid.is_some() { return Err(ParseError::InvalidData( "txid must be None for JoinSplit::parse_from_slice".to_string(), )); } - if tx_version != None { + if tx_version.is_some() { return Err(ParseError::InvalidData( "tx_version must be None for JoinSplit::parse_from_slice".to_string(), )); @@ -312,12 +313,12 @@ impl ParseFromSlice for Action { txid: Option>>, tx_version: Option, ) -> Result<(&[u8], Self), ParseError> { - if txid != None { + if txid.is_some() { return Err(ParseError::InvalidData( "txid must be None for Action::parse_from_slice".to_string(), )); } - if tx_version != None { + if tx_version.is_some() { return Err(ParseError::InvalidData( "tx_version must be None for Action::parse_from_slice".to_string(), )); @@ -676,7 +677,7 @@ impl ParseFromSlice for FullTransaction { "txid must be used for FullTransaction::parse_from_slice".to_string(), ) })?; - if tx_version != None { + if tx_version.is_some() { return Err(ParseError::InvalidData( "tx_version must be None for FullTransaction::parse_from_slice".to_string(), )); diff --git a/zingo-rpc/src/jsonrpc/connector.rs b/zingo-rpc/src/jsonrpc/connector.rs index 1025613..19a6fef 100644 --- a/zingo-rpc/src/jsonrpc/connector.rs +++ b/zingo-rpc/src/jsonrpc/connector.rs @@ -153,17 +153,17 @@ impl JsonRpcConnector { request_builder.header("Authorization", format!("Basic {}", auth)); } let request_body = serde_json::to_string(&req) - .map_err(|e| JsonRpcConnectorError::SerdeJsonError(e.into()))?; + .map_err(JsonRpcConnectorError::SerdeJsonError)?; let request = request_builder .body(Body::from(request_body)) - .map_err(|e| JsonRpcConnectorError::HttpError(e.into()))?; + .map_err(JsonRpcConnectorError::HttpError)?; let response = client .request(request) .await - .map_err(|e| JsonRpcConnectorError::HyperError(e.into()))?; + .map_err(JsonRpcConnectorError::HyperError)?; let body_bytes = hyper::body::to_bytes(response.into_body()) .await - .map_err(|e| JsonRpcConnectorError::HyperError(e.into()))?; + .map_err(JsonRpcConnectorError::HyperError)?; let body_str = String::from_utf8_lossy(&body_bytes); if body_str.contains("Work queue depth exceeded") { @@ -176,7 +176,7 @@ impl JsonRpcConnector { continue; } let response: RpcResponse = serde_json::from_slice(&body_bytes) - .map_err(|e| JsonRpcConnectorError::SerdeJsonError(e.into()))?; + .map_err(JsonRpcConnectorError::SerdeJsonError)?; return match response.error { Some(error) => Err(JsonRpcConnectorError::new(format!( "RPC Error {}: {}", diff --git a/zingo-rpc/src/jsonrpc/primitives.rs b/zingo-rpc/src/jsonrpc/primitives.rs index 10a6371..e26abe3 100644 --- a/zingo-rpc/src/jsonrpc/primitives.rs +++ b/zingo-rpc/src/jsonrpc/primitives.rs @@ -167,13 +167,12 @@ impl FromHex for ProxySerializedBlock { fn from_hex>(hex: T) -> Result { hex::decode(hex) .map(|bytes| ProxySerializedBlock(SerializedBlock::from(bytes))) - .map_err(|e| e.into()) } } impl AsRef<[u8]> for ProxySerializedBlock { fn as_ref(&self) -> &[u8] { - &self.0.as_ref() + self.0.as_ref() } } diff --git a/zingoproxy-testutils/src/lib.rs b/zingoproxy-testutils/src/lib.rs index bfb0325..41767a9 100644 --- a/zingoproxy-testutils/src/lib.rs +++ b/zingoproxy-testutils/src/lib.rs @@ -125,7 +125,7 @@ pub async fn drop_test_manager( } if let Some(ref path) = temp_conf_path { - if let Err(e) = std::fs::remove_dir_all(&path) { + if let Err(e) = std::fs::remove_dir_all(path) { eprintln!( "@zingoproxyd: Failed to delete temporary regtest configuration directory: {:?}.", e @@ -133,7 +133,7 @@ pub async fn drop_test_manager( } } if let Some(ref path) = Some(temp_wallet_path) { - if let Err(e) = std::fs::remove_dir_all(&path) { + if let Err(e) = std::fs::remove_dir_all(path) { eprintln!( "@zingoproxyd: Failed to delete temporary directory: {:?}.", e @@ -165,7 +165,7 @@ fn set_custom_drops( default_panic_hook(panic_info); online_panic.store(false, std::sync::atomic::Ordering::SeqCst); if let Some(ref path) = temp_conf_path_panic { - if let Err(e) = std::fs::remove_dir_all(&path) { + if let Err(e) = std::fs::remove_dir_all(path) { eprintln!( "@zingoproxyd: Failed to delete temporary regtest config directory: {:?}.", e @@ -173,7 +173,7 @@ fn set_custom_drops( } } if let Some(ref path) = temp_wallet_path_panic { - if let Err(e) = std::fs::remove_dir_all(&path) { + if let Err(e) = std::fs::remove_dir_all(path) { eprintln!( "@zingoproxyd: Failed to delete temporary wallet directory: {:?}.", e @@ -188,7 +188,7 @@ fn set_custom_drops( println!("@zingoproxyd: Received Ctrl+C, exiting."); online_ctrlc.store(false, std::sync::atomic::Ordering::SeqCst); if let Some(ref path) = temp_conf_path_ctrlc { - if let Err(e) = std::fs::remove_dir_all(&path) { + if let Err(e) = std::fs::remove_dir_all(path) { eprintln!( "@zingoproxyd: Failed to delete temporary regtest config directory: {:?}.", e @@ -196,7 +196,7 @@ fn set_custom_drops( } } if let Some(ref path) = temp_wallet_path_ctrlc { - if let Err(e) = std::fs::remove_dir_all(&path) { + if let Err(e) = std::fs::remove_dir_all(path) { eprintln!( "@zingoproxyd: Failed to delete temporary wallet directory: {:?}.", e