Skip to content

Commit 51e1e7e

Browse files
authored
Merge pull request #512 from AmbireTech/channel-list-filter-by-chain
Channel list filter by chain
2 parents d2f89cc + 6ec970a commit 51e1e7e

File tree

10 files changed

+374
-93
lines changed

10 files changed

+374
-93
lines changed

primitives/src/sentry.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,10 @@ impl<'de> Deserialize<'de> for DateHour<Utc> {
550550
#[derive(Debug, Serialize, Deserialize, PartialEq)]
551551
#[serde(rename_all = "camelCase")]
552552
pub struct Pagination {
553+
/// The total amount of pages available for this request
553554
pub total_pages: u64,
555+
/// The current page number returned from this request
556+
/// First page starts from `0`
554557
pub page: u64,
555558
}
556559

@@ -637,7 +640,7 @@ pub struct ValidationErrorResponse {
637640
}
638641

639642
pub mod channel_list {
640-
use crate::{Channel, ValidatorId};
643+
use crate::{ChainId, Channel, ValidatorId};
641644
use serde::{Deserialize, Serialize};
642645

643646
use super::Pagination;
@@ -652,11 +655,14 @@ pub mod channel_list {
652655

653656
#[derive(Debug, Serialize, Deserialize)]
654657
pub struct ChannelListQuery {
658+
/// default is `u64::default()` = `0`
655659
#[serde(default)]
656-
// default is `u64::default()` = `0`
657660
pub page: u64,
658-
/// filters the channels containing a specific validator if provided
661+
/// Returns only the [`Channel`]s containing a specified validator if provided.
659662
pub validator: Option<ValidatorId>,
663+
/// Returns only the Channels from the specified [`ChainId`]s.
664+
#[serde(default)]
665+
pub chains: Vec<ChainId>,
660666
}
661667
}
662668

@@ -677,15 +683,15 @@ pub mod campaign_list {
677683

678684
#[derive(Debug, Serialize, Deserialize, PartialEq)]
679685
pub struct CampaignListQuery {
686+
/// default is `u64::default()` = `0`
680687
#[serde(default)]
681-
// default is `u64::default()` = `0`
682688
pub page: u64,
683689
/// filters the list on `active.to >= active_to_ge`
684690
/// It should be the same timestamp format as the `Campaign.active.to`: **seconds**
685691
#[serde(with = "ts_seconds", default = "Utc::now", rename = "activeTo")]
686692
pub active_to_ge: DateTime<Utc>,
687693
pub creator: Option<Address>,
688-
/// filters the campaigns containing a specific validator if provided
694+
/// Returns only the [`Campaign`]s containing a specified validator if provided.
689695
#[serde(flatten)]
690696
pub validator: Option<ValidatorParam>,
691697
}

sentry/migrations/20190806011140_initial-tables/up.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CREATE TABLE channels (
66
token varchar(42) NOT NULL,
77
-- Using varchar for U256 for simplicity
88
nonce varchar(78) NOT NULL,
9+
chain_id integer NOT NULL,
910
-- In order to be able to order the channels for the `GET channel` request
1011
created timestamp(2) with time zone NOT NULL,
1112
-- Do not rename the Primary key constraint (`channels_pkey`)!

sentry/src/db/accounting.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ pub async fn spend_amount(
185185

186186
#[cfg(test)]
187187
mod test {
188-
use primitives::test_util::{
189-
ADVERTISER, ADVERTISER_2, CREATOR, DUMMY_CAMPAIGN, PUBLISHER, PUBLISHER_2,
188+
use primitives::{
189+
config::GANACHE_CONFIG,
190+
test_util::{ADVERTISER, ADVERTISER_2, CREATOR, DUMMY_CAMPAIGN, PUBLISHER, PUBLISHER_2},
190191
};
191192

192193
use crate::db::{
@@ -203,8 +204,14 @@ mod test {
203204
setup_test_migrations(database.pool.clone())
204205
.await
205206
.expect("Migrations should succeed");
207+
208+
let channel_chain = GANACHE_CONFIG
209+
.find_chain_of(DUMMY_CAMPAIGN.channel.token)
210+
.expect("Channel token should be whitelisted in config!");
211+
let channel_context = channel_chain.with_channel(DUMMY_CAMPAIGN.channel);
212+
206213
// insert the channel into the DB
207-
let channel = insert_channel(&database.pool, DUMMY_CAMPAIGN.channel)
214+
let channel = insert_channel(&database.pool, &channel_context)
208215
.await
209216
.expect("Should insert");
210217

@@ -399,8 +406,13 @@ mod test {
399406
.await
400407
.expect("Migrations should succeed");
401408

409+
let channel_chain = GANACHE_CONFIG
410+
.find_chain_of(DUMMY_CAMPAIGN.channel.token)
411+
.expect("Channel token should be whitelisted in config!");
412+
let channel_context = channel_chain.with_channel(DUMMY_CAMPAIGN.channel);
413+
402414
// insert the channel into the DB
403-
let channel = insert_channel(&database.pool, DUMMY_CAMPAIGN.channel)
415+
let channel = insert_channel(&database.pool, &channel_context)
404416
.await
405417
.expect("Should insert");
406418

@@ -486,8 +498,13 @@ mod test {
486498
.await
487499
.expect("Migrations should succeed");
488500

501+
let channel_chain = GANACHE_CONFIG
502+
.find_chain_of(DUMMY_CAMPAIGN.channel.token)
503+
.expect("Channel token should be whitelisted in config!");
504+
let channel_context = channel_chain.with_channel(DUMMY_CAMPAIGN.channel);
505+
489506
// insert the channel into the DB
490-
let channel = insert_channel(&database.pool, DUMMY_CAMPAIGN.channel)
507+
let channel = insert_channel(&database.pool, &channel_context)
491508
.await
492509
.expect("Should insert");
493510

sentry/src/db/campaign.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ mod test {
579579
use primitives::{
580580
campaign,
581581
campaign::Validators,
582+
config::GANACHE_CONFIG,
582583
event_submission::{RateLimit, Rule},
583584
sentry::{campaign_modify::ModifyCampaign, CLICK, IMPRESSION},
584585
targeting::Rules,
@@ -603,8 +604,13 @@ mod test {
603604

604605
let campaign = DUMMY_CAMPAIGN.clone();
605606

607+
let channel_chain = GANACHE_CONFIG
608+
.find_chain_of(DUMMY_CAMPAIGN.channel.token)
609+
.expect("Channel token should be whitelisted in config!");
610+
let channel_context = channel_chain.with_channel(DUMMY_CAMPAIGN.channel);
611+
606612
// insert the channel into the DB
607-
let _channel = insert_channel(&database.pool, DUMMY_CAMPAIGN.channel)
613+
let _channel = insert_channel(&database.pool, &channel_context)
608614
.await
609615
.expect("Should insert");
610616

@@ -699,10 +705,17 @@ mod test {
699705
let mut channel_with_different_leader = DUMMY_CAMPAIGN.channel;
700706
channel_with_different_leader.leader = IDS[&ADVERTISER_2];
701707

702-
insert_channel(&database, DUMMY_CAMPAIGN.channel)
708+
let channel_chain = GANACHE_CONFIG
709+
.find_chain_of(DUMMY_CAMPAIGN.channel.token)
710+
.expect("Channel token should be whitelisted in config!");
711+
let channel_context = channel_chain.clone().with_channel(DUMMY_CAMPAIGN.channel);
712+
let channel_context_different_leader =
713+
channel_chain.with_channel(channel_with_different_leader);
714+
715+
insert_channel(&database, &channel_context)
703716
.await
704717
.expect("Should insert");
705-
insert_channel(&database, channel_with_different_leader)
718+
insert_channel(&database, &channel_context_different_leader)
706719
.await
707720
.expect("Should insert");
708721

0 commit comments

Comments
 (0)