Skip to content

Commit dadf4eb

Browse files
committed
cargo fmt + clippy
1 parent 161ebf3 commit dadf4eb

File tree

8 files changed

+105
-70
lines changed

8 files changed

+105
-70
lines changed

primitives/src/sentry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ pub struct ValidationErrorResponse {
637637
}
638638

639639
pub mod channel_list {
640-
use crate::{Channel, ValidatorId, ChainId};
640+
use crate::{ChainId, Channel, ValidatorId};
641641
use serde::{Deserialize, Serialize};
642642

643643
use super::Pagination;

sentry/src/db/accounting.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,13 @@ mod test {
189189
ADVERTISER, ADVERTISER_2, CREATOR, DUMMY_CAMPAIGN, PUBLISHER, PUBLISHER_2,
190190
};
191191

192-
use crate::{db::{
193-
insert_channel,
194-
tests_postgres::{setup_test_migrations, DATABASE_POOL},
195-
}, test_util::setup_dummy_app};
196-
192+
use crate::{
193+
db::{
194+
insert_channel,
195+
tests_postgres::{setup_test_migrations, DATABASE_POOL},
196+
},
197+
test_util::setup_dummy_app,
198+
};
197199

198200
use super::*;
199201

@@ -415,7 +417,6 @@ mod test {
415417
.expect("Channel token should be whitelisted in config!");
416418
let channel_context = channel_chain.with_channel(DUMMY_CAMPAIGN.channel);
417419

418-
419420
// insert the channel into the DB
420421
let channel = insert_channel(&database.pool, &channel_context)
421422
.await

sentry/src/db/campaign.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -571,10 +571,13 @@ mod campaign_remaining {
571571

572572
#[cfg(test)]
573573
mod test {
574-
use crate::{db::{
575-
insert_channel,
576-
tests_postgres::{setup_test_migrations, DATABASE_POOL},
577-
}, test_util::setup_dummy_app};
574+
use crate::{
575+
db::{
576+
insert_channel,
577+
tests_postgres::{setup_test_migrations, DATABASE_POOL},
578+
},
579+
test_util::setup_dummy_app,
580+
};
578581
use chrono::TimeZone;
579582
use primitives::{
580583
campaign,
@@ -610,7 +613,6 @@ mod test {
610613
.expect("Channel token should be whitelisted in config!");
611614
let channel_context = channel_chain.with_channel(DUMMY_CAMPAIGN.channel);
612615

613-
614616
// insert the channel into the DB
615617
let _channel = insert_channel(&database.pool, &channel_context)
616618
.await
@@ -713,8 +715,8 @@ mod test {
713715
.find_chain_of(DUMMY_CAMPAIGN.channel.token)
714716
.expect("Channel token should be whitelisted in config!");
715717
let channel_context = channel_chain.clone().with_channel(DUMMY_CAMPAIGN.channel);
716-
let channel_context_different_leader = channel_chain.with_channel(channel_with_different_leader);
717-
718+
let channel_context_different_leader =
719+
channel_chain.with_channel(channel_with_different_leader);
718720

719721
insert_channel(&database, &channel_context)
720722
.await

sentry/src/db/channel.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use primitives::{Channel, ChannelId, ChainOf};
1+
use primitives::{ChainOf, Channel, ChannelId};
22

33
pub use list_channels::list_channels;
44

@@ -31,7 +31,10 @@ pub async fn get_channel_by_id(
3131
/// ON CONFLICT ON CONSTRAINT channels_pkey DO UPDATE SET created=EXCLUDED.created
3232
/// RETURNING leader, follower, guardian, token, nonce
3333
/// ```
34-
pub async fn insert_channel(pool: &DbPool, channel_chain: &ChainOf<Channel>) -> Result<Channel, PoolError> {
34+
pub async fn insert_channel(
35+
pool: &DbPool,
36+
channel_chain: &ChainOf<Channel>,
37+
) -> Result<Channel, PoolError> {
3538
let client = pool.get().await?;
3639
let chain_id = channel_chain.chain.chain_id;
3740
let channel = channel_chain.context;
@@ -61,7 +64,10 @@ pub async fn insert_channel(pool: &DbPool, channel_chain: &ChainOf<Channel>) ->
6164

6265
mod list_channels {
6366
use primitives::{
64-
sentry::{channel_list::{ChannelListResponse, ChannelListQuery}, Pagination},
67+
sentry::{
68+
channel_list::{ChannelListQuery, ChannelListResponse},
69+
Pagination,
70+
},
6571
Channel,
6672
};
6773

@@ -162,7 +168,10 @@ mod list_channels {
162168
client.query_one(&stmt, &[&validator.to_string()]).await?
163169
}
164170
None => {
165-
let statement = format!("SELECT COUNT(id)::varchar FROM channels WHERE {}", where_clauses.join(" AND "));
171+
let statement = format!(
172+
"SELECT COUNT(id)::varchar FROM channels WHERE {}",
173+
where_clauses.join(" AND ")
174+
);
166175
let stmt = client.prepare(&statement).await?;
167176

168177
client.query_one(&stmt, &[]).await?
@@ -175,12 +184,15 @@ mod list_channels {
175184

176185
#[cfg(test)]
177186
mod test {
178-
use primitives::{test_util::DUMMY_CAMPAIGN, sentry::channel_list::ChannelListQuery, ChainId};
179-
180-
use crate::{db::{
181-
insert_channel,
182-
tests_postgres::{setup_test_migrations, DATABASE_POOL},
183-
}, test_util::setup_dummy_app};
187+
use primitives::{sentry::channel_list::ChannelListQuery, test_util::DUMMY_CAMPAIGN, ChainId};
188+
189+
use crate::{
190+
db::{
191+
insert_channel,
192+
tests_postgres::{setup_test_migrations, DATABASE_POOL},
193+
},
194+
test_util::setup_dummy_app,
195+
};
184196

185197
use super::list_channels::list_channels;
186198

sentry/src/db/spendable.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,13 @@ mod test {
123123
Deposit, UnifiedNum,
124124
};
125125

126-
use crate::{db::{
127-
insert_channel,
128-
tests_postgres::{setup_test_migrations, DATABASE_POOL},
129-
}, test_util::setup_dummy_app};
126+
use crate::{
127+
db::{
128+
insert_channel,
129+
tests_postgres::{setup_test_migrations, DATABASE_POOL},
130+
},
131+
test_util::setup_dummy_app,
132+
};
130133
use tokio::time::{sleep, Duration};
131134

132135
use super::*;

sentry/src/routes/campaign.rs

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,15 @@ where
172172
));
173173
}
174174

175-
let channel_context = app.config.find_chain_of(campaign.channel.token).ok_or_else(|| ResponseError::FailedValidation("Channel token is not whitelisted in this validator".into()))?.with_channel(campaign.channel);
175+
let channel_context = app
176+
.config
177+
.find_chain_of(campaign.channel.token)
178+
.ok_or_else(|| {
179+
ResponseError::FailedValidation(
180+
"Channel token is not whitelisted in this validator".into(),
181+
)
182+
})?
183+
.with_channel(campaign.channel);
176184
// make sure that the Channel is available in the DB
177185
// insert Channel
178186
insert_channel(&app.pool, &channel_context)
@@ -810,11 +818,14 @@ pub mod insert_events {
810818
};
811819
use redis::aio::MultiplexedConnection;
812820

813-
use crate::{db::{
814-
insert_channel,
815-
redis_pool::TESTS_POOL,
816-
tests_postgres::{setup_test_migrations, DATABASE_POOL},
817-
}, test_util::setup_dummy_app};
821+
use crate::{
822+
db::{
823+
insert_channel,
824+
redis_pool::TESTS_POOL,
825+
tests_postgres::{setup_test_migrations, DATABASE_POOL},
826+
},
827+
test_util::setup_dummy_app,
828+
};
818829

819830
use super::*;
820831

@@ -1525,27 +1536,39 @@ mod test {
15251536
.find_chain_of(DUMMY_CAMPAIGN.channel.token)
15261537
.expect("Channel token should be whitelisted in config!");
15271538

1528-
insert_channel(&app.pool, &channel_chain.clone().with_channel(DUMMY_CAMPAIGN.channel))
1529-
.await
1530-
.expect("Should insert dummy channel");
1539+
insert_channel(
1540+
&app.pool,
1541+
&channel_chain.clone().with_channel(DUMMY_CAMPAIGN.channel),
1542+
)
1543+
.await
1544+
.expect("Should insert dummy channel");
15311545
insert_campaign(&app.pool, &DUMMY_CAMPAIGN)
15321546
.await
15331547
.expect("Should insert dummy campaign");
1534-
insert_channel(&app.pool, &channel_chain.clone().with_channel(channel_new_leader))
1535-
.await
1536-
.expect("Should insert dummy channel");
1548+
insert_channel(
1549+
&app.pool,
1550+
&channel_chain.clone().with_channel(channel_new_leader),
1551+
)
1552+
.await
1553+
.expect("Should insert dummy channel");
15371554
insert_campaign(&app.pool, &campaign_new_leader)
15381555
.await
15391556
.expect("Should insert dummy campaign");
1540-
insert_channel(&app.pool, &channel_chain.clone().with_channel(channel_new_follower))
1541-
.await
1542-
.expect("Should insert dummy channel");
1557+
insert_channel(
1558+
&app.pool,
1559+
&channel_chain.clone().with_channel(channel_new_follower),
1560+
)
1561+
.await
1562+
.expect("Should insert dummy channel");
15431563
insert_campaign(&app.pool, &campaign_new_follower)
15441564
.await
15451565
.expect("Should insert dummy campaign");
1546-
insert_channel(&app.pool, &channel_chain.with_channel(channel_new_leader_and_follower))
1547-
.await
1548-
.expect("Should insert dummy channel");
1566+
insert_channel(
1567+
&app.pool,
1568+
&channel_chain.with_channel(channel_new_leader_and_follower),
1569+
)
1570+
.await
1571+
.expect("Should insert dummy channel");
15491572
insert_campaign(&app.pool, &campaign_new_leader_and_follower)
15501573
.await
15511574
.expect("Should insert dummy campaign");

sentry/src/routes/channel.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,8 @@ pub async fn channel_list<C: Locked + 'static>(
5050
.checked_mul(app.config.channels_find_limit.into())
5151
.ok_or_else(|| ResponseError::BadRequest("Page and/or limit is too large".into()))?;
5252

53-
let list_response = list_channels(
54-
&app.pool,
55-
skip,
56-
app.config.channels_find_limit,
57-
&query
58-
)
59-
.await?;
53+
let list_response =
54+
list_channels(&app.pool, skip, app.config.channels_find_limit, &query).await?;
6055

6156
Ok(success_response(serde_json::to_string(&list_response)?))
6257
}
@@ -137,7 +132,7 @@ async fn create_or_update_spendable_document<A: Locked>(
137132
channel_context: &ChainOf<Channel>,
138133
spender: Address,
139134
) -> Result<Spendable, ResponseError> {
140-
insert_channel(&pool, &channel_context).await?;
135+
insert_channel(&pool, channel_context).await?;
141136

142137
let deposit = adapter.get_deposit(channel_context, spender).await?;
143138
let total = UnifiedNum::from_precision(deposit.total, channel_context.token.precision.get());
@@ -610,9 +605,8 @@ pub mod validator_message {
610605
validator_id: &Option<ValidatorId>,
611606
message_types: &[String],
612607
) -> Result<Response<Body>, ResponseError> {
613-
let query = serde_qs::from_str::<ValidatorMessagesListQuery>(
614-
req.uri().query().unwrap_or(""),
615-
)?;
608+
let query =
609+
serde_qs::from_str::<ValidatorMessagesListQuery>(req.uri().query().unwrap_or(""))?;
616610

617611
let channel = req
618612
.extensions()
@@ -1052,10 +1046,10 @@ mod test {
10521046
nonce: Nonce::from(987_654_321_u32),
10531047
};
10541048
let channel_context = app
1055-
.config
1056-
.find_chain_of(channel.token)
1057-
.expect("Dummy channel Token should be present in config!")
1058-
.with(channel);
1049+
.config
1050+
.find_chain_of(channel.token)
1051+
.expect("Dummy channel Token should be present in config!")
1052+
.with(channel);
10591053
insert_channel(&app.pool, &channel_context)
10601054
.await
10611055
.expect("should insert");
@@ -1068,10 +1062,10 @@ mod test {
10681062
nonce: Nonce::from(987_654_322_u32),
10691063
};
10701064
let channel_context = app
1071-
.config
1072-
.find_chain_of(channel_other_token.token)
1073-
.expect("Dummy channel Token should be present in config!")
1074-
.with(channel_other_token);
1065+
.config
1066+
.find_chain_of(channel_other_token.token)
1067+
.expect("Dummy channel Token should be present in config!")
1068+
.with(channel_other_token);
10751069
insert_channel(&app.pool, &channel_context)
10761070
.await
10771071
.expect("should insert");
@@ -1084,10 +1078,10 @@ mod test {
10841078
nonce: Nonce::from(987_654_323_u32),
10851079
};
10861080
let channel_context = app
1087-
.config
1088-
.find_chain_of(channel_other_leader.token)
1089-
.expect("Dummy channel Token should be present in config!")
1090-
.with(channel_other_leader);
1081+
.config
1082+
.find_chain_of(channel_other_leader.token)
1083+
.expect("Dummy channel Token should be present in config!")
1084+
.with(channel_other_leader);
10911085
insert_channel(&app.pool, &channel_context)
10921086
.await
10931087
.expect("should insert");

validator_worker/src/sentry_interface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ pub mod channels {
538538
let query = ChannelListQuery {
539539
page,
540540
validator: Some(validator),
541-
chains: vec![]
541+
chains: vec![],
542542
};
543543

544544
let endpoint = sentry_url

0 commit comments

Comments
 (0)