Skip to content

Commit 53a1e52

Browse files
authored
Merge pull request #227 from samparsky/adex-audit
Make contract calls async
2 parents 2da2dcb + 07b307f commit 53a1e52

File tree

8 files changed

+174
-141
lines changed

8 files changed

+174
-141
lines changed

Cargo.lock

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

adapter/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ ethkey = { version = "0.4.0", git = "https://github.com/paritytech/parity-ethere
2424
sha2 = "0.8.0"
2525
base64 = "0.10.1"
2626
lazy_static = "1.4.0"
27+
# Futures
28+
futures = { version = "0.3.1", features = ["compat"] }
2729

2830
[dev-dependencies]
29-
byteorder = "1.3"
31+
byteorder = "1.3"
32+
tokio = { version = "0.2", features = ["macros", "rt-core"] }

adapter/src/dummy.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use futures::future::BoxFuture;
12
use primitives::adapter::{Adapter, AdapterError, AdapterResult, DummyAdapterOptions, Session};
23
use primitives::channel_validator::ChannelValidator;
34
use primitives::config::Config;
@@ -63,29 +64,33 @@ impl Adapter for DummyAdapter {
6364
Ok(is_same)
6465
}
6566

66-
fn validate_channel(&self, channel: &Channel) -> AdapterResult<bool> {
67-
match DummyAdapter::is_channel_valid(&self.config, self.whoami(), channel) {
68-
Ok(_) => Ok(true),
69-
Err(e) => Err(AdapterError::InvalidChannel(e.to_string())),
70-
}
67+
fn validate_channel<'a>(&'a self, channel: &'a Channel) -> BoxFuture<'a, AdapterResult<bool>> {
68+
Box::pin(async move {
69+
match DummyAdapter::is_channel_valid(&self.config, self.whoami(), channel) {
70+
Ok(_) => Ok(true),
71+
Err(e) => Err(AdapterError::InvalidChannel(e.to_string())),
72+
}
73+
})
7174
}
7275

73-
fn session_from_token(&self, token: &str) -> AdapterResult<Session> {
74-
let identity = self
75-
.authorization_tokens
76-
.iter()
77-
.find(|(_, id)| *id == token);
76+
fn session_from_token<'a>(&'a self, token: &'a str) -> BoxFuture<'a, AdapterResult<Session>> {
77+
Box::pin(async move {
78+
let identity = self
79+
.authorization_tokens
80+
.iter()
81+
.find(|(_, id)| *id == token);
7882

79-
match identity {
80-
Some((id, _)) => Ok(Session {
81-
uid: self.session_tokens[id].clone(),
82-
era: 0,
83-
}),
84-
None => Err(AdapterError::Authentication(format!(
85-
"no session token for this auth: {}",
86-
token
87-
))),
88-
}
83+
match identity {
84+
Some((id, _)) => Ok(Session {
85+
uid: self.session_tokens[id].clone(),
86+
era: 0,
87+
}),
88+
None => Err(AdapterError::Authentication(format!(
89+
"no session token for this auth: {}",
90+
token
91+
))),
92+
}
93+
})
8994
}
9095

9196
fn get_auth(&self, _validator: &ValidatorId) -> AdapterResult<String> {

0 commit comments

Comments
 (0)