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