Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Address all warnings/errors from clippy (#27)
Browse files Browse the repository at this point in the history
Co-authored-by: Tuomas Mäkinen <[email protected]>
  • Loading branch information
tuommaki and tuommaki authored Jan 10, 2024
1 parent 301f0e9 commit 77fd479
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 68 deletions.
6 changes: 3 additions & 3 deletions crates/node/src/asset_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl AssetManager {
prover,
verifier,
} => (Program::from(prover), Program::from(verifier)),
_ => return Err(AssetManagerError::IncompatibleTxPayload(tx.hash.clone()).into()),
_ => return Err(AssetManagerError::IncompatibleTxPayload(tx.hash).into()),
};

self.process_program(&prover).await?;
Expand All @@ -125,7 +125,7 @@ impl AssetManager {

let workflow = match tx.payload.clone() {
Payload::Run { workflow } => workflow,
_ => return Err(AssetManagerError::IncompatibleTxPayload(tx.hash.clone()).into()),
_ => return Err(AssetManagerError::IncompatibleTxPayload(tx.hash).into()),
};

// TODO: Ideally the following would happen concurrently for each file...
Expand All @@ -138,7 +138,7 @@ impl AssetManager {
checksum,
} => {
let f = types::File {
tx: tx.hash.clone(),
tx: tx.hash,
name: file_name,
url: file_url,
};
Expand Down
1 change: 1 addition & 0 deletions crates/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ pub enum GenerateCommand {
},
}

#[allow(clippy::large_enum_variant)]
#[derive(Debug, Subcommand)]
pub enum Command {
/// Generate objects.
Expand Down
4 changes: 2 additions & 2 deletions crates/node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ async fn run(config: Arc<Config>) -> Result<()> {
for addr in config.p2p_discovery_addrs.clone() {
tracing::info!("connecting to p2p peer {}", addr);
match addr.to_socket_addrs() {
Ok(socket_iter) => {
for peer in socket_iter {
Ok(mut socket_iter) => {
if let Some(peer) = socket_iter.next() {
p2p.node().connect(peer).await?;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/node/src/mempool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Mempool {

// Broadcast new transaction to P2P network if it's configured.
if let Some(ref tx_chan) = self.tx_chan {
if let Ok(_) = tx_chan.send_tx(&tx).await {
if tx_chan.send_tx(&tx).await.is_ok() {
tx.propagated = true;
self.storage.set(&tx).await?;
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/node/src/networking/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ mod tests {
struct Sink(Arc<Sender<Transaction>>);
impl Sink {
fn new(tx: Arc<Sender<Transaction>>) -> Self {
Self { 0: tx }
Self(tx)
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/node/src/rpc_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl RpcClient {
tx_hash: &Hash,
) -> Result<Option<Transaction>, Box<dyn Error>> {
let mut params = ArrayParams::new();
params.insert(&tx_hash).expect("rpc params");
params.insert(tx_hash).expect("rpc params");

let resp = self
.client
Expand All @@ -40,7 +40,7 @@ impl RpcClient {

pub async fn send_transaction(&self, tx: &Transaction) -> Result<(), Box<dyn Error>> {
let mut params = ArrayParams::new();
params.insert(&tx).expect("rpc params");
params.insert(tx).expect("rpc params");

let resp = self
.client
Expand All @@ -57,7 +57,7 @@ impl RpcClient {

pub async fn get_tx_tree(&self, tx_hash: &Hash) -> Result<TransactionTree, Box<dyn Error>> {
let mut params = ArrayParams::new();
params.insert(&tx_hash).expect("rpc params");
params.insert(tx_hash).expect("rpc params");

let resp = self
.client
Expand Down
6 changes: 2 additions & 4 deletions crates/node/src/rpc_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,11 @@ async fn get_transaction(params: Params<'static>, ctx: Arc<Context>) -> RpcRespo

tracing::info!("JSON-RPC: get_transaction()");

let resp = match ctx.database.find_transaction(&tx_hash).await {
match ctx.database.find_transaction(&tx_hash).await {
Ok(Some(tx)) => RpcResponse::Ok(tx),
Ok(None) => RpcResponse::Err(RpcError::NotFound(tx_hash.to_string())),
Err(e) => RpcResponse::Err(RpcError::NotFound(tx_hash.to_string())),
};

resp
}
}

#[tracing::instrument(level = "info")]
Expand Down
8 changes: 4 additions & 4 deletions crates/node/src/scheduler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ impl TaskManager for Scheduler {
TaskKind::Proof => Transaction {
hash: Hash::default(),
payload: Payload::Proof {
parent: running_task.task.tx.clone(),
prover: program.clone(),
parent: running_task.task.tx,
prover: program,
proof: result.data,
},
nonce,
Expand All @@ -309,8 +309,8 @@ impl TaskManager for Scheduler {
TaskKind::Verification => Transaction {
hash: Hash::default(),
payload: Payload::Verification {
parent: running_task.task.tx.clone(),
verifier: program.clone(),
parent: running_task.task.tx,
verifier: program,
verification: result.data,
},
nonce,
Expand Down
10 changes: 5 additions & 5 deletions crates/node/src/storage/database/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl Database {
.fetch_optional(&self.pool)
.await?;

return Ok(res.is_some());
Ok(res.is_some())
}

pub async fn get_incomplete_assets(&self) -> Result<Vec<Hash>> {
Expand Down Expand Up @@ -352,8 +352,8 @@ impl Database {
let mut txs = Vec::with_capacity(refs.len());
for tx_hash in refs {
let tx = self.find_transaction(&tx_hash).await?;
if tx.is_some() {
txs.push(tx.unwrap());
if let Some(tx) = tx {
txs.push(tx);
}
}

Expand Down Expand Up @@ -494,11 +494,11 @@ impl Database {
let mut db_tx = self.pool.begin().await?;

sqlx::query("DELETE FROM program USING deploy WHERE (program.hash = deploy.prover OR program.hash = deploy.verifier) AND deploy.tx = $1")
.bind(&tx_hash)
.bind(tx_hash)
.execute(&mut *db_tx)
.await?;
sqlx::query("DELETE FROM transaction WHERE hash = $1")
.bind(&tx_hash)
.bind(tx_hash)
.execute(&mut *db_tx)
.await?;

Expand Down
6 changes: 2 additions & 4 deletions crates/node/src/types/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Hash {
pub fn random<R: Rng>(rng: &mut R) -> Hash {
let mut bs = [0u8; HASH_SIZE];
rng.fill_bytes(&mut bs);
Hash { 0: bs }
Hash(bs)
}
}

Expand Down Expand Up @@ -58,9 +58,7 @@ impl From<String> for Hash {

impl From<&[u8]> for Hash {
fn from(value: &[u8]) -> Self {
Self {
0: value.try_into().expect("copy"),
}
Self(value.try_into().expect("copy"))
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/node/src/types/key_capsule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl KeyCapsule {

match self.keys.iter().find(|(recipient, _)| recipient == pk) {
Some((_, key)) => {
let key = ecies::decrypt(sk, &key)?;
let key = ecies::decrypt(sk, key)?;
let msg = ecies::decrypt(&key, self.msg.as_slice())?;
Ok(msg.to_vec())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/node/src/types/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum RpcResponse<T: Clone> {
impl<T: Clone> RpcResponse<T> {
pub fn unwrap(&self) -> T {
if let RpcResponse::Ok(v) = self {
return v.clone();
v.clone()
} else {
// TODO: Consider better debug print here?
panic!("unwrap");
Expand Down
2 changes: 1 addition & 1 deletion crates/node/src/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl Payload {
} => {
buf.append(&mut parent.to_vec());
buf.append(&mut verifier.to_vec());
buf.append(&mut verification.clone().as_mut());
buf.append(verification.clone().as_mut());
}
Payload::Cancel { parent } => {
buf.append(&mut parent.to_vec());
Expand Down
Loading

0 comments on commit 77fd479

Please sign in to comment.