From d359380e8a827a7e3100918e760b6b8c5ddbe989 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Fri, 11 Dec 2020 13:57:52 +0200 Subject: [PATCH] update primitives & rustfmt --- Cargo.lock | 2 +- src/cache.rs | 47 ++++++++++++++++++++++++++++---------- src/lib.rs | 8 ++++--- src/market.rs | 15 +++++++----- src/sentry_api.rs | 13 ++++++++--- src/status.rs | 6 ++--- src/units_for_slot_test.rs | 2 +- 7 files changed, 64 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4533aea..a68071b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1563,7 +1563,7 @@ dependencies = [ [[package]] name = "primitives" version = "0.1.0" -source = "git+https://github.com/AdExNetwork/adex-validator-stack-rust?branch=bugfixes#92e07547cd7571bc92457fa0009987665a246620" +source = "git+https://github.com/AdExNetwork/adex-validator-stack-rust?branch=bugfixes#8ed5fcbdb328fb16d4ed73ece1cc32514ffeb375" dependencies = [ "async-trait", "chrono", diff --git a/src/cache.rs b/src/cache.rs index 69ba3a7..e57635f 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -321,7 +321,10 @@ mod test { .await; Mock::given(method("GET")) - .and(path(format!("/leader/channel/{}/last-approved", channel_id))) + .and(path(format!( + "/leader/channel/{}/last-approved", + channel_id + ))) .and(query_param("withHeartbeat", "true")) .respond_with(ResponseTemplate::new(200).set_body_json(&leader_last_approved)) .expect(2_u64) @@ -331,10 +334,9 @@ mod test { Mock::given(method("GET")) .and(path(format!( "/leader/channel/{}/validator-messages/{}/NewState", - channel_id, - leader_id + channel_id, leader_id ))) - .and(query_param("limit" ,"1")) + .and(query_param("limit", "1")) .respond_with(ResponseTemplate::new(200).set_body_json(&leader_latest_new_state)) .expect(2_u64) .mount(&mock_server) @@ -348,7 +350,10 @@ mod test { .await; Mock::given(method("GET")) - .and(path(format!("/follower/channel/{}/last-approved", channel_id))) + .and(path(format!( + "/follower/channel/{}/last-approved", + channel_id + ))) .and(query_param("withHeartbeat", "true")) .respond_with(ResponseTemplate::new(200).set_body_json(&follower_last_approved)) .expect(2_u64) @@ -427,7 +432,10 @@ mod test { }; Mock::given(method("GET")) - .and(path(format!("/leader/channel/{}/last-approved", channel_id))) + .and(path(format!( + "/leader/channel/{}/last-approved", + channel_id + ))) .and(query_param("withHeartbeat", "true")) .respond_with(ResponseTemplate::new(200).set_body_json(&leader_last_approved)) .expect(1_u64) @@ -435,7 +443,10 @@ mod test { .await; Mock::given(method("GET")) - .and(path(format!("/follower/channel/{}/last-approved", channel_id))) + .and(path(format!( + "/follower/channel/{}/last-approved", + channel_id + ))) .and(query_param("withHeartbeat", "true")) .respond_with(ResponseTemplate::new(200).set_body_json(&follower_last_approved)) .expect(1_u64) @@ -498,8 +509,11 @@ mod test { }; Mock::given(method("GET")) - .and(path(format!("/leader/channel/{}/last-approved", channel_id))) - .and(query_param("withHeartbeat", "true")) + .and(path(format!( + "/leader/channel/{}/last-approved", + channel_id + ))) + .and(query_param("withHeartbeat", "true")) .respond_with(ResponseTemplate::new(200).set_body_json(&leader_last_approved)) .expect(1_u64) .mount(&mock_server) @@ -600,7 +614,10 @@ mod test { .await; Mock::given(method("GET")) - .and(path(format!("/leader/channel/{}/last-approved", channel_id))) + .and(path(format!( + "/leader/channel/{}/last-approved", + channel_id + ))) .and(query_param("withHeartbeat", "true")) .respond_with(ResponseTemplate::new(200).set_body_json(&leader_last_approved)) // The second time we call is from the Follower Validator to get up to date Status of the Campaign @@ -616,7 +633,10 @@ mod test { .await; Mock::given(method("GET")) - .and(path(format!("/follower/channel/{}/last-approved", channel_id))) + .and(path(format!( + "/follower/channel/{}/last-approved", + channel_id + ))) .and(query_param("withHeartbeat", "true")) .respond_with(ResponseTemplate::new(200).set_body_json(&follower_last_approved)) .expect(2_u64) @@ -718,7 +738,10 @@ mod test { }; Mock::given(method("GET")) - .and(path(format!("/leader/channel/{}/last-approved", channel_id))) + .and(path(format!( + "/leader/channel/{}/last-approved", + channel_id + ))) .and(query_param("withHeartbeat", "true")) .respond_with(ResponseTemplate::new(200).set_body_json(&leader_last_approved)) // The second time we call is from the Follower Validator to get up to date Status of the Campaign diff --git a/src/lib.rs b/src/lib.rs index a4c4dd1..9a4d5bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ #![deny(clippy::all)] #![deny(rust_2018_idioms)] pub use cache::Cache; -use hyper::{Body, Method, Request, Response, Server, Client}; +use hyper::{Body, Client, Method, Request, Response, Server}; use hyper_tls::HttpsConnector; use std::net::SocketAddr; use std::sync::Arc; @@ -104,7 +104,6 @@ pub async fn serve( error!(&logger, "server error: {}", e); } - Ok(()) } @@ -131,7 +130,10 @@ async fn handle( .map(|p_q| { let string = p_q.to_string(); // the MarketUrl (i.e. ApiUrl) always suffixes the path - string.strip_prefix('/').map(ToString::to_string).unwrap_or(string) + string + .strip_prefix('/') + .map(ToString::to_string) + .unwrap_or(string) }) .unwrap_or_default(); diff --git a/src/market.rs b/src/market.rs index a607b1c..f1c67f5 100644 --- a/src/market.rs +++ b/src/market.rs @@ -1,8 +1,8 @@ use primitives::{ market::{Campaign, StatusType}, supermarket::units_for_slot::response::AdUnit, - AdSlot, util::ApiUrl, + AdSlot, }; use reqwest::{Client, Error, StatusCode}; use serde::{Deserialize, Serialize}; @@ -21,7 +21,11 @@ pub struct MarketApi { } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -#[serde(rename_all = "camelCase", from = "ad_slot::ShimResponse", into = "ad_slot::ShimResponse")] +#[serde( + rename_all = "camelCase", + from = "ad_slot::ShimResponse", + into = "ad_slot::ShimResponse" +)] pub struct AdSlotResponse { pub slot: AdSlot, pub accepted_referrers: Vec, @@ -219,9 +223,9 @@ mod ad_slot { use chrono::{DateTime, Utc}; use reqwest::Url; - use serde::{Serialize, Deserialize}; + use serde::{Deserialize, Serialize}; - use primitives::{BigNum, AdSlot, ValidatorId, targeting::Rule}; + use primitives::{targeting::Rule, AdSlot, BigNum, ValidatorId}; #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] #[serde(rename_all = "camelCase")] @@ -302,7 +306,7 @@ mod ad_slot { description: ad_slot.description, website: ad_slot.website, archived: ad_slot.archived, - modified: ad_slot.modified + modified: ad_slot.modified, } } } @@ -322,7 +326,6 @@ mod ad_slot { website: self.website, archived: self.archived, modified: self.modified, - } } } diff --git a/src/sentry_api.rs b/src/sentry_api.rs index 08489a4..b3f46ef 100644 --- a/src/sentry_api.rs +++ b/src/sentry_api.rs @@ -1,9 +1,13 @@ use chrono::Utc; use futures::future::{try_join_all, TryFutureExt}; -use primitives::{Channel, ChannelId, ValidatorDesc, sentry::{ +use primitives::{ + sentry::{ channel_list::ChannelListQuery, ChannelListResponse, LastApprovedResponse, ValidatorMessage, ValidatorMessageResponse, - }, util::ApiUrl}; + }, + util::ApiUrl, + Channel, ChannelId, ValidatorDesc, +}; use reqwest::{Client, Response}; use std::time::Duration; use thiserror::Error; @@ -83,7 +87,10 @@ impl SentryApi { // if the url is wrong `panic!` let url = api_url - .join(&format!("channel/{}/last-approved?withHeartbeat=true", channel_id)) + .join(&format!( + "channel/{}/last-approved?withHeartbeat=true", + channel_id + )) .expect("Url should be valid"); Ok(self.client.get(url).send().await?.json().await?) diff --git a/src/status.rs b/src/status.rs index 820f3dc..8f16249 100644 --- a/src/status.rs +++ b/src/status.rs @@ -221,7 +221,7 @@ pub async fn get_status( }; let follower = channel.spec.validators.follower(); - let follower_la = sentry.get_last_approved(channel.id,&follower).await?; + let follower_la = sentry.get_last_approved(channel.id, &follower).await?; // setup the messages for the checks let messages = Messages { @@ -271,7 +271,7 @@ pub async fn get_status( /// Calls SentryApi for the Leader's LastApproved NewState and returns the NewState Balance async fn fetch_balances(sentry: &SentryApi, channel: &Channel) -> Result { let leader_la = sentry - .get_last_approved(channel.id,&channel.spec.validators.leader()) + .get_last_approved(channel.id, &channel.spec.validators.leader()) .await?; let balances = leader_la @@ -324,7 +324,7 @@ async fn is_rejected_state( }; let latest_new_state = sentry - .get_latest_new_state(channel.id,channel.spec.validators.leader()) + .get_latest_new_state(channel.id, channel.spec.validators.leader()) .await?; let latest_new_state = match latest_new_state { diff --git a/src/units_for_slot_test.rs b/src/units_for_slot_test.rs index 458d8d9..5f24f56 100644 --- a/src/units_for_slot_test.rs +++ b/src/units_for_slot_test.rs @@ -25,7 +25,7 @@ mod units_for_slot_tests { use super::*; use chrono::DateTime; use http::header::USER_AGENT; - use primitives::{Channel, ChannelId, targeting::Rules}; + use primitives::{targeting::Rules, Channel, ChannelId}; // User Agent OS: Linux (only in `woothee`) // User Agent Browser Family: Firefox