Skip to content

Commit 72f5be4

Browse files
authored
Merge pull request #229 from AdExNetwork/issue-9-get-event-aggregates
Issue #9 GET Channel Events aggregates
2 parents 943559a + dd3508d commit 72f5be4

File tree

19 files changed

+212
-48
lines changed

19 files changed

+212
-48
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[workspace]
22

33
members = [
4-
"adapter",
54
"primitives",
5+
"adapter",
6+
"adview-manager",
67
"validator_worker",
78
"sentry",
8-
"adview-manager",
99
]
1010

1111
[patch.crates-io]
12-
redis = {version = "0.13.1-alpha.0", git = "https://github.com/Marwes/redis-rs", branch = "async_await_api"}
12+
redis = {version = "0.13.1-alpha.0", git = "https://github.com/mitsuhiko/redis-rs"}

adapter/src/ethereum.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,8 @@ mod test {
564564
)
565565
.expect("prep_db: failed to deserialize channel id"),
566566
// leader_account
567-
creator: "0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39".to_string(),
567+
creator: ValidatorId::try_from("Df08F82De32B8d460adbE8D72043E3a7e25A3B39")
568+
.expect("should be valid ValidatorId"),
568569
deposit_asset: eth_checksum::checksum(&format!("{:?}", token_contract.address())),
569570
deposit_amount: 2_000.into(),
570571
valid_until: Utc::now() + Duration::days(2),

adapter/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ impl TryFrom<&Channel> for EthereumChannel {
9494
.map(|v| &v.id)
9595
.collect::<Vec<_>>();
9696

97-
let creator = <[u8; 20]>::from_hex(&channel.creator[2..])
98-
.map_err(|_| ChannelError::InvalidArgument("failed to parse creator".into()))?;
97+
let creator = channel.creator.inner();
9998
let deposit_asset = <[u8; 20]>::from_hex(&channel.deposit_asset[2..])
10099
.map_err(|_| ChannelError::InvalidArgument("failed to parse deposit asset".into()))?;
101100

primitives/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ num-derive = "0.2"
3535
fake = { version = "^1.3", features = ["chrono"] }
3636
rand = "^0.6"
3737
# postgres feature
38-
postgres-types = { version = "0.1.0-alpha.2", optional = true }
38+
postgres-types = { version = "0.1.0", optional = true }
3939
bytes = { version = "0.5", optional = true }
4040
tokio-postgres = { version = "0.5.1", optional = true, features = ["with-chrono-0_4", "with-serde_json-1"] }
4141
# Futures

primitives/src/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl FromHex for ChannelId {
4949
#[serde(rename_all = "camelCase")]
5050
pub struct Channel {
5151
pub id: ChannelId,
52-
pub creator: String,
52+
pub creator: ValidatorId,
5353
pub deposit_asset: String,
5454
pub deposit_amount: BigNum,
5555
#[serde(with = "ts_seconds")]

primitives/src/channel_validator.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::channel::{Channel, ChannelError, SpecValidator, SpecValidators};
22
use crate::config::Config;
33
use crate::ValidatorId;
44
use chrono::Utc;
5+
use std::cmp::PartialEq;
56

67
pub trait ChannelValidator {
78
fn is_channel_valid(
@@ -60,10 +61,10 @@ pub fn all_validators_listed(validators: &SpecValidators, whitelist: &[Validator
6061
}
6162
}
6263

63-
pub fn creator_listed(channel: &Channel, whitelist: &[String]) -> bool {
64+
pub fn creator_listed(channel: &Channel, whitelist: &[ValidatorId]) -> bool {
6465
// if the list is empty, return true, as we don't have a whitelist to restrict us to
6566
// or if we have a list, check if it includes the `channel.creator`
66-
whitelist.is_empty() || whitelist.iter().any(|allowed| allowed == &channel.creator)
67+
whitelist.is_empty() || whitelist.iter().any(|allowed| allowed.eq(&channel.creator))
6768
}
6869

6970
pub fn asset_listed(channel: &Channel, whitelist: &[String]) -> bool {

primitives/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct Config {
3333
pub validator_tick_timeout: u32,
3434
pub ip_rate_limit: RateLimit, // HashMap??
3535
pub sid_rate_limit: RateLimit, // HashMap ??
36-
pub creators_whitelist: Vec<String>,
36+
pub creators_whitelist: Vec<ValidatorId>,
3737
pub minimal_deposit: BigNum,
3838
pub minimal_fee: BigNum,
3939
pub token_address_whitelist: Vec<String>,

primitives/src/sentry.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ pub struct Earner {
6262
pub promilles: u64,
6363
}
6464

65+
pub type EarnerAddress = ValidatorId;
66+
6567
#[derive(Debug, Serialize, Deserialize)]
6668
#[serde(rename_all = "camelCase")]
6769
pub struct EventAggregate {
@@ -112,18 +114,30 @@ pub struct ValidatorMessageResponse {
112114

113115
#[derive(Serialize, Deserialize, Debug)]
114116
pub struct EventAggregateResponse {
117+
pub channel: Channel,
115118
pub events: Vec<EventAggregate>,
116119
}
117120

118121
#[cfg(feature = "postgres")]
119122
mod postgres {
120123
use super::ValidatorMessage;
124+
use crate::sentry::EventAggregate;
121125
use crate::validator::MessageTypes;
122126
use bytes::BytesMut;
123127
use postgres_types::{accepts, to_sql_checked, IsNull, Json, ToSql, Type};
124128
use std::error::Error;
125129
use tokio_postgres::Row;
126130

131+
impl From<&Row> for EventAggregate {
132+
fn from(row: &Row) -> Self {
133+
Self {
134+
channel_id: row.get("channel_id"),
135+
created: row.get("created"),
136+
events: row.get::<_, Json<_>>("events").0,
137+
}
138+
}
139+
}
140+
127141
impl From<&Row> for ValidatorMessage {
128142
fn from(row: &Row) -> Self {
129143
Self {

primitives/src/util/tests/prep_db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ lazy_static! {
5858

5959
Channel {
6060
id: ChannelId::from_hex("061d5e2a67d0a9a10f1c732bca12a676d83f79663a396f7d87b3e30b9b411088").expect("prep_db: failed to deserialize channel id"),
61-
creator: "0x033ed90e0fec3f3ea1c9b005c724d704501e0196".to_string(),
61+
creator: ValidatorId::try_from("033ed90e0fec3f3ea1c9b005c724d704501e0196").expect("Should be valid ValidatorId"),
6262
deposit_asset: "0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359".to_string(),
6363
deposit_amount: 1_000.into(),
6464
// UNIX timestamp for 2100-01-01

0 commit comments

Comments
 (0)