Skip to content

Commit 9dad371

Browse files
committed
2 parents a5778dc + 2fb3645 commit 9dad371

File tree

26 files changed

+1598
-1306
lines changed

26 files changed

+1598
-1306
lines changed

Cargo.lock

Lines changed: 824 additions & 919 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ futures = { version = "0.3.1", features = ["compat"] }
3232

3333
[dev-dependencies]
3434
byteorder = "1.3"
35-
tokio = { version = "0.2", features = ["macros", "rt-core"] }
35+
tokio = { version = "0.2", features = ["macros", "rt-threaded"] }

adapter/src/dummy.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use futures::future::{BoxFuture, FutureExt};
2-
use primitives::adapter::{Adapter, AdapterError, AdapterResult, DummyAdapterOptions, Session};
2+
use primitives::adapter::{
3+
Adapter, AdapterErrorKind, AdapterResult, DummyAdapterOptions, Error as AdapterError, Session,
4+
};
35
use primitives::channel_validator::ChannelValidator;
46
use primitives::config::Config;
57
use primitives::{Channel, ToETHChecksum, ValidatorId};
68
use std::collections::HashMap;
9+
use std::fmt;
710

811
#[derive(Debug, Clone)]
912
pub struct DummyAdapter {
@@ -30,16 +33,28 @@ impl DummyAdapter {
3033
}
3134
}
3235

36+
#[derive(Debug)]
37+
pub struct Error {}
38+
impl fmt::Display for Error {
39+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40+
write!(f, "Dummy Adapter error occurred!")
41+
}
42+
}
43+
44+
impl AdapterErrorKind for Error {}
45+
3346
impl Adapter for DummyAdapter {
34-
fn unlock(&mut self) -> AdapterResult<()> {
47+
type AdapterError = Error;
48+
49+
fn unlock(&mut self) -> AdapterResult<(), Self::AdapterError> {
3550
Ok(())
3651
}
3752

3853
fn whoami(&self) -> &ValidatorId {
3954
&self.identity
4055
}
4156

42-
fn sign(&self, state_root: &str) -> AdapterResult<String> {
57+
fn sign(&self, state_root: &str) -> AdapterResult<String, Self::AdapterError> {
4358
let signature = format!(
4459
"Dummy adapter signature for {} by {}",
4560
state_root,
@@ -53,7 +68,7 @@ impl Adapter for DummyAdapter {
5368
signer: &ValidatorId,
5469
_state_root: &str,
5570
signature: &str,
56-
) -> AdapterResult<bool> {
71+
) -> AdapterResult<bool, Self::AdapterError> {
5772
// select the `identity` and compare it to the signer
5873
// for empty string this will return array with 1 element - an empty string `[""]`
5974
let is_same = match signature.rsplit(' ').take(1).next() {
@@ -64,17 +79,22 @@ impl Adapter for DummyAdapter {
6479
Ok(is_same)
6580
}
6681

67-
fn validate_channel<'a>(&'a self, channel: &'a Channel) -> BoxFuture<'a, AdapterResult<bool>> {
82+
fn validate_channel<'a>(
83+
&'a self,
84+
channel: &'a Channel,
85+
) -> BoxFuture<'a, AdapterResult<bool, Self::AdapterError>> {
6886
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-
}
87+
DummyAdapter::is_channel_valid(&self.config, self.whoami(), channel)
88+
.map(|_| true)
89+
.map_err(AdapterError::InvalidChannel)
7390
}
7491
.boxed()
7592
}
7693

77-
fn session_from_token<'a>(&'a self, token: &'a str) -> BoxFuture<'a, AdapterResult<Session>> {
94+
fn session_from_token<'a>(
95+
&'a self,
96+
token: &'a str,
97+
) -> BoxFuture<'a, AdapterResult<Session, Self::AdapterError>> {
7898
async move {
7999
let identity = self
80100
.authorization_tokens
@@ -95,7 +115,7 @@ impl Adapter for DummyAdapter {
95115
.boxed()
96116
}
97117

98-
fn get_auth(&self, _validator: &ValidatorId) -> AdapterResult<String> {
118+
fn get_auth(&self, _validator: &ValidatorId) -> AdapterResult<String, Self::AdapterError> {
99119
let who = self
100120
.session_tokens
101121
.iter()

0 commit comments

Comments
 (0)