Skip to content

Commit 65d6c32

Browse files
authored
Merge pull request #161 from samparsky/158-fix-validator-worker
Issue #158 fix validator worker
2 parents 87877fb + 821b28a commit 65d6c32

File tree

22 files changed

+415
-266
lines changed

22 files changed

+415
-266
lines changed

Cargo.lock

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

adapter/src/dummy.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use primitives::adapter::{Adapter, AdapterError, AdapterResult, DummyAdapterOptions, Session};
22
use primitives::channel_validator::ChannelValidator;
33
use primitives::config::Config;
4-
use primitives::Channel;
4+
use primitives::{Channel, ValidatorId};
55
use std::collections::HashMap;
66

77
#[derive(Debug, Clone)]
88
pub struct DummyAdapter {
9-
identity: String,
9+
identity: ValidatorId,
1010
config: Config,
1111
// Auth tokens that we have verified (tokenId => session)
12-
session_tokens: HashMap<String, String>,
12+
session_tokens: HashMap<String, ValidatorId>,
1313
// Auth tokens that we've generated to authenticate with someone (address => token)
1414
authorization_tokens: HashMap<String, String>,
1515
}
@@ -23,8 +23,8 @@ impl DummyAdapter {
2323
Self {
2424
identity: opts.dummy_identity,
2525
config: config.to_owned(),
26-
session_tokens: opts.dummy_auth_tokens,
27-
authorization_tokens: opts.dummy_auth,
26+
session_tokens: opts.dummy_auth,
27+
authorization_tokens: opts.dummy_auth_tokens,
2828
}
2929
}
3030
}
@@ -34,8 +34,8 @@ impl Adapter for DummyAdapter {
3434
Ok(())
3535
}
3636

37-
fn whoami(&self) -> String {
38-
self.identity.clone()
37+
fn whoami(&self) -> &ValidatorId {
38+
&self.identity
3939
}
4040

4141
fn sign(&self, state_root: &str) -> AdapterResult<String> {
@@ -47,11 +47,16 @@ impl Adapter for DummyAdapter {
4747
Ok(signature)
4848
}
4949

50-
fn verify(&self, signer: &str, _state_root: &str, signature: &str) -> AdapterResult<bool> {
50+
fn verify(
51+
&self,
52+
signer: &ValidatorId,
53+
_state_root: &str,
54+
signature: &str,
55+
) -> AdapterResult<bool> {
5156
// select the `identity` and compare it to the signer
5257
// for empty string this will return array with 1 element - an empty string `[""]`
5358
let is_same = match signature.rsplit(' ').take(1).next() {
54-
Some(from) => from == signer,
59+
Some(from) => from == signer.to_string(),
5560
None => false,
5661
};
5762

@@ -73,7 +78,7 @@ impl Adapter for DummyAdapter {
7378

7479
match identity {
7580
Some((id, _)) => Ok(Session {
76-
uid: id.to_owned(),
81+
uid: self.session_tokens[id].clone(),
7782
era: 0,
7883
}),
7984
None => Err(AdapterError::Authentication(format!(
@@ -83,12 +88,11 @@ impl Adapter for DummyAdapter {
8388
}
8489
}
8590

86-
fn get_auth(&mut self, _validator: &str) -> AdapterResult<String> {
91+
fn get_auth(&mut self, _validator: &ValidatorId) -> AdapterResult<String> {
8792
let who = self
8893
.session_tokens
8994
.iter()
9095
.find(|(_, id)| *id == &self.identity);
91-
9296
match who {
9397
Some((id, _)) => {
9498
let auth = self.authorization_tokens.get(id).expect("id should exist");

0 commit comments

Comments
 (0)