Skip to content

Commit 896e49d

Browse files
committed
fix: ethereum adapter calls to async
1 parent 99176c2 commit 896e49d

File tree

8 files changed

+180
-138
lines changed

8 files changed

+180
-138
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ 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_legacy = { version = "0.3.1", package = "futures" }
29+
futures-preview = { version = "=0.3.0-alpha.19", features = ["compat"]}
2730

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

adapter/src/dummy.rs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use primitives::channel_validator::ChannelValidator;
33
use primitives::config::Config;
44
use primitives::{Channel, ValidatorId};
55
use std::collections::HashMap;
6+
use futures::future::BoxFuture;
67

78
#[derive(Debug, Clone)]
89
pub struct DummyAdapter {
@@ -63,29 +64,38 @@ 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(
69+
async move {
70+
match DummyAdapter::is_channel_valid(&self.config, self.whoami(), channel) {
71+
Ok(_) => Ok(true),
72+
Err(e) => Err(AdapterError::InvalidChannel(e.to_string())),
73+
}
74+
}
75+
)
76+
7177
}
7278

73-
fn session_from_token(&self, token: &str) -> AdapterResult<Session> {
74-
let identity = self
75-
.authorization_tokens
76-
.iter()
77-
.find(|(_, id)| *id == token);
78-
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-
}
79+
fn session_from_token<'a>(&'a self, token: &'a str) -> BoxFuture<'a, AdapterResult<Session>> {
80+
Box::pin(
81+
async move {
82+
let identity = self
83+
.authorization_tokens
84+
.iter()
85+
.find(|(_, id)| *id == token);
86+
87+
match identity {
88+
Some((id, _)) => Ok(Session {
89+
uid: self.session_tokens[id].clone(),
90+
era: 0,
91+
}),
92+
None => Err(AdapterError::Authentication(format!(
93+
"no session token for this auth: {}",
94+
token
95+
))),
96+
}
97+
}
98+
)
8999
}
90100

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

0 commit comments

Comments
 (0)