Skip to content

Commit 1fca9ec

Browse files
committed
fix clippy warnings
1 parent 70376b3 commit 1fca9ec

27 files changed

+109
-113
lines changed

adapter/src/dummy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ impl Adapter for DummyAdapter {
9292
Ok(())
9393
}
9494

95-
fn whoami(&self) -> &ValidatorId {
96-
&self.identity
95+
fn whoami(&self) -> ValidatorId {
96+
self.identity
9797
}
9898

9999
fn sign(&self, state_root: &str) -> AdapterResult<String, Self::AdapterError> {

adapter/src/ethereum.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ impl Adapter for EthereumAdapter {
149149
Ok(())
150150
}
151151

152-
fn whoami(&self) -> &ValidatorId {
153-
&self.address
152+
fn whoami(&self) -> ValidatorId {
153+
self.address
154154
}
155155

156156
fn sign(&self, state_root: &str) -> AdapterResult<String, Self::AdapterError> {
@@ -263,7 +263,7 @@ impl Adapter for EthereumAdapter {
263263
address: self.whoami().to_checksum(),
264264
};
265265

266-
ewt_sign(&wallet, &self.keystore_pwd, &payload)
266+
ewt_sign(wallet, &self.keystore_pwd, &payload)
267267
.map_err(|err| AdapterError::Adapter(Error::SignMessage(err).into()))
268268
}
269269

@@ -401,8 +401,8 @@ fn hash_message(message: &[u8]) -> [u8; 32] {
401401
let message_length = message.len();
402402

403403
let mut result = Keccak::new_keccak256();
404-
result.update(&format!("{}{}", eth, message_length).as_bytes());
405-
result.update(&message);
404+
result.update(format!("{}{}", eth, message_length).as_bytes());
405+
result.update(message);
406406

407407
let mut res: [u8; 32] = [0; 32];
408408
result.finalize(&mut res);
@@ -453,7 +453,7 @@ pub fn ewt_sign(
453453
base64::URL_SAFE_NO_PAD,
454454
);
455455
let message = Message::from(hash_message(
456-
&format!("{}.{}", header_encoded, payload_encoded).as_bytes(),
456+
format!("{}.{}", header_encoded, payload_encoded).as_bytes(),
457457
));
458458
let signature: Signature = signer
459459
.sign(password, &message)
@@ -475,7 +475,7 @@ pub fn ewt_verify(
475475
token: &str,
476476
) -> Result<VerifyPayload, EwtVerifyError> {
477477
let message = Message::from(hash_message(
478-
&format!("{}.{}", header_encoded, payload_encoded).as_bytes(),
478+
format!("{}.{}", header_encoded, payload_encoded).as_bytes(),
479479
));
480480

481481
let decoded_signature = base64::decode_config(&token, base64::URL_SAFE_NO_PAD)

adview-manager/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fn get_unit_html(
172172
) -> String {
173173
let image_url = normalize_url(&ad_unit.media_url);
174174

175-
let element_html = if is_video(&ad_unit) {
175+
let element_html = if is_video(ad_unit) {
176176
video_html(on_load, size, &image_url, &ad_unit.media_mime)
177177
} else {
178178
image_html(on_load, size, &image_url)

primitives/src/adapter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub trait Adapter: Send + Sync + fmt::Debug + Clone {
8181
fn unlock(&mut self) -> AdapterResult<(), Self::AdapterError>;
8282

8383
/// Get Adapter whoami
84-
fn whoami(&self) -> &ValidatorId;
84+
fn whoami(&self) -> ValidatorId;
8585

8686
/// Signs the provided state_root
8787
fn sign(&self, state_root: &str) -> AdapterResult<String, Self::AdapterError>;

primitives/src/big_num.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl TryFrom<&str> for BigNum {
243243
type Error = super::DomainError;
244244

245245
fn try_from(num: &str) -> Result<Self, Self::Error> {
246-
let big_uint = BigUint::from_str(&num)
246+
let big_uint = BigUint::from_str(num)
247247
.map_err(|err| super::DomainError::InvalidArgument(err.to_string()))?;
248248

249249
Ok(Self(big_uint))

primitives/src/campaign.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ pub mod validators {
318318
}
319319

320320
pub fn iter(&self) -> Iter<'_> {
321-
Iter::new(&self)
321+
Iter::new(self)
322322
}
323323
}
324324

primitives/src/campaign_validator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Validator for Campaign {
5757
return Err(Validation::UnlistedValidator.into());
5858
}
5959

60-
if !creator_listed(&self, &config.creators_whitelist) {
60+
if !creator_listed(self, &config.creators_whitelist) {
6161
return Err(Validation::UnlistedCreator.into());
6262
}
6363

primitives/src/channel.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ impl SpecValidators {
238238

239239
pub fn find(&self, validator_id: &ValidatorId) -> Option<SpecValidator<'_>> {
240240
if &self.leader().id == validator_id {
241-
Some(SpecValidator::Leader(&self.leader()))
241+
Some(SpecValidator::Leader(self.leader()))
242242
} else if &self.follower().id == validator_id {
243-
Some(SpecValidator::Follower(&self.follower()))
243+
Some(SpecValidator::Follower(self.follower()))
244244
} else {
245245
None
246246
}
@@ -257,7 +257,7 @@ impl SpecValidators {
257257
}
258258

259259
pub fn iter(&self) -> Iter<'_> {
260-
Iter::new(&self)
260+
Iter::new(self)
261261
}
262262
}
263263

primitives/src/sentry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ pub mod campaign_create {
380380
}
381381
}
382382
}
383-
383+
384384
// All editable fields stored in one place, used for checking when a budget is changed
385385
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
386386
pub struct ModifyCampaign {

primitives/src/sentry/accounting.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,18 @@ impl<S: BalancesState> Balances<S> {
6969
Ok(())
7070
}
7171

72-
/// Adds the spender to the Balances with `UnifiedNum::from(0)` if he does not exist
72+
/// Adds the spender to the Balances with `0` if he does not exist
7373
pub fn add_spender(&mut self, spender: Address) {
74-
self.spenders.entry(spender).or_insert(UnifiedNum::from(0));
74+
self.spenders
75+
.entry(spender)
76+
.or_insert_with(UnifiedNum::default);
7577
}
7678

77-
/// Adds the earner to the Balances with `UnifiedNum::from(0)` if he does not exist
79+
/// Adds the earner to the Balances with `0` if he does not exist
7880
pub fn add_earner(&mut self, earner: Address) {
79-
self.earners.entry(earner).or_insert(UnifiedNum::from(0));
81+
self.earners
82+
.entry(earner)
83+
.or_insert_with(UnifiedNum::default);
8084
}
8185
}
8286

primitives/src/util/tests/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ pub fn past_datetime(from: Option<&DateTime<Utc>>) -> DateTime<Utc> {
2525

2626
let from = from.unwrap_or(&default_from);
2727

28-
datetime_between(&from, Some(&to))
28+
datetime_between(from, Some(&to))
2929
}

primitives/src/validator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl ValidatorId {
2727
}
2828

2929
pub fn inner(&self) -> &[u8; 20] {
30-
&self.0.as_bytes()
30+
self.0.as_bytes()
3131
}
3232
}
3333

@@ -53,7 +53,7 @@ impl From<&[u8; 20]> for ValidatorId {
5353

5454
impl AsRef<[u8]> for ValidatorId {
5555
fn as_ref(&self) -> &[u8] {
56-
&self.0.as_ref()
56+
self.0.as_ref()
5757
}
5858
}
5959

sentry/src/access.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub async fn check_access(
4040
let auth_uid = auth.map(|auth| auth.uid.to_string()).unwrap_or_default();
4141

4242
// Rules for events
43-
if forbidden_country(&session) || forbidden_referrer(&session) {
43+
if forbidden_country(session) || forbidden_referrer(session) {
4444
return Err(Error::ForbiddenReferrer);
4545
}
4646

@@ -79,11 +79,11 @@ pub async fn check_access(
7979
let apply_all_rules = try_join_all(rules.iter().map(|rule| {
8080
apply_rule(
8181
redis.clone(),
82-
&rule,
83-
&events,
84-
&campaign,
82+
rule,
83+
events,
84+
campaign,
8585
&auth_uid,
86-
&session,
86+
session,
8787
)
8888
}));
8989

sentry/src/analytics_recorder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ pub async fn record(
114114
.ignore();
115115
}
116116
}
117-
_ => {}
118117
});
119118

120119
if let Err(err) = db.query_async::<_, Option<String>>(&mut conn).await {

sentry/src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub async fn setup_migrations(environment: &str) {
7777
.database_password(POSTGRES_PASSWORD.as_str())
7878
.database_host(POSTGRES_HOST.as_str())
7979
.database_port(*POSTGRES_PORT)
80-
.database_name(&POSTGRES_DB.as_ref().unwrap_or(&POSTGRES_USER))
80+
.database_name(POSTGRES_DB.as_ref().unwrap_or(&POSTGRES_USER))
8181
.build()
8282
.expect("Should build migration settings");
8383

sentry/src/lib.rs

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -125,63 +125,63 @@ impl<A: Adapter + 'static> Application<A> {
125125
None => Default::default(),
126126
};
127127

128-
let req = match Authenticate.call(req, &self).await {
128+
let req = match Authenticate.call(req, self).await {
129129
Ok(req) => req,
130130
Err(error) => return map_response_error(error),
131131
};
132132

133133
let mut response = match (req.uri().path(), req.method()) {
134-
("/cfg", &Method::GET) => config(req, &self).await,
135-
("/channel", &Method::POST) => create_channel(req, &self).await,
136-
("/channel/list", &Method::GET) => channel_list(req, &self).await,
137-
("/channel/validate", &Method::POST) => channel_validate(req, &self).await,
134+
("/cfg", &Method::GET) => config(req, self).await,
135+
("/channel", &Method::POST) => create_channel(req, self).await,
136+
("/channel/list", &Method::GET) => channel_list(req, self).await,
137+
("/channel/validate", &Method::POST) => channel_validate(req, self).await,
138138

139-
("/analytics", &Method::GET) => analytics(req, &self).await,
139+
("/analytics", &Method::GET) => analytics(req, self).await,
140140
("/analytics/advanced", &Method::GET) => {
141-
let req = match AuthRequired.call(req, &self).await {
141+
let req = match AuthRequired.call(req, self).await {
142142
Ok(req) => req,
143143
Err(error) => {
144144
return map_response_error(error);
145145
}
146146
};
147147

148-
advanced_analytics(req, &self).await
148+
advanced_analytics(req, self).await
149149
}
150150
("/analytics/for-advertiser", &Method::GET) => {
151-
let req = match AuthRequired.call(req, &self).await {
151+
let req = match AuthRequired.call(req, self).await {
152152
Ok(req) => req,
153153
Err(error) => {
154154
return map_response_error(error);
155155
}
156156
};
157-
advertiser_analytics(req, &self).await
157+
advertiser_analytics(req, self).await
158158
}
159159
("/analytics/for-publisher", &Method::GET) => {
160-
let req = match AuthRequired.call(req, &self).await {
160+
let req = match AuthRequired.call(req, self).await {
161161
Ok(req) => req,
162162
Err(error) => {
163163
return map_response_error(error);
164164
}
165165
};
166166

167-
publisher_analytics(req, &self).await
167+
publisher_analytics(req, self).await
168168
}
169169
// For creating campaigns
170170
("/v5/campaign", &Method::POST) => {
171-
let req = match AuthRequired.call(req, &self).await {
171+
let req = match AuthRequired.call(req, self).await {
172172
Ok(req) => req,
173173
Err(error) => {
174174
return map_response_error(error);
175175
}
176176
};
177177

178-
create_campaign(req, &self).await
178+
create_campaign(req, self).await
179179
}
180-
(route, _) if route.starts_with("/analytics") => analytics_router(req, &self).await,
180+
(route, _) if route.starts_with("/analytics") => analytics_router(req, self).await,
181181
// This is important because it prevents us from doing
182182
// expensive regex matching for routes without /channel
183-
(path, _) if path.starts_with("/channel") => channels_router(req, &self).await,
184-
(path, _) if path.starts_with("/v5/campaign") => campaigns_router(req, &self).await,
183+
(path, _) if path.starts_with("/channel") => channels_router(req, self).await,
184+
(path, _) if path.starts_with("/v5/campaign") => campaigns_router(req, self).await,
185185
_ => Err(ResponseError::NotFound),
186186
}
187187
.unwrap_or_else(map_response_error);
@@ -198,12 +198,12 @@ async fn campaigns_router<A: Adapter + 'static>(
198198
) -> Result<Response<Body>, ResponseError> {
199199
let (path, method) = (req.uri().path(), req.method());
200200

201-
if let (Some(_caps), &Method::POST) = (CAMPAIGN_UPDATE_BY_ID.captures(&path), method) {
201+
if let (Some(_caps), &Method::POST) = (CAMPAIGN_UPDATE_BY_ID.captures(path), method) {
202202
let req = CampaignLoad.call(req, app).await?;
203203

204204
update_campaign::handle_route(req, app).await
205205
} else if let (Some(caps), &Method::POST) =
206-
(INSERT_EVENTS_BY_CAMPAIGN_ID.captures(&path), method)
206+
(INSERT_EVENTS_BY_CAMPAIGN_ID.captures(path), method)
207207
{
208208
let param = RouteParams(vec![caps
209209
.get(1)
@@ -214,7 +214,7 @@ async fn campaigns_router<A: Adapter + 'static>(
214214

215215
campaign::insert_events::handle_route(req, app).await
216216
} else if let (Some(_caps), &Method::POST) =
217-
(CLOSE_CAMPAIGN_BY_CAMPAIGN_ID.captures(&path), method)
217+
(CLOSE_CAMPAIGN_BY_CAMPAIGN_ID.captures(path), method)
218218
{
219219
// TODO AIP#61: Close campaign:
220220
// - only by creator
@@ -308,16 +308,6 @@ async fn channels_router<A: Adapter + 'static>(
308308
) -> Result<Response<Body>, ResponseError> {
309309
let (path, method) = (req.uri().path().to_owned(), req.method());
310310

311-
// regex matching for routes with params
312-
/* if let (Some(caps), &Method::POST) = (CREATE_EVENTS_BY_CHANNEL_ID.captures(&path), method) {
313-
let param = RouteParams(vec![caps
314-
.get(1)
315-
.map_or("".to_string(), |m| m.as_str().to_string())]);
316-
317-
req.extensions_mut().insert(param);
318-
319-
insert_events(req, app).await
320-
} else */
321311
if let (Some(caps), &Method::GET) = (LAST_APPROVED_BY_CHANNEL_ID.captures(&path), method) {
322312
let param = RouteParams(vec![caps
323313
.get(1)
@@ -353,7 +343,7 @@ async fn channels_router<A: Adapter + 'static>(
353343
}
354344
};
355345

356-
list_validator_messages(req, &app, &extract_params.0, &extract_params.1).await
346+
list_validator_messages(req, app, &extract_params.0, &extract_params.1).await
357347
} else if let (Some(caps), &Method::POST) = (CHANNEL_VALIDATOR_MESSAGES.captures(&path), method)
358348
{
359349
let param = RouteParams(vec![caps
@@ -368,7 +358,7 @@ async fn channels_router<A: Adapter + 'static>(
368358
.apply(req, app)
369359
.await?;
370360

371-
create_validator_messages(req, &app).await
361+
create_validator_messages(req, app).await
372362
} else if let (Some(caps), &Method::GET) = (CHANNEL_EVENTS_AGGREGATES.captures(&path), method) {
373363
req = AuthRequired.call(req, app).await?;
374364

sentry/src/payout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn get_payout(
3535
} => {
3636
let targeting_rules = campaign.targeting_rules.clone();
3737

38-
let pricing = get_pricing_bounds(&campaign, &event_type);
38+
let pricing = get_pricing_bounds(campaign, &event_type);
3939

4040
if targeting_rules.is_empty() {
4141
Ok(Some((*publisher, pricing.min)))

sentry/src/routes/analytics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub async fn process_analytics<A: Adapter>(
8080
app: &Application<A>,
8181
analytics_type: AnalyticsType,
8282
) -> Result<String, ResponseError> {
83-
let query = serde_urlencoded::from_str::<AnalyticsQuery>(&req.uri().query().unwrap_or(""))?;
83+
let query = serde_urlencoded::from_str::<AnalyticsQuery>(req.uri().query().unwrap_or(""))?;
8484
query
8585
.is_valid()
8686
.map_err(|e| ResponseError::BadRequest(e.to_string()))?;
@@ -113,7 +113,7 @@ pub async fn advanced_analytics<A: Adapter>(
113113
let auth = req.extensions().get::<Auth>().expect("auth is required");
114114
let advertiser_channels = advertiser_channel_ids(&app.pool, &auth.uid).await?;
115115

116-
let query = serde_urlencoded::from_str::<AnalyticsQuery>(&req.uri().query().unwrap_or(""))?;
116+
let query = serde_urlencoded::from_str::<AnalyticsQuery>(req.uri().query().unwrap_or(""))?;
117117

118118
let response = get_advanced_reports(
119119
&app.redis,

0 commit comments

Comments
 (0)