Skip to content

Commit dbed5cb

Browse files
authored
Merge pull request #132 from samparsky/sentry_implementation
Sentry implementation
2 parents 6e7d2b7 + 9489ac8 commit dbed5cb

File tree

21 files changed

+422
-341
lines changed

21 files changed

+422
-341
lines changed

adapter/src/dummy.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
#![deny(rust_2018_idioms)]
33

44
use futures::future::{ok, FutureExt};
5-
use primitives::adapter::{Adapter, AdapterFuture, AdapterOptions};
5+
use primitives::adapter::{Adapter, AdapterOptions, AdapterResult};
66
use primitives::channel_validator::ChannelValidator;
77
use primitives::config::Config;
8-
use primitives::Channel;
8+
use primitives::{Channel, ValidatorDesc};
99
use std::collections::HashMap;
1010

11+
#[derive(Debug, Clone)]
1112
pub struct DummyAdapter {
1213
identity: String,
1314
auth_tokens: HashMap<String, String>,
@@ -35,45 +36,45 @@ impl Adapter for DummyAdapter {
3536
}
3637
}
3738

38-
fn unlock(&self) -> AdapterFuture<bool> {
39-
ok(true).boxed()
39+
fn unlock(&self) -> AdapterResult<bool> {
40+
Ok(true)
4041
}
4142

4243
fn whoami(&self) -> String {
4344
self.identity.to_string()
4445
}
4546

46-
fn sign(&self, state_root: String) -> AdapterFuture<String> {
47+
fn sign(&self, state_root: String) -> AdapterResult<String> {
4748
let signature = format!(
4849
"Dummy adapter signature for {} by {}",
4950
state_root,
5051
self.whoami()
5152
);
52-
ok(signature).boxed()
53+
Ok(signature)
5354
}
5455

55-
fn verify(&self, signer: &str, _state_root: &str, signature: &str) -> AdapterFuture<bool> {
56+
fn verify(&self, signer: &str, _state_root: &str, signature: &str) -> AdapterResult<bool> {
5657
// select the `identity` and compare it to the signer
5758
// for empty string this will return array with 1 element - an empty string `[""]`
5859
let is_same = match signature.rsplit(' ').take(1).next() {
5960
Some(from) => from == signer,
6061
None => false,
6162
};
6263

63-
ok(is_same).boxed()
64+
Ok(is_same)
6465
}
6566

66-
fn validate_channel(&self, _channel: &Channel) -> AdapterFuture<bool> {
67+
fn validate_channel(&self, _channel: &Channel) -> AdapterResult<bool> {
6768
// @TODO
68-
ok(true).boxed()
69+
Ok(true)
6970
}
7071

71-
fn session_from_token(&self, _token: &str) -> AdapterFuture<String> {
72+
fn session_from_token(&self, _token: &str) -> AdapterResult<String> {
7273
// @TODO
73-
ok("hello".to_string()).boxed()
74+
Ok("hello".to_string())
7475
}
7576

76-
fn get_auth(&self, _validator: &str) -> AdapterFuture<String> {
77+
fn get_auth(&self, _validator: &ValidatorDesc) -> AdapterResult<String> {
7778
// let participant = self
7879
// .participants
7980
// .iter()
@@ -84,6 +85,6 @@ impl Adapter for DummyAdapter {
8485
// "Identity not found".to_string(),
8586
// )),
8687
// };
87-
ok("auth".to_string()).boxed()
88+
Ok("auth".to_string())
8889
}
8990
}

adapter/src/ethereum.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#![deny(clippy::all)]
22
#![deny(rust_2018_idioms)]
33

4-
use std::collections::HashMap;
5-
64
use futures::future::{ok, FutureExt};
7-
use primitives::adapter::{Adapter, AdapterFuture, AdapterOptions};
5+
use primitives::adapter::{Adapter, AdapterOptions, AdapterResult};
86
use primitives::channel_validator::ChannelValidator;
97
use primitives::config::Config;
10-
use primitives::Channel;
8+
use primitives::{Channel, ValidatorDesc};
9+
use std::collections::HashMap;
1110
use web3::types::Address;
1211

12+
#[derive(Debug, Clone)]
1313
pub struct EthereumAdapter {
1414
address: Option<Address>,
1515
keystore_json: String,
@@ -47,45 +47,45 @@ impl Adapter for EthereumAdapter {
4747
}
4848
}
4949

50-
fn unlock(&self) -> AdapterFuture<bool> {
51-
ok(true).boxed()
50+
fn unlock(&self) -> AdapterResult<bool> {
51+
Ok(true)
5252
}
5353

5454
fn whoami(&self) -> String {
5555
self.address.unwrap().to_string()
5656
}
5757

58-
fn sign(&self, state_root: String) -> AdapterFuture<String> {
58+
fn sign(&self, state_root: String) -> AdapterResult<String> {
5959
let signature = format!(
6060
"Dummy adapter signature for {} by {}",
6161
state_root,
6262
self.whoami()
6363
);
64-
ok(signature).boxed()
64+
Ok(signature)
6565
}
6666

67-
fn verify(&self, signer: &str, _state_root: &str, signature: &str) -> AdapterFuture<bool> {
67+
fn verify(&self, signer: &str, _state_root: &str, signature: &str) -> AdapterResult<bool> {
6868
// select the `identity` and compare it to the signer
6969
// for empty string this will return array with 1 element - an empty string `[""]`
7070
let is_same = match signature.rsplit(' ').take(1).next() {
7171
Some(from) => from == signer,
7272
None => false,
7373
};
7474

75-
ok(is_same).boxed()
75+
Ok(is_same)
7676
}
7777

78-
fn validate_channel(&self, _channel: &Channel) -> AdapterFuture<bool> {
78+
fn validate_channel(&self, _channel: &Channel) -> AdapterResult<bool> {
7979
// @TODO
80-
ok(true).boxed()
80+
Ok(true)
8181
}
8282

83-
fn session_from_token(&self, _token: &str) -> AdapterFuture<String> {
83+
fn session_from_token(&self, _token: &str) -> AdapterResult<String> {
8484
// @TODO
85-
ok("hello".to_string()).boxed()
85+
Ok("hello".to_string())
8686
}
8787

88-
fn get_auth(&self, _validator: &str) -> AdapterFuture<String> {
88+
fn get_auth(&self, _validator: &ValidatorDesc) -> AdapterResult<String> {
8989
// let participant = self
9090
// .participants
9191
// .iter()
@@ -96,6 +96,6 @@ impl Adapter for EthereumAdapter {
9696
// "Identity not found".to_string(),
9797
// )),
9898
// };
99-
ok("auth".to_string()).boxed()
99+
Ok("auth".to_string())
100100
}
101101
}

docs/config/dev.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
max_channels = 512
1+
max_channels=512
22
channels_find_limit = 200
33
wait_time = 500
44

@@ -14,8 +14,14 @@ list_timeout = 5000
1414
fetch_timeout = 5000
1515
validator_tick_timeout = 5000
1616

17-
ip_rate_limit = { type = "ip", timeframe = 20000 }
18-
SID_RATE_LIMIT = { type = 'sid', timeframe = 20000 }
17+
ip_rate_limit = {type='ip', timeframe=20000}
18+
sid_rate_limit = {type='sid', timeframe=20000}
1919

2020
ethereum_core_address = '0x333420fc6a897356e69b62417cd17ff012177d2b'
21-
ethereum_network = 'goerli'
21+
ethereum_network = 'goerli'
22+
23+
creators_whitelist = []
24+
minimal_deposit = "0"
25+
minimal_fee = "0"
26+
token_address_whitelist = []
27+
validators_whitelist = []

docs/config/prod.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ fetch_timeout = 10000
1717
validator_tick_timeout = 10000
1818

1919
ip_rate_limit = { type = "ip", timeframe = 20000 }
20-
20+
sid_rate_limit = { type = "sid", timeframe = 0 }
2121
ethereum_core_address = '0x333420fc6a897356e69b62417cd17ff012177d2b'
2222
ethereum_network = 'homestead'
2323
token_address_whitelist = ['0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359']
2424

2525
creators_whitelist = []
26-
minimal_deposit = 0
27-
minimal_fee = 0
28-
validators_whitelist = []
26+
minimal_deposit = "0"
27+
minimal_fee = "0"
28+
validators_whitelist = []

primitives/src/adapter.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ use futures::prelude::*;
22
use std::collections::HashMap;
33
use std::pin::Pin;
44
// use domain::validator::message::State;
5+
use crate::channel_validator::ChannelValidator;
6+
use crate::validator::ValidatorDesc;
57
use crate::{Channel, Config};
6-
//
78
//use crate::sanity::SanityChecker;
89
use std::error::Error;
910
use std::fmt;
11+
use std::fmt::Debug;
1012

11-
pub type AdapterFuture<T> = Pin<Box<dyn Future<Output = Result<T, AdapterError>> + Send>>;
13+
pub type AdapterResult<T> = Result<T, AdapterError>;
1214

1315
#[derive(Debug, Eq, PartialEq)]
1416
pub enum AdapterError {
@@ -34,30 +36,30 @@ pub struct AdapterOptions {
3436
pub keystore_pwd: Option<String>,
3537
}
3638

37-
pub trait Adapter {
39+
pub trait Adapter: ChannelValidator + Clone + Debug + Send + Sync {
3840
type Output;
3941

4042
/// Initialize adapter
4143
fn init(opts: AdapterOptions, config: &Config) -> Self::Output;
4244

4345
/// Unlock adapter
44-
fn unlock(&self) -> AdapterFuture<bool>;
46+
fn unlock(&self) -> AdapterResult<bool>;
4547

4648
/// Get Adapter whoami
4749
fn whoami(&self) -> String;
4850

4951
/// Signs the provided state_root
50-
fn sign(&self, state_root: String) -> AdapterFuture<String>;
52+
fn sign(&self, state_root: String) -> AdapterResult<String>;
5153

5254
/// Verify, based on the signature & state_root, that the signer is the same
53-
fn verify(&self, signer: &str, state_root: &str, signature: &str) -> AdapterFuture<bool>;
55+
fn verify(&self, signer: &str, state_root: &str, signature: &str) -> AdapterResult<bool>;
5456

5557
/// Validate a channel
56-
fn validate_channel(&self, channel: &Channel) -> AdapterFuture<bool>;
58+
fn validate_channel(&self, channel: &Channel) -> AdapterResult<bool>;
5759

5860
/// Get user session from token
59-
fn session_from_token(&self, token: &str) -> AdapterFuture<String>;
61+
fn session_from_token(&self, token: &str) -> AdapterResult<String>;
6062

6163
/// Gets authentication for specific validator
62-
fn get_auth(&self, validator: &str) -> AdapterFuture<String>;
64+
fn get_auth(&self, validator: &ValidatorDesc) -> AdapterResult<String>;
6365
}

primitives/src/channel.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ pub struct ChannelSpec {
3838
#[serde(default, skip_serializing_if = "Option::is_none")]
3939
pub min_targeting_score: Option<f64>,
4040
/// EventSubmission object, applies to event submission (POST /channel/:id/events)
41-
pub event_submission: EventSubmission,
41+
pub event_submission: Option<EventSubmission>,
4242
/// A millisecond timestamp of when the campaign was created
43-
#[serde(with = "ts_milliseconds")]
44-
pub created: DateTime<Utc>,
43+
#[serde(
44+
default,
45+
skip_serializing_if = "Option::is_none",
46+
with = "ts_milliseconds_option"
47+
)]
48+
pub created: Option<DateTime<Utc>>,
4549
/// A millisecond timestamp representing the time you want this campaign to become active (optional)
4650
/// Used by the AdViewManager
4751
#[serde(
@@ -51,7 +55,7 @@ pub struct ChannelSpec {
5155
)]
5256
pub active_from: Option<DateTime<Utc>>,
5357
/// A random number to ensure the campaignSpec hash is unique
54-
pub nonce: BigNum,
58+
pub nonce: Option<BigNum>,
5559
/// A millisecond timestamp of when the campaign should enter a withdraw period
5660
/// (no longer accept any events other than CHANNEL_CLOSE)
5761
/// A sane value should be lower than channel.validUntil * 1000 and higher than created

primitives/src/channel_validator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use chrono::Utc;
44

55
pub trait ChannelValidator {
66
fn is_channel_valid(config: &Config, channel: &Channel) -> Result<(), ChannelError> {
7-
let adapter_channel_validator = match channel.spec.validators.find(&config.identity) {
7+
let identity = &config.clone().identity.unwrap_or_else(|| "".to_string());
8+
let adapter_channel_validator = match channel.spec.validators.find(identity) {
89
// check if the channel validators include our adapter identity
910
SpecValidator::None => return Err(ChannelError::AdapterNotIncluded),
1011
SpecValidator::Leader(validator) | SpecValidator::Follower(validator) => validator,

0 commit comments

Comments
 (0)