Clippy review
This commit is contained in:
parent
7488d19ae6
commit
117ab0c141
|
@ -9,7 +9,7 @@ use plan::{Plan, Witness};
|
|||
use transaction::Transaction;
|
||||
use signature::{KeyPair, PublicKey, Signature};
|
||||
use mint::Mint;
|
||||
use historian::{reserve_signature, Historian};
|
||||
use historian::Historian;
|
||||
use recorder::Signal;
|
||||
use std::sync::mpsc::SendError;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
@ -116,7 +116,7 @@ impl Accountant {
|
|||
tr: &Transaction,
|
||||
allow_deposits: bool,
|
||||
) -> Result<()> {
|
||||
if !reserve_signature(&mut self.historian.signatures, &tr.sig) {
|
||||
if !self.historian.reserve_signature(&tr.sig) {
|
||||
return Err(AccountingError::InvalidTransferSignature);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,8 +35,7 @@ impl Event {
|
|||
pub fn get_signature(&self) -> Option<Signature> {
|
||||
match *self {
|
||||
Event::Transaction(ref tr) => Some(tr.sig),
|
||||
Event::Signature { .. } => None,
|
||||
Event::Timestamp { .. } => None,
|
||||
Event::Signature { .. } | Event::Timestamp { .. } => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,14 @@ impl Historian {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn reserve_signature(&mut self, sig: &Signature) -> bool {
|
||||
if self.signatures.contains(sig) {
|
||||
return false;
|
||||
}
|
||||
self.signatures.insert(*sig);
|
||||
true
|
||||
}
|
||||
|
||||
/// A background thread that will continue tagging received Event messages and
|
||||
/// sending back Entry messages until either the receiver or sender channel is closed.
|
||||
fn create_recorder(
|
||||
|
@ -55,14 +63,6 @@ impl Historian {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn reserve_signature(sigs: &mut HashSet<Signature>, sig: &Signature) -> bool {
|
||||
if sigs.contains(sig) {
|
||||
return false;
|
||||
}
|
||||
sigs.insert(*sig);
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -112,10 +112,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_duplicate_event_signature() {
|
||||
let mut sigs = HashSet::new();
|
||||
let zero = Hash::default();
|
||||
let mut hist = Historian::new(&zero, None);
|
||||
let sig = Signature::default();
|
||||
assert!(reserve_signature(&mut sigs, &sig));
|
||||
assert!(!reserve_signature(&mut sigs, &sig));
|
||||
assert!(hist.reserve_signature(&sig));
|
||||
assert!(!hist.reserve_signature(&sig));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -68,10 +68,10 @@ impl Packet {
|
|||
match *a {
|
||||
SocketAddr::V4(v4) => {
|
||||
let ip = v4.ip().octets();
|
||||
self.addr[0] = ip[0] as u16;
|
||||
self.addr[1] = ip[1] as u16;
|
||||
self.addr[2] = ip[2] as u16;
|
||||
self.addr[3] = ip[3] as u16;
|
||||
self.addr[0] = u16::from(ip[0]);
|
||||
self.addr[1] = u16::from(ip[1]);
|
||||
self.addr[2] = u16::from(ip[2]);
|
||||
self.addr[3] = u16::from(ip[3]);
|
||||
self.port = a.port();
|
||||
}
|
||||
SocketAddr::V6(v6) => {
|
||||
|
@ -83,7 +83,7 @@ impl Packet {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct PacketData {
|
||||
pub packets: Vec<Packet>,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue