Skip to content

Commit 978a71b

Browse files
authored
Merge pull request #355 from AdExNetwork/bugfixes
Bugfixes
2 parents 4015d81 + 787afd5 commit 978a71b

File tree

11 files changed

+569
-97
lines changed

11 files changed

+569
-97
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ We need two services to be able to run `Sentry`: `Postgres` and `Redis`.
3939

4040
### Running Redis
4141

42-
`docker run --rm --name adex-validator-redis -d redis`
42+
`docker run --rm -p 6379:6379 --name adex-validator-redis -d redis`
4343

4444
### Running Sentry Rest API
4545

adapter/src/ethereum.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,9 @@ mod test {
429429
use crate::EthereumChannel;
430430
use chrono::{Duration, Utc};
431431
use hex::FromHex;
432-
use primitives::adapter::KeystoreOptions;
433432
use primitives::config::configuration;
434433
use primitives::ChannelId;
434+
use primitives::{adapter::KeystoreOptions, targeting::Rules};
435435
use primitives::{ChannelSpec, EventSubmission, SpecValidators, ValidatorDesc};
436436
use std::convert::TryFrom;
437437
use web3::types::Address;
@@ -651,13 +651,13 @@ mod test {
651651
deposit_asset: eth_checksum::checksum(&format!("{:?}", token_contract.address())),
652652
deposit_amount: 2_000.into(),
653653
valid_until: Utc::now() + Duration::days(2),
654-
targeting_rules: vec![],
654+
targeting_rules: Rules::new(),
655655
spec: ChannelSpec {
656656
title: None,
657657
validators: SpecValidators::new(leader_validator_desc, follower_validator_desc),
658658
max_per_impression: 10.into(),
659659
min_per_impression: 10.into(),
660-
targeting_rules: vec![],
660+
targeting_rules: Rules::new(),
661661
event_submission: Some(EventSubmission { allow: vec![] }),
662662
created: Utc::now(),
663663
active_from: None,

primitives/src/ad_slot.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
use crate::{targeting::Rule, BigNum, ValidatorId};
2-
use chrono::{DateTime, Utc};
2+
use chrono::{
3+
serde::{ts_milliseconds, ts_milliseconds_option},
4+
DateTime, Utc,
5+
};
36
use serde::{Deserialize, Serialize};
47
use std::collections::HashMap;
58

69
/// See [AdEx Protocol adSlot.md][protocol] & [adex-models AdSlot.js][adex-models] for more details.
710
/// [protocol]: https://github.com/AdExNetwork/adex-protocol/blob/master/adSlot.md
811
/// [adex-models]: https://github.com/AdExNetwork/adex-models/blob/master/src/models/AdSlot.js
9-
#[derive(Serialize, Deserialize, Debug, Clone)]
12+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
1013
#[serde(rename_all = "camelCase")]
1114
pub struct AdSlot {
1215
/// valid ipfs hash of spec props below
@@ -32,6 +35,7 @@ pub struct AdSlot {
3235
/// User address from the session
3336
pub owner: ValidatorId,
3437
/// UTC timestamp in milliseconds, used as nonce for escaping duplicated spec ipfs hashes
38+
#[serde(with = "ts_milliseconds")]
3539
pub created: DateTime<Utc>,
3640
/// the name of the unit used in platform UI
3741
#[serde(default)]
@@ -45,5 +49,6 @@ pub struct AdSlot {
4549
#[serde(default)]
4650
pub archived: bool,
4751
/// UTC timestamp in milliseconds, changed every time modifiable property is changed
52+
#[serde(with = "ts_milliseconds_option")]
4853
pub modified: Option<DateTime<Utc>>,
4954
}

primitives/src/ad_unit.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use chrono::{DateTime, Utc};
1+
use chrono::{
2+
serde::{ts_milliseconds, ts_milliseconds_option},
3+
DateTime, Utc,
4+
};
25
use serde::{Deserialize, Serialize};
36

47
use crate::{ValidatorId, IPFS};
@@ -25,18 +28,27 @@ pub struct AdUnit {
2528
/// Advertised URL
2629
pub target_url: String,
2730
/// Number; minimum targeting score (optional)
31+
#[serde(default, skip_serializing_if = "Option::is_none")]
2832
pub min_targeting_score: Option<f64>,
2933
/// user address from the session
3034
pub owner: ValidatorId,
3135
/// number, UTC timestamp in milliseconds, used as nonce for escaping duplicated spec ipfs hashes
36+
#[serde(with = "ts_milliseconds")]
3237
pub created: DateTime<Utc>,
3338
/// the name of the unit used in platform UI
39+
#[serde(default, skip_serializing_if = "Option::is_none")]
3440
pub title: Option<String>,
3541
/// arbitrary text used in platform UI
42+
#[serde(default, skip_serializing_if = "Option::is_none")]
3643
pub description: Option<String>,
3744
/// user can change it - used for filtering in platform UI
3845
#[serde(default)]
3946
pub archived: bool,
4047
/// UTC timestamp in milliseconds, changed every time modifiable property is changed
48+
#[serde(
49+
default,
50+
with = "ts_milliseconds_option",
51+
skip_serializing_if = "Option::is_none"
52+
)]
4153
pub modified: Option<DateTime<Utc>>,
4254
}

primitives/src/channel.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use chrono::{DateTime, Utc};
88
use serde::{Deserialize, Deserializer, Serialize};
99
use serde_hex::{SerHex, StrictPfx};
1010

11-
use crate::{targeting::Rule, AdUnit, BigNum, EventSubmission, ValidatorDesc, ValidatorId};
11+
use crate::{targeting::Rules, AdUnit, BigNum, EventSubmission, ValidatorDesc, ValidatorId};
1212
use hex::{FromHex, FromHexError};
1313

1414
#[derive(Serialize, Deserialize, PartialEq, Eq, Copy, Clone, Hash)]
@@ -96,7 +96,7 @@ pub struct Channel {
9696
#[serde(with = "ts_seconds")]
9797
pub valid_until: DateTime<Utc>,
9898
#[serde(default)]
99-
pub targeting_rules: Vec<Rule>,
99+
pub targeting_rules: Rules,
100100
pub spec: ChannelSpec,
101101
}
102102

@@ -181,7 +181,7 @@ pub struct ChannelSpec {
181181
#[serde(default, skip_serializing_if = "Vec::is_empty")]
182182
pub ad_units: Vec<AdUnit>,
183183
#[serde(default)]
184-
pub targeting_rules: Vec<Rule>,
184+
pub targeting_rules: Rules,
185185
}
186186

187187
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
@@ -370,7 +370,7 @@ mod test {
370370
pub mod postgres {
371371
use super::ChannelId;
372372
use super::{Channel, ChannelSpec};
373-
use crate::targeting::Rule;
373+
use crate::targeting::Rules;
374374
use bytes::BytesMut;
375375
use hex::FromHex;
376376
use postgres_types::{accepts, to_sql_checked, FromSql, IsNull, Json, ToSql, Type};
@@ -385,7 +385,7 @@ pub mod postgres {
385385
deposit_asset: row.get("deposit_asset"),
386386
deposit_amount: row.get("deposit_amount"),
387387
valid_until: row.get("valid_until"),
388-
targeting_rules: row.get::<_, Json<Vec<Rule>>>("targeting_rules").0,
388+
targeting_rules: row.get::<_, Json<Rules>>("targeting_rules").0,
389389
spec: row.get::<_, Json<ChannelSpec>>("spec").0,
390390
}
391391
}

0 commit comments

Comments
 (0)