Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Implemented clippy comments
Browse files Browse the repository at this point in the history
  • Loading branch information
carllin committed Aug 2, 2018
1 parent 02df062 commit dc3c6d1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
11 changes: 6 additions & 5 deletions src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,13 @@ impl Bank {
}
return Err(BankError::AccountNotFound(tx.from));
}

let bal = option.unwrap();

self.reserve_signature_with_last_id(&tx.sig, &tx.last_id)?;

/// Negative fee shouldn't be possible here, we checked for valid fees when
/// deserializing the transactions
// Negative fee shouldn't be possible here, we checked for valid fees when
// deserializing the transactions
let total_cost_result = tx.instructions.iter().try_fold(tx.fee, |total, i| {
if let Instruction::NewContract(contract) = i {
if contract.tokens < 0 {
Expand Down Expand Up @@ -261,7 +262,7 @@ impl Bank {
/// Apply only a transaction's credits.
/// Note: It is safe to apply credits from multiple transactions in parallel.
fn apply_credits(&self, tx: &Transaction, balances: &mut HashMap<PublicKey, i64>) {
for i in tx.instructions.iter() {
for i in &tx.instructions {
match i {
Instruction::NewContract(contract) => {
let plan = contract.plan.clone();
Expand Down Expand Up @@ -439,7 +440,7 @@ impl Bank {
.expect("invalid ledger: need at least 2 entries");
{
let tx = &entry1.transactions[0];
if tx.instructions.len() == 0 {
if tx.instructions.is_empty() {
panic!("invalid ledger, first transaction is empty");
}

Expand Down Expand Up @@ -701,7 +702,7 @@ mod tests {
let tx = bank.transfer_on_date(1, &mint.keypair(), pubkey, dt, mint.last_id())
.unwrap();

let mut contract_id: Signature = Signature::default();
let contract_id;
if let Instruction::NewContract(contract) = &tx.instructions[0] {
contract_id = contract.id;
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/thin_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
//! unstable and may change in future releases.
use bincode::{deserialize, serialize};
use budget::Condition;
use chrono::prelude::Utc;
use hash::Hash;
use influx_db_client as influxdb;
use metrics;
use payment_plan::Payment;
use request::{Request, Response};
use signature::{KeyPair, PublicKey, Signature};
use std::collections::HashMap;
Expand All @@ -19,7 +16,7 @@ use std::thread::sleep;
use std::time::Duration;
use std::time::Instant;
use timing;
use transaction::{Contract, Transaction, FEE_PER_INSTRUCTION};
use transaction::Transaction;

/// An object for querying and sending transactions to the network.
pub struct ThinClient {
Expand Down Expand Up @@ -282,7 +279,7 @@ impl ThinClient {
for run in 0..(LAST + 1) {
let out = self.poll_get_balance(bob_pubkey);
if expected.is_none() || run == LAST {
return out.ok().clone();
return out.ok();
}
trace!("retry_get_balance[{}] {:?} {:?}", run, out, expected);
if let (Some(e), Ok(o)) = (expected, out) {
Expand All @@ -306,16 +303,19 @@ mod tests {
use super::*;
use bank::Bank;
use budget::Budget;
use budget::Condition::Timestamp;
use chrono::prelude::Utc;
use crdt::TestNode;
use fullnode::FullNode;
use logger;
use mint::Mint;
use payment_plan::Payment;
use service::Service;
use signature::{KeyPair, KeyPairUtil};
use std::io::sink;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use transaction::{Instruction, Plan};
use transaction::{Contract, Instruction, Plan, FEE_PER_INSTRUCTION};

#[test]
fn test_thin_client() {
Expand Down
8 changes: 4 additions & 4 deletions src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Transaction {
let from = from_keypair.pubkey();
let mut tx = Transaction {
sig: Signature::default(),
instructions: instructions,
instructions,
last_id,
from,
fee,
Expand All @@ -146,7 +146,7 @@ impl Transaction {
fee: i64,
last_id: Hash,
) -> Self {
let payment = Payment { tokens: tokens, to };
let payment = Payment { tokens, to };
let budget = Budget::Pay(payment);
let plan = Plan::Budget(budget);
let contract = Contract::new(tokens, plan);
Expand Down Expand Up @@ -229,15 +229,15 @@ impl Transaction {
return false;
}

for i in self.instructions.iter() {
for i in &self.instructions {
if let Instruction::NewContract(contract) = i {
if !contract.plan.verify(contract.tokens) {
return false;
}
}
}

return true;
true
}

/// Verify the number of instructions doesn't exceed the limit, and that
Expand Down
4 changes: 2 additions & 2 deletions src/voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub fn entries_to_votes(entries: &[Entry]) -> Vec<(PublicKey, Vote, Hash)> {
fn transaction_to_votes(tx: &Transaction) -> Vec<(PublicKey, Vote, Hash)> {
tx.instructions
.iter()
.filter_map(|i| match &i {
&Instruction::NewVote(ref vote) => Some((tx.from, vote.clone(), tx.last_id)),
.filter_map(|i| match *i {
Instruction::NewVote(ref vote) => Some((tx.from, vote.clone(), tx.last_id)),
_ => None,
})
.collect()
Expand Down

0 comments on commit dc3c6d1

Please sign in to comment.