|
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, |
4 | 10 | };
|
5 |
| -use primitives::channel_validator::ChannelValidator; |
6 |
| -use primitives::config::Config; |
7 |
| -use primitives::{Channel, ToETHChecksum, ValidatorId}; |
8 | 11 | use std::collections::HashMap;
|
9 | 12 | use std::fmt;
|
10 | 13 |
|
@@ -43,6 +46,7 @@ impl fmt::Display for Error {
|
43 | 46 |
|
44 | 47 | impl AdapterErrorKind for Error {}
|
45 | 48 |
|
| 49 | +#[async_trait] |
46 | 50 | impl Adapter for DummyAdapter {
|
47 | 51 | type AdapterError = Error;
|
48 | 52 |
|
@@ -79,40 +83,34 @@ impl Adapter for DummyAdapter {
|
79 | 83 | Ok(is_same)
|
80 | 84 | }
|
81 | 85 |
|
82 |
| - fn validate_channel<'a>( |
| 86 | + async fn validate_channel<'a>( |
83 | 87 | &'a self,
|
84 | 88 | 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) |
92 | 93 | }
|
93 | 94 |
|
94 |
| - fn session_from_token<'a>( |
| 95 | + async fn session_from_token<'a>( |
95 | 96 | &'a self,
|
96 | 97 | 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); |
103 | 103 |
|
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 | + ))), |
114 | 113 | }
|
115 |
| - .boxed() |
116 | 114 | }
|
117 | 115 |
|
118 | 116 | fn get_auth(&self, _validator: &ValidatorId) -> AdapterResult<String, Self::AdapterError> {
|
|
0 commit comments