Skip to content

Commit 2a14247

Browse files
authored
Merge pull request #333 from AdExNetwork/adapter-async-trait
Adapter async-trait
2 parents 28e8c14 + 0a6d260 commit 2a14247

File tree

8 files changed

+184
-164
lines changed

8 files changed

+184
-164
lines changed

Cargo.lock

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

adapter/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ base64 = "0.10.1"
2929
lazy_static = "1.4.0"
3030
# Futures
3131
futures = { version = "0.3.1", features = ["compat"] }
32+
async-trait = "0.1.40"
3233

3334
[dev-dependencies]
3435
byteorder = "1.3"

adapter/src/dummy.rs

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
use futures::future::{BoxFuture, FutureExt};
2-
use primitives::adapter::{
3-
Adapter, AdapterErrorKind, AdapterResult, DummyAdapterOptions, Error as AdapterError, Session,
1+
use async_trait::async_trait;
2+
use primitives::{
3+
adapter::{
4+
Adapter, AdapterErrorKind, AdapterResult, DummyAdapterOptions, Error as AdapterError,
5+
Session,
6+
},
7+
channel_validator::ChannelValidator,
8+
config::Config,
9+
Channel, ToETHChecksum, ValidatorId,
410
};
5-
use primitives::channel_validator::ChannelValidator;
6-
use primitives::config::Config;
7-
use primitives::{Channel, ToETHChecksum, ValidatorId};
811
use std::collections::HashMap;
912
use std::fmt;
1013

@@ -43,6 +46,7 @@ impl fmt::Display for Error {
4346

4447
impl AdapterErrorKind for Error {}
4548

49+
#[async_trait]
4650
impl Adapter for DummyAdapter {
4751
type AdapterError = Error;
4852

@@ -79,40 +83,34 @@ impl Adapter for DummyAdapter {
7983
Ok(is_same)
8084
}
8185

82-
fn validate_channel<'a>(
86+
async fn validate_channel<'a>(
8387
&'a self,
8488
channel: &'a Channel,
85-
) -> BoxFuture<'a, AdapterResult<bool, Self::AdapterError>> {
86-
async move {
87-
DummyAdapter::is_channel_valid(&self.config, self.whoami(), channel)
88-
.map(|_| true)
89-
.map_err(AdapterError::InvalidChannel)
90-
}
91-
.boxed()
89+
) -> AdapterResult<bool, Self::AdapterError> {
90+
DummyAdapter::is_channel_valid(&self.config, self.whoami(), channel)
91+
.map(|_| true)
92+
.map_err(AdapterError::InvalidChannel)
9293
}
9394

94-
fn session_from_token<'a>(
95+
async fn session_from_token<'a>(
9596
&'a self,
9697
token: &'a str,
97-
) -> BoxFuture<'a, AdapterResult<Session, Self::AdapterError>> {
98-
async move {
99-
let identity = self
100-
.authorization_tokens
101-
.iter()
102-
.find(|(_, id)| *id == token);
98+
) -> AdapterResult<Session, Self::AdapterError> {
99+
let identity = self
100+
.authorization_tokens
101+
.iter()
102+
.find(|(_, id)| *id == token);
103103

104-
match identity {
105-
Some((id, _)) => Ok(Session {
106-
uid: self.session_tokens[id],
107-
era: 0,
108-
}),
109-
None => Err(AdapterError::Authentication(format!(
110-
"no session token for this auth: {}",
111-
token
112-
))),
113-
}
104+
match identity {
105+
Some((id, _)) => Ok(Session {
106+
uid: self.session_tokens[id],
107+
era: 0,
108+
}),
109+
None => Err(AdapterError::Authentication(format!(
110+
"no session token for this auth: {}",
111+
token
112+
))),
114113
}
115-
.boxed()
116114
}
117115

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

0 commit comments

Comments
 (0)