Skip to content

Commit 3fe919f

Browse files
authored
Merge pull request #194 from samparsky/refactor-sentry-process
Refactor route, fix POST /channel
2 parents b672127 + d006ed2 commit 3fe919f

File tree

11 files changed

+305
-184
lines changed

11 files changed

+305
-184
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adapter/src/ethereum.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,7 @@ mod test {
380380
#[test]
381381
fn should_init_and_unlock_ethereum_adapter() {
382382
let mut eth_adapter = setup_eth_adapter();
383-
let unlock = eth_adapter.unlock().expect("should unlock eth adapter");
384-
385-
assert_eq!((), unlock, "failed to unlock eth adapter");
383+
eth_adapter.unlock().expect("should unlock eth adapter");
386384
}
387385

388386
#[test]

primitives/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Lachezar Lechev <[email protected]>, Omidiora Samuel <[email protected]
55
edition = "2018"
66

77
[features]
8-
postgres = ["postgres-types", "bytes"]
8+
postgres = ["postgres-types", "bytes", "tokio-postgres"]
99

1010
[dependencies]
1111
# Futures
@@ -39,5 +39,7 @@ rand = { version = "^0.6" }
3939
# postgres feature
4040
postgres-types = {version = "0.1.0-alpha.1", optional = true}
4141
bytes = { version = "0.4.12", optional = true}
42+
tokio-postgres = {version = "0.5.0-alpha.1", optional = true, features = ["with-chrono-0_4", "with-serde_json-1"]}
43+
4244
# Other
4345
lazy_static = "1.4.0"

primitives/src/channel.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,12 @@ impl Error for ChannelError {
197197
#[cfg(feature = "postgres")]
198198
pub mod postgres {
199199
use super::ChannelId;
200+
use super::{Channel, ChannelSpec};
200201
use bytes::BytesMut;
201202
use hex::FromHex;
202203
use postgres_types::{FromSql, IsNull, ToSql, Type};
203204
use std::error::Error;
205+
use tokio_postgres::{types::Json, Row};
204206

205207
impl<'a> FromSql<'a> for ChannelId {
206208
fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
@@ -217,6 +219,19 @@ pub mod postgres {
217219
}
218220
}
219221

222+
impl From<&Row> for Channel {
223+
fn from(row: &Row) -> Self {
224+
Self {
225+
id: row.get("channel_id"),
226+
creator: row.get("creator"),
227+
deposit_asset: row.get("deposit_asset"),
228+
deposit_amount: row.get("deposit_amount"),
229+
valid_until: row.get("valid_until"),
230+
spec: row.get::<_, Json<ChannelSpec>>("spec").0,
231+
}
232+
}
233+
}
234+
220235
impl ToSql for ChannelId {
221236
fn to_sql(
222237
&self,

sentry/src/chain.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use crate::ResponseError;
2+
use hyper::{Body, Request};
3+
use std::future::Future;
4+
5+
// chain middleware function calls
6+
//
7+
// function signature
8+
// fn middleware(mut req: Request) -> Result<Request, ResponseError>
9+
10+
pub async fn chain<M, MF>(
11+
req: Request<Body>,
12+
middlewares: Vec<M>,
13+
) -> Result<Request<Body>, ResponseError>
14+
where
15+
MF: Future<Output = Result<Request<Body>, ResponseError>> + Send,
16+
M: FnMut(Request<Body>) -> MF,
17+
{
18+
let mut req = Ok(req);
19+
20+
for mut mw in middlewares.into_iter() {
21+
match mw(req.unwrap()).await {
22+
Ok(r) => {
23+
req = Ok(r);
24+
}
25+
Err(e) => {
26+
req = Err(e);
27+
break;
28+
}
29+
}
30+
}
31+
32+
req
33+
}

sentry/src/event_reducer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ mod test {
6565
let channel = channel;
6666

6767
let mut event_aggr = EventAggregate {
68-
channel_id: channel.id.clone(),
68+
channel_id: channel.id,
6969
created: Utc::now(),
7070
events: Default::default(),
7171
};

0 commit comments

Comments
 (0)