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 Campaigns containing a specified creator if provided.

validator: Option<ValidatorParam>

Returns only the Campaigns containing a specified validator if provided.

Trait Implementations

Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more