Skip to content

Commit 1c8d3be

Browse files
authored
Merge pull request #2 from AdExNetwork/route-discrepancies-fixes
Tweaks and cleanup
2 parents eecfb1a + e7f9d80 commit 1c8d3be

File tree

3 files changed

+19
-33
lines changed

3 files changed

+19
-33
lines changed

primitives/src/validator.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,13 @@ impl AsRef<[u8]> for ValidatorId {
8181
impl TryFrom<&str> for ValidatorId {
8282
type Error = DomainError;
8383
fn try_from(value: &str) -> Result<Self, Self::Error> {
84-
let hex_value = if value.len() == 42 {
85-
&value[2..]
86-
} else {
87-
value
88-
};
89-
90-
if hex_value.len() != 40 {
91-
return Err(DomainError::InvalidArgument(
84+
let hex_value = match value {
85+
value if value.len() == 42 => Ok(&value[2..]),
86+
value if value.len() == 40 => Ok(value),
87+
_ => Err(DomainError::InvalidArgument(
9288
"invalid validator id length".to_string(),
93-
));
94-
}
89+
)),
90+
}?;
9591

9692
let result = hex::decode(hex_value).map_err(|_| {
9793
DomainError::InvalidArgument("Failed to deserialize validator id".to_string())

sentry/src/access.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ mod test {
256256
async fn session_uid_rate_limit() {
257257
let (config, redis) = setup().await;
258258

259-
let session = &Session {
259+
let session = Session {
260260
era: 0,
261261
uid: IDS["follower"].clone(),
262262
ip: Default::default(),
@@ -276,7 +276,7 @@ mod test {
276276

277277
let response = check_access(
278278
&redis,
279-
Some(session),
279+
Some(&session),
280280
&config.ip_rate_limit,
281281
&channel,
282282
&events,
@@ -286,7 +286,7 @@ mod test {
286286

287287
let err_response = check_access(
288288
&redis,
289-
Some(session),
289+
Some(&session),
290290
&config.ip_rate_limit,
291291
&channel,
292292
&events,

sentry/src/routes/channel.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,9 @@ pub async fn create_channel<A: Adapter>(
5858
Err(error) => {
5959
error!(&app.logger, "{}", &error; "module" => "create_channel");
6060
match error {
61-
RunError::User(e) => {
62-
if e.code() == Some(&error::SqlState::UNIQUE_VIOLATION) {
63-
Err(ResponseError::Conflict(
64-
"channel already exists".to_string(),
65-
))
66-
} else {
67-
Err(error_response)
68-
}
69-
}
61+
RunError::User(e) if e.code() == Some(&error::SqlState::UNIQUE_VIOLATION) => Err(
62+
ResponseError::Conflict("channel already exists".to_string()),
63+
),
7064
_ => Err(error_response),
7165
}
7266
}
@@ -189,29 +183,25 @@ pub async fn insert_events<A: Adapter + 'static>(
189183
req: Request<Body>,
190184
app: &Application<A>,
191185
) -> Result<Response<Body>, ResponseError> {
192-
let session = req
193-
.extensions()
194-
.get::<Session>()
195-
.map(ToOwned::to_owned)
196-
.to_owned();
186+
let (req_head, req_body) = req.into_parts();
187+
let session = req_head.extensions.get::<Session>();
197188

198-
let route_params = req
199-
.extensions()
189+
let route_params = req_head
190+
.extensions
200191
.get::<RouteParams>()
201192
.expect("request should have route params");
202193

203194
let channel_id = ChannelId::from_hex(route_params.index(0))?;
204195

205-
let into_body = req.into_body();
206-
let body = hyper::body::to_bytes(into_body).await?;
207-
let request_body = serde_json::from_slice::<HashMap<String, Vec<Event>>>(&body)?;
196+
let body_bytes = hyper::body::to_bytes(req_body).await?;
197+
let request_body = serde_json::from_slice::<HashMap<String, Vec<Event>>>(&body_bytes)?;
208198

209199
let events = request_body
210200
.get("events")
211201
.ok_or_else(|| ResponseError::BadRequest("invalid request".to_string()))?;
212202

213203
app.event_aggregator
214-
.record(app, &channel_id, session.as_ref(), &events)
204+
.record(app, &channel_id, session, &events)
215205
.await?;
216206

217207
Ok(Response::builder()

0 commit comments

Comments
 (0)