pub struct CreateCampaign {
    pub id: Option<CampaignId>,
    pub channel: Channel,
    pub creator: Address,
    pub budget: UnifiedNum,
    pub validators: Validators,
    pub title: Option<String>,
    pub pricing_bounds: PricingBounds,
    pub event_submission: Option<EventSubmission>,
    pub ad_units: Vec<AdUnit>,
    pub targeting_rules: Rules,
    pub created: DateTime<Utc>,
    pub active: Active,
}
Expand description

All fields are present except the CampaignId which is randomly created This struct defines the Body of the request (in JSON)

Examples

use primitives::{sentry::campaign_create::CreateCampaign, test_util::DUMMY_CAMPAIGN, CampaignId};
use serde_json::json;
use std::str::FromStr;

fn main() {
    // CreateCampaign in an HTTP request.
    // A CampaignId will be randomly generated for the newly created Campaign.
    {
        let create_campaign = CreateCampaign::from_campaign_erased(DUMMY_CAMPAIGN.clone(), None);

        let _create_campaign_str =
            serde_json::to_string(&create_campaign).expect("should serialize");

        let create_campaign_json = json!({
            "channel":{
                "leader":"0x80690751969B234697e9059e04ed72195c3507fa",
                "follower":"0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
                "guardian":"0xe061E1EB461EaBE512759aa18A201B20Fe90631D",
                "token":"0x2BCaf6968aEC8A3b5126FBfAb5Fd419da6E8AD8E",
                "nonce":"987654321"
            },
            "creator":"0xaCBaDA2d5830d1875ae3D2de207A1363B316Df2F",
            "budget":"100000000000",
            "validators":[
                {
                    "id":"0x80690751969B234697e9059e04ed72195c3507fa",
                    "fee":"3000",
                    "url":"http://localhost:8005"
                },
                {
                    "id":"0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
                    "fee":"2000",
                    "url":"http://localhost:8006"
                }
            ],
            "title":"Dummy Campaign",
            "pricingBounds":{
                "CLICK":{"min":"0","max":"0"},
                "IMPRESSION":{"min":"1","max":"10"}
            },
            "eventSubmission":{"allow":[]},
            "targetingRules":[],
            "created":1612162800000_u64,
            "activeTo":4073414400000_u64
        });

        let create_campaign_json =
            serde_json::to_string(&create_campaign_json).expect("should serialize");

        let deserialized: CreateCampaign =
            serde_json::from_str(&create_campaign_json).expect("should deserialize");

        assert_eq!(create_campaign, deserialized);
    }

    // CreateCampaign with a provided ID
    {
        let mut create_campaign =
            CreateCampaign::from_campaign_erased(DUMMY_CAMPAIGN.clone(), None);
        create_campaign.id = Some(
            CampaignId::from_str("0x936da01f9abd4d9d80c702af85c822a8").expect("Should be valid id"),
        );

        let create_campaign_json = json!({
            "id":"0x936da01f9abd4d9d80c702af85c822a8",
            "channel":{
                "leader":"0x80690751969B234697e9059e04ed72195c3507fa",
                "follower":"0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
                "guardian":"0xe061E1EB461EaBE512759aa18A201B20Fe90631D",
                "token":"0x2BCaf6968aEC8A3b5126FBfAb5Fd419da6E8AD8E",
                "nonce":"987654321"
            },
            "creator":"0xaCBaDA2d5830d1875ae3D2de207A1363B316Df2F",
            "budget":"100000000000",
            "validators":[
                {
                    "id":"0x80690751969B234697e9059e04ed72195c3507fa",
                    "fee":"3000",
                    "url":"http://localhost:8005"
                },
                {
                    "id":"0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7",
                    "fee":"2000",
                    "url":"http://localhost:8006"
                }
            ],
            "title":"Dummy Campaign",
            "pricingBounds":{"CLICK":{"min":"0","max":"0"},"IMPRESSION":{"min":"1","max":"10"}},
            "eventSubmission":{"allow":[]},
            "targetingRules":[],
            "created":1612162800000_u64,
            "activeTo":4073414400000_u64
        });

        let create_campaign_json =
            serde_json::to_string(&create_campaign_json).expect("should serialize");
        let deserialized: CreateCampaign =
            serde_json::from_str(&create_campaign_json).expect("should deserialize");

        assert_eq!(create_campaign, deserialized);
    }
}

Fields

id: Option<CampaignId>channel: Channelcreator: Addressbudget: UnifiedNumvalidators: Validatorstitle: Option<String>pricing_bounds: PricingBounds

Event pricing bounds

event_submission: Option<EventSubmission>

EventSubmission object, applies to event submission (POST /channel/:id/events)

ad_units: Vec<AdUnit>

An array of AdUnit (optional)

targeting_rules: Rulescreated: DateTime<Utc>

A millisecond timestamp of when the campaign was created

active: Active

A millisecond timestamp representing the time you want this campaign to become active (optional) Used by the AdViewManager & Targeting AIP#31

Implementations

Creates a new Campaign If CampaignId was not provided with the request it will be generated using CampaignId::new()

Creates a CreateCampaign without using the [Campaign.id]. You can either pass None to randomly generate a new CampaignId. Or you can pass a CampaignId to be used for the CreateCampaign.

This function will retains the original [Campaign.id] (CampaignId).

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
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