Skip to content

Commit e89be3c

Browse files
committed
fix: apply formatting
1 parent f5651f9 commit e89be3c

File tree

3 files changed

+53
-24
lines changed

3 files changed

+53
-24
lines changed

sentry/src/db.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ pub async fn setup_migrations(environment: &str) {
8484

8585
let mut migrations = vec![make_migration!("20190806011140_initial-tables")];
8686

87-
8887
if environment == "development" {
8988
// seeds database tables for testing
9089
migrations.push(make_migration!("20190806011140_initial-tables/seed"));

sentry/src/db/event_aggregate.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ use bb8_postgres::tokio_postgres::types::{ToSql, Type};
55
use bb8_postgres::tokio_postgres::Error;
66
use chrono::{DateTime, Utc};
77
use futures::pin_mut;
8-
use primitives::sentry::{EventAggregate, ApproveStateValidatorMessage, NewStateValidatorMessage, HeartbeatValidatorMessage};
8+
use primitives::sentry::{
9+
ApproveStateValidatorMessage, EventAggregate, HeartbeatValidatorMessage,
10+
NewStateValidatorMessage,
11+
};
912
use primitives::BigNum;
10-
use primitives::{ChannelId, ValidatorId, Channel};
13+
use primitives::{Channel, ChannelId, ValidatorId};
1114
use std::ops::Add;
1215

13-
14-
pub async fn lastest_approve_state(
16+
pub async fn lastest_approve_state(
1517
pool: &DbPool,
16-
channel: &Channel
18+
channel: &Channel,
1719
) -> Result<Option<ApproveStateValidatorMessage>, RunError<bb8_postgres::tokio_postgres::Error>> {
1820
pool
1921
.run(move |connection| {
@@ -53,7 +55,7 @@ pub async fn latest_new_state(
5355
pub async fn latest_heartbeats(
5456
pool: &DbPool,
5557
channel_id: &ChannelId,
56-
validator_id: ValidatorId
58+
validator_id: ValidatorId,
5759
) -> Result<Vec<HeartbeatValidatorMessage>, RunError<bb8_postgres::tokio_postgres::Error>> {
5860
pool
5961
.run(move |connection| {

sentry/src/routes/channel.rs

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use self::channel_list::{ChannelListQuery, LastApprovedQuery};
2+
use crate::db::event_aggregate::{lastest_approve_state, latest_heartbeats, latest_new_state};
23
use crate::db::{get_channel_by_id, insert_channel, insert_validator_messages, list_channels};
3-
use crate::db::event_aggregate::{ lastest_approve_state, latest_new_state, latest_heartbeats};
44
use crate::success_response;
55
use crate::Application;
66
use crate::ResponseError;
@@ -11,7 +11,7 @@ use hex::FromHex;
1111
use hyper::{Body, Request, Response};
1212
use primitives::adapter::Adapter;
1313
use primitives::channel::SpecValidator;
14-
use primitives::sentry::{Event, SuccessResponse, LastApprovedResponse, LastApproved};
14+
use primitives::sentry::{Event, LastApproved, LastApprovedResponse, SuccessResponse};
1515
use primitives::validator::MessageTypes;
1616
use primitives::{Channel, ChannelId};
1717
use slog::error;
@@ -99,43 +99,71 @@ pub async fn last_approved<A: Adapter>(
9999
.extensions()
100100
.get::<RouteParams>()
101101
.expect("request should have route params");
102-
102+
103103
let channel_id = ChannelId::from_hex(route_params.index(0))?;
104104
let channel = get_channel_by_id(&app.pool, &channel_id).await?.unwrap();
105105

106106
let approve_state = lastest_approve_state(&app.pool, &channel).await?;
107107
if approve_state.is_none() {
108108
return Ok(Response::builder()
109-
.header("Content-type", "application/json")
110-
.body(serde_json::to_string(&LastApprovedResponse{ last_approved: None, heartbeats: None })?.into())
111-
.unwrap())
109+
.header("Content-type", "application/json")
110+
.body(
111+
serde_json::to_string(&LastApprovedResponse {
112+
last_approved: None,
113+
heartbeats: None,
114+
})?
115+
.into(),
116+
)
117+
.unwrap());
112118
}
113119

114-
let state_root = approve_state.as_ref().expect("value should be present").msg.state_root.clone();
120+
let state_root = approve_state
121+
.as_ref()
122+
.expect("value should be present")
123+
.msg
124+
.state_root
125+
.clone();
115126
let new_state = latest_new_state(&app.pool, &channel, &state_root).await?;
116127
if new_state.is_none() {
117128
return Ok(Response::builder()
118-
.header("Content-type", "application/json")
119-
.body(serde_json::to_string(&LastApprovedResponse{ last_approved: None, heartbeats: None })?.into())
120-
.unwrap())
129+
.header("Content-type", "application/json")
130+
.body(
131+
serde_json::to_string(&LastApprovedResponse {
132+
last_approved: None,
133+
heartbeats: None,
134+
})?
135+
.into(),
136+
)
137+
.unwrap());
121138
}
122139

123140
let query = serde_urlencoded::from_str::<LastApprovedQuery>(&req.uri().query().unwrap_or(""))?;
124-
let validators = channel.spec.validators;
141+
let validators = channel.spec.validators;
125142
let channel_id = channel.id;
126143
let heartbeats = if query.with_heartbeat.is_some() {
127144
let result = try_join_all(
128-
validators.into_iter()
129-
.map(|validator| latest_heartbeats(&app.pool, &channel_id, validator.id.clone()))
130-
).await?;
145+
validators
146+
.into_iter()
147+
.map(|validator| latest_heartbeats(&app.pool, &channel_id, validator.id.clone())),
148+
)
149+
.await?;
131150
Some(result.into_iter().flatten().collect::<Vec<_>>())
132151
} else {
133152
None
134153
};
135154

136155
Ok(Response::builder()
137156
.header("Content-type", "application/json")
138-
.body(serde_json::to_string(&&LastApprovedResponse{ last_approved: Some(LastApproved { new_state, approve_state }), heartbeats })?.into())
157+
.body(
158+
serde_json::to_string(&&LastApprovedResponse {
159+
last_approved: Some(LastApproved {
160+
new_state,
161+
approve_state,
162+
}),
163+
heartbeats,
164+
})?
165+
.into(),
166+
)
139167
.unwrap())
140168
}
141169

@@ -239,9 +267,9 @@ mod channel_list {
239267
#[derive(Debug, Deserialize)]
240268
#[serde(rename_all = "camelCase")]
241269
pub(super) struct LastApprovedQuery {
242-
pub with_heartbeat: Option<String>
270+
pub with_heartbeat: Option<String>,
243271
}
244-
272+
245273
fn default_page() -> u64 {
246274
0
247275
}

0 commit comments

Comments
 (0)