diff --git a/backend/src/chain.rs b/backend/src/chain.rs index 0e06d39..5c13773 100644 --- a/backend/src/chain.rs +++ b/backend/src/chain.rs @@ -79,10 +79,8 @@ impl Chain { if &*self.label.0 == label { self.label.1 += 1; - } else { - if count > self.label.1 { - self.rename(label.into(), count); - } + } else if count > self.label.1 { + self.rename(label.into(), count); } } @@ -172,7 +170,7 @@ impl Chain { self.block_times.reset(); self.timestamp = timestamp; - self.serializer.push(feed::BestBlock(self.best.height, timestamp.unwrap_or_else(|| now), None)); + self.serializer.push(feed::BestBlock(self.best.height, timestamp.unwrap_or(now), None)); self.serializer.push(feed::BestFinalized(finalized.height, finalized.hash)); } } @@ -259,7 +257,7 @@ impl Handler for Chain { let nid = self.nodes.add(Node::new(node)); let chain = ctx.address(); - if let Err(_) = rec.do_send(Initialize { nid, conn_id, chain }) { + if rec.do_send(Initialize { nid, conn_id, chain }).is_err() { self.nodes.remove(nid); } else if let Some(node) = self.nodes.get(nid) { self.serializer.push(feed::AddedNode(nid, node)); @@ -456,7 +454,7 @@ impl Handler for Chain { self.serializer.push(feed::TimeSync(now())); self.serializer.push(feed::BestBlock( self.best.height, - self.timestamp.unwrap_or_else(|| 0), + self.timestamp.unwrap_or(0), self.average_block_time, )); self.serializer.push(feed::BestFinalized(self.finalized.height, self.finalized.hash)); diff --git a/backend/src/feed.rs b/backend/src/feed.rs index aeb6216..18e24f5 100644 --- a/backend/src/feed.rs +++ b/backend/src/feed.rs @@ -46,7 +46,7 @@ impl FeedMessageSerializer { } pub fn finalize(&mut self) -> Option { - if self.buffer.len() == 0 { + if self.buffer.is_empty() { return None; } diff --git a/backend/src/main.rs b/backend/src/main.rs index 8ccb27d..3577abe 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -20,10 +20,10 @@ use node::connector::NodeConnector; use types::NodeId; use util::{Locator, LocatorFactory}; -const VERSION: &'static str = env!("CARGO_PKG_VERSION"); -const AUTHORS: &'static str = env!("CARGO_PKG_AUTHORS"); -const NAME: &'static str = "Substrate Telemetry Backend"; -const ABOUT: &'static str = "This is the Telemetry Backend that injects and provide the data sent by Substrate/Polkadot nodes"; +const VERSION: &str = env!("CARGO_PKG_VERSION"); +const AUTHORS: &str = env!("CARGO_PKG_AUTHORS"); +const NAME: &str = "Substrate Telemetry Backend"; +const ABOUT: &str = "This is the Telemetry Backend that injects and provide the data sent by Substrate/Polkadot nodes"; #[derive(Clap)] #[clap(name = NAME, version = VERSION, author = AUTHORS, about = ABOUT)] @@ -54,9 +54,9 @@ enum LogLevel { Trace, } -impl Into for &LogLevel { - fn into(self) -> log::LevelFilter { - match self { +impl From<&LogLevel> for log::LevelFilter { + fn from(log_level: &LogLevel) -> Self { + match log_level { LogLevel::Error => log::LevelFilter::Error, LogLevel::Warn => log::LevelFilter::Warn, LogLevel::Info => log::LevelFilter::Info, @@ -65,6 +65,7 @@ impl Into for &LogLevel { } } } + /// Entry point for connecting nodes #[get("/submit/")] async fn node_route( @@ -74,7 +75,7 @@ async fn node_route( locator: web::Data>, ) -> Result { let ip = req.connection_info().realip_remote_addr().and_then(|mut addr| { - if let Some(port_idx) = addr.find(":") { + if let Some(port_idx) = addr.find(':') { addr = &addr[..port_idx]; } addr.parse::().ok() diff --git a/backend/src/node.rs b/backend/src/node.rs index e3e6563..0c61f46 100644 --- a/backend/src/node.rs +++ b/backend/src/node.rs @@ -89,10 +89,7 @@ impl Node { } pub fn location(&self) -> Option<&NodeLocation> { - match self.location { - Some(ref location) => Some(&**location), - None => None - } + self.location.as_deref() } pub fn update_location(&mut self, location: Arc) { diff --git a/backend/src/node/connector.rs b/backend/src/node/connector.rs index 79fe238..5b8fa2b 100644 --- a/backend/src/node/connector.rs +++ b/backend/src/node/connector.rs @@ -118,7 +118,7 @@ impl NodeConnector { _ => (), } - self.aggregator.do_send(AddNode { rec, conn_id, node }); + self.aggregator.do_send(AddNode { node, conn_id, rec }); } else { if backlog.len() >= 10 { backlog.remove(0); diff --git a/backend/src/util/location.rs b/backend/src/util/location.rs index d4bad3d..7a64fd1 100644 --- a/backend/src/util/location.rs +++ b/backend/src/util/location.rs @@ -26,7 +26,7 @@ impl LocatorFactory { // Default entry for localhost cache.insert( Ipv4Addr::new(127, 0, 0, 1), - Some(Arc::new(NodeLocation { latitude: 52.5166667, longitude: 13.4, city: "Berlin".into() })), + Some(Arc::new(NodeLocation { latitude: 52.516_6667, longitude: 13.4, city: "Berlin".into() })), ); LocatorFactory { @@ -64,7 +64,7 @@ impl IPApiLocate { fn into_node_location(self) -> Option { let IPApiLocate { city, loc } = self; - let mut loc = loc.split(",").map(|n| n.parse()); + let mut loc = loc.split(',').map(|n| n.parse()); let latitude = loc.next()?.ok()?; let longitude = loc.next()?.ok()?; @@ -176,4 +176,4 @@ mod tests { assert!(location.is_none()); } -} \ No newline at end of file +}