Struct primitives::sentry::campaign_list::CampaignListQuery
source · pub struct CampaignListQuery {
pub page: u64,
pub active_to_ge: DateTime<Utc>,
pub creator: Option<Address>,
pub validator: Option<ValidatorParam>,
}
Expand description
GET /v5/campaign/list
query
Examples
use chrono::{TimeZone, Utc};
use primitives::{
sentry::campaign_list::{CampaignListQuery, ValidatorParam},
test_util::{ADVERTISER, FOLLOWER, IDS, LEADER},
};
fn main() {
// Empty query - default values only
{
let empty_query = "";
let query: CampaignListQuery = serde_qs::from_str(empty_query).unwrap();
assert_eq!(0, query.page);
assert!(
Utc::now() >= query.active_to_ge,
"By default `activeTo` is set to `Utc::now()`"
);
assert!(query.creator.is_none());
assert!(query.validator.is_none());
}
// In the following examples we always use `activeTo`
// as it makes simpler examples for assertions rather than using the default `Utc::now()`
// Query with `activeTo` only
{
let active_to_query = "activeTo=1624192200";
let active_to = CampaignListQuery {
page: 0,
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
creator: None,
validator: None,
};
assert_eq!(active_to, serde_qs::from_str(active_to_query).unwrap());
}
// Query with `page` & `activeTo`
{
let with_page_query = "page=14&activeTo=1624192200";
let with_page = CampaignListQuery {
page: 14,
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
creator: None,
validator: None,
};
assert_eq!(with_page, serde_qs::from_str(with_page_query).unwrap());
}
// Query with `creator`
{
let with_creator_query =
"activeTo=1624192200&creator=0xDd589B43793934EF6Ad266067A0d1D4896b0dff0";
let with_creator = CampaignListQuery {
page: 0,
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
creator: Some(*ADVERTISER),
validator: None,
};
assert_eq!(
with_creator,
serde_qs::from_str(with_creator_query).unwrap()
);
}
// Query with `validator`
// You can either have `leader` or `validator` but not both!
{
let with_creator_validator_query =
"activeTo=1624192200&validator=0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7";
let with_creator_validator = CampaignListQuery {
page: 0,
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
creator: None,
validator: Some(ValidatorParam::Validator(IDS[&FOLLOWER])),
};
assert_eq!(
with_creator_validator,
serde_qs::from_str(with_creator_validator_query).unwrap()
);
}
// Query with `leader`
// You can either have `leader` or `validator` but not both!
{
let with_leader_query =
"activeTo=1624192200&leader=0x80690751969B234697e9059e04ed72195c3507fa";
let with_leader = CampaignListQuery {
page: 0,
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
creator: None,
validator: Some(ValidatorParam::Leader(IDS[&LEADER])),
};
assert_eq!(with_leader, serde_qs::from_str(with_leader_query).unwrap());
}
// Query with all parameters and `validator`
// You can either have `leader` or `validator` but not both!
{
let full_query = "page=14&activeTo=1624192200&creator=0xDd589B43793934EF6Ad266067A0d1D4896b0dff0&validator=0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7";
let full_expected = CampaignListQuery {
page: 14,
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
creator: Some(*ADVERTISER),
validator: Some(ValidatorParam::Validator(IDS[&FOLLOWER])),
};
assert_eq!(full_expected, serde_qs::from_str(full_query).unwrap());
}
}
Fields
page: u64
Default is u64::default()
= 0
.
active_to_ge: DateTime<Utc>
Filters the list on Campaign.active.to >= active_to_ge
.
It should be the same timestamp format as the Campaign.active.to
: seconds
Note: This field is deserialized from activeTo
.
creator: Option<Address>
Returns only the Campaign
s containing a specified creator if provided.
validator: Option<ValidatorParam>
Returns only the Campaign
s containing a specified validator if provided.
Trait Implementations
sourceimpl Debug for CampaignListQuery
impl Debug for CampaignListQuery
sourceimpl<'de> Deserialize<'de> for CampaignListQuery
impl<'de> Deserialize<'de> for CampaignListQuery
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl PartialEq<CampaignListQuery> for CampaignListQuery
impl PartialEq<CampaignListQuery> for CampaignListQuery
sourcefn eq(&self, other: &CampaignListQuery) -> bool
fn eq(&self, other: &CampaignListQuery) -> bool
sourceimpl Serialize for CampaignListQuery
impl Serialize for CampaignListQuery
impl Eq for CampaignListQuery
impl StructuralEq for CampaignListQuery
impl StructuralPartialEq for CampaignListQuery
Auto Trait Implementations
impl RefUnwindSafe for CampaignListQuery
impl Send for CampaignListQuery
impl Sync for CampaignListQuery
impl Unpin for CampaignListQuery
impl UnwindSafe for CampaignListQuery
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more