Skip to content

Commit

Permalink
applied clippy changes
Browse files Browse the repository at this point in the history
  • Loading branch information
idky137 committed Jun 18, 2024
1 parent 5460808 commit 420d32d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 55 deletions.
2 changes: 1 addition & 1 deletion zingo-proxyd/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions zingo-rpc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
46 changes: 19 additions & 27 deletions zingo-rpc/src/blockcache/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ impl ParseFromSlice for BlockHeaderData {
txid: Option<Vec<Vec<u8>>>,
tx_version: Option<u32>,
) -> 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(),
));
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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(),
));
Expand All @@ -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..],
Expand Down Expand Up @@ -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<FullTransaction>) -> Result<i32, ParseError> {
pub fn get_block_height(transactions: &[FullTransaction]) -> Result<i32, ParseError> {
let coinbase_script = transactions[0].raw_transaction.transparent_inputs[0]
.script_sig
.as_slice();
Expand All @@ -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<Vec<Vec<u8>>>) -> Result<Self, ParseError> {
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(),
Expand Down Expand Up @@ -370,8 +370,8 @@ impl FullBlock {
sapling_commitment_tree_size: u32,
orchard_commitment_tree_size: u32,
) -> Result<CompactBlock, ParseError> {
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)
}
}

Expand Down Expand Up @@ -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()),
}
}
8 changes: 7 additions & 1 deletion zingo-rpc/src/blockcache/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -126,6 +132,6 @@ impl Mempool {
&self,
) -> Result<Option<zebra_chain::block::Hash>, MempoolError> {
let best_block_hash = self.best_block_hash.read().await;
Ok(best_block_hash.clone())
Ok(*best_block_hash)
}
}
23 changes: 12 additions & 11 deletions zingo-rpc/src/blockcache/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ impl ParseFromSlice for TxIn {
txid: Option<Vec<Vec<u8>>>,
tx_version: Option<u32>,
) -> 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(),
));
Expand Down Expand Up @@ -71,12 +71,12 @@ impl ParseFromSlice for TxOut {
txid: Option<Vec<Vec<u8>>>,
tx_version: Option<u32>,
) -> 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(),
));
Expand All @@ -95,6 +95,7 @@ impl ParseFromSlice for TxOut {
}
}

#[allow(clippy::type_complexity)]
fn parse_transparent(data: &[u8]) -> Result<(&[u8], Vec<TxIn>, Vec<TxOut>), ParseError> {
let mut cursor = Cursor::new(data);

Expand Down Expand Up @@ -139,7 +140,7 @@ impl ParseFromSlice for Spend {
txid: Option<Vec<Vec<u8>>>,
tx_version: Option<u32>,
) -> 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(),
));
Expand Down Expand Up @@ -194,7 +195,7 @@ impl ParseFromSlice for Output {
txid: Option<Vec<Vec<u8>>>,
tx_version: Option<u32>,
) -> 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(),
));
Expand Down Expand Up @@ -251,12 +252,12 @@ impl ParseFromSlice for JoinSplit {
txid: Option<Vec<Vec<u8>>>,
tx_version: Option<u32>,
) -> 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(),
));
Expand Down Expand Up @@ -312,12 +313,12 @@ impl ParseFromSlice for Action {
txid: Option<Vec<Vec<u8>>>,
tx_version: Option<u32>,
) -> 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(),
));
Expand Down Expand Up @@ -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(),
));
Expand Down
10 changes: 5 additions & 5 deletions zingo-rpc/src/jsonrpc/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -176,7 +176,7 @@ impl JsonRpcConnector {
continue;
}
let response: RpcResponse<R> = 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 {}: {}",
Expand Down
3 changes: 1 addition & 2 deletions zingo-rpc/src/jsonrpc/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,12 @@ impl FromHex for ProxySerializedBlock {
fn from_hex<T: AsRef<[u8]>>(hex: T) -> Result<Self, Self::Error> {
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()
}
}

Expand Down
12 changes: 6 additions & 6 deletions zingoproxy-testutils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ 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
);
}
}
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
Expand Down Expand Up @@ -165,15 +165,15 @@ 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
);
}
}
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
Expand All @@ -188,15 +188,15 @@ 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
);
}
}
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
Expand Down

0 comments on commit 420d32d

Please sign in to comment.