Skip to content

Commit 3484bf1

Browse files
committed
Channel.targeting_rules & ChanneSpec.targeting_rules
1 parent b8dd680 commit 3484bf1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

primitives/src/channel.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
use std::error::Error;
22
use std::fmt;
3+
use std::ops::Deref;
34

45
use chrono::serde::{ts_milliseconds, ts_milliseconds_option, ts_seconds};
56
use chrono::{DateTime, Utc};
67
use serde::{Deserialize, Deserializer, Serialize};
78
use serde_hex::{SerHex, StrictPfx};
89

9-
use crate::big_num::BigNum;
10-
use crate::{AdUnit, EventSubmission, TargetingTag, ValidatorDesc, ValidatorId};
10+
use crate::{
11+
targeting::Rule, AdUnit, BigNum, EventSubmission, TargetingTag, ValidatorDesc, ValidatorId,
12+
};
1113
use hex::{FromHex, FromHexError};
12-
use std::ops::Deref;
1314

1415
#[derive(Serialize, Deserialize, PartialEq, Eq, Copy, Clone, Hash)]
1516
#[serde(transparent)]
@@ -84,6 +85,8 @@ pub struct Channel {
8485
pub deposit_amount: BigNum,
8586
#[serde(with = "ts_seconds")]
8687
pub valid_until: DateTime<Utc>,
88+
#[serde(default)]
89+
pub targeting_rules: Vec<Rule>,
8790
pub spec: ChannelSpec,
8891
}
8992

@@ -171,6 +174,8 @@ pub struct ChannelSpec {
171174
/// An array of AdUnit (optional)
172175
#[serde(default, skip_serializing_if = "Vec::is_empty")]
173176
pub ad_units: Vec<AdUnit>,
177+
#[serde(default)]
178+
pub targeting_rules: Vec<Rule>,
174179
#[serde(default, skip_serializing_if = "Vec::is_empty")]
175180
pub price_multiplication_rules: Vec<PriceMultiplicationRules>,
176181
#[serde(default)]
@@ -339,6 +344,7 @@ impl Error for ChannelError {
339344
pub mod postgres {
340345
use super::ChannelId;
341346
use super::{Channel, ChannelSpec};
347+
use crate::targeting::Rule;
342348
use bytes::BytesMut;
343349
use hex::FromHex;
344350
use postgres_types::{accepts, to_sql_checked, FromSql, IsNull, Json, ToSql, Type};
@@ -354,6 +360,7 @@ pub mod postgres {
354360
deposit_amount: row.get("deposit_amount"),
355361
valid_until: row.get("valid_until"),
356362
spec: row.get::<_, Json<ChannelSpec>>("spec").0,
363+
targeting_rules: row.get::<_, Json<Vec<Rule>>>("targeting_rules").0,
357364
}
358365
}
359366
}

primitives/src/util/tests/prep_db.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ lazy_static! {
6464
creator: ValidatorId::try_from("033ed90e0fec3f3ea1c9b005c724d704501e0196").expect("Should be valid ValidatorId"),
6565
deposit_asset: "0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359".to_string(),
6666
deposit_amount: 1_000.into(),
67+
targeting_rules: vec![],
6768
// UNIX timestamp for 2100-01-01
6869
valid_until: Utc.timestamp(4_102_444_800, 0),
6970
spec: ChannelSpec {
7071
title: None,
7172
validators: SpecValidators::new(DUMMY_VALIDATOR_LEADER.clone(), DUMMY_VALIDATOR_FOLLOWER.clone()),
7273
max_per_impression: 10.into(),
7374
min_per_impression: 1.into(),
75+
targeting_rules: vec![],
7476
targeting: vec![],
7577
min_targeting_score: None,
7678
event_submission: Some(EventSubmission { allow: vec![] }),

0 commit comments

Comments
 (0)