Skip to content

Commit

Permalink
Implemented clippy comments
Browse files Browse the repository at this point in the history
  • Loading branch information
carllin committed Jul 29, 2018
1 parent 931c4c7 commit 93fad15
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
15 changes: 9 additions & 6 deletions src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,16 @@ impl Bank {
{
let option = bals.get_mut(&tx.from);
if option.is_none() {
if let Instruction::NewVote(_) = &tx.instruction {
inc_new_counter!("bank-appy_debits-vote_account_not_found", 1);
} else {
inc_new_counter!("bank-appy_debits-generic_account_not_found", 1);
for i in &tx.instructions {
if let Instruction::NewVote(_) = i {
inc_new_counter!("bank-appy_debits-vote_account_not_found", 1);
} else {
inc_new_counter!("bank-appy_debits-generic_account_not_found", 1);
}
}
return Err(BankError::AccountNotFound(tx.from));
}

let bal = option.unwrap();

self.reserve_signature_with_last_id(&tx.sig, &tx.last_id)?;
Expand Down Expand Up @@ -250,7 +253,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 @@ -428,7 +431,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
6 changes: 3 additions & 3 deletions src/thin_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,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 Down Expand Up @@ -462,7 +462,7 @@ mod tests {
#[test]
fn test_multiple_transfers() {
logger::setup();
let leader = TestNode::new();
let leader = TestNode::new_localhost();
let alice = Mint::new(10_000);
let bank = Bank::new(&alice);
let bob_pubkey = KeyPair::new().pubkey();
Expand Down Expand Up @@ -538,7 +538,7 @@ mod tests {
#[test]
fn test_contract_fulfillment() {
logger::setup();
let leader = TestNode::new();
let leader = TestNode::new_localhost();
let alice = Mint::new(10_000);
let bank = Bank::new(&alice);
let bob_pubkey = KeyPair::new().pubkey();
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 @@ -20,8 +20,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 93fad15

Please sign in to comment.