Skip to content

Issue #381 Spender aggregates - structs and setup #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 56 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
6a9ca1a
primitives - remove unused `ValidatorError`
elpiel Mar 12, 2021
aaabc5a
primitives - Channel v5 & Campaing + move structs
elpiel Mar 12, 2021
a4b2ebb
primitives - ToHex & address::Address
elpiel Mar 12, 2021
e5ed959
primitives - Address - improvements
elpiel Mar 15, 2021
fc5f7e9
primitives - channel v5 - use Address
elpiel Mar 15, 2021
4a803ab
primitives - campaign - spec Validators and matching
elpiel Mar 15, 2021
fa4f084
rustfmt
elpiel Mar 15, 2021
defa9ab
primitives - campaign - merge spec and change fields
elpiel Mar 16, 2021
9ae51cc
primitives - Cargo - update deps and remove duplicates
elpiel Mar 16, 2021
98790b5
primitives - channel_v5 - `Nonce` & Channel `fn id()`
elpiel Mar 16, 2021
7ea437b
primitives - ValidatorId to_address & as_bytes
elpiel Mar 16, 2021
564ba9c
primtivies campaign::Active - fix `to` name
elpiel Mar 16, 2021
9c76970
Merge pull request #383 from AdExNetwork/issue-382-channel-and-campaign
elpiel Mar 18, 2021
3f8ec05
primitives - UnifiedNum
elpiel Mar 17, 2021
be47342
pirmitives - BigNum - impl num::pow::Pow
elpiel Mar 18, 2021
080b517
primitives - UnifiedNum - impl num::pow::Pow & to_preicison()
elpiel Mar 18, 2021
9815a24
primitives - UnifiedNum - test for Zero & One
elpiel Mar 18, 2021
055307c
primitives - BigNum - impl Display instead of ToString
elpiel Mar 18, 2021
0804b77
primitives - ValidatorMessage with a Generic
elpiel Mar 18, 2021
a086b9c
primitives - impl FromStr for ValidatorId
elpiel Mar 19, 2021
6f149b2
primitives - sentry - MessageResponse test
elpiel Mar 19, 2021
eb006a3
primivies - ValidatorId change errors to address::Error
elpiel Mar 19, 2021
310ea23
primitives - UnifiedNum - use u64 as internal value
elpiel Mar 22, 2021
a38e0f2
primitives - UnifiedNum - Update doc
elpiel Mar 23, 2021
5903527
primitives - UnifiedNum - fix test comment
elpiel Mar 23, 2021
7621a77
Merge pull request #386 from AdExNetwork/issue-384-unified-precision
elpiel Mar 23, 2021
f345f6a
Merge pull request #387 from AdExNetwork/validator-messages-improvements
elpiel Mar 23, 2021
b6ec00c
add todos for #381
elpiel Mar 23, 2021
b5c4e73
todo to change BalancesMap's ValidatorId to Address
elpiel Mar 23, 2021
c152159
primitives - UnifiedNum - (De)Serialize & docs clarification
elpiel Mar 23, 2021
a853860
primitives - UnifiedNum - fix (de)serialization
elpiel Mar 24, 2021
16d2369
primitives - Cargo - add `uuid` for CampaignId
elpiel Mar 24, 2021
f605639
primitives - Address - impl more traits and helper methods
elpiel Mar 25, 2021
33af087
primitives - campaign - CampaignId
elpiel Mar 25, 2021
231c52f
primitives - test - prep_db - Campaign & Addresses
elpiel Mar 25, 2021
b9b2ba0
primitives - channel_v5 - Channel - derive Eq
elpiel Mar 25, 2021
27ffbbf
Prepare for AIP#61 changes with TODOs and all-around changes
elpiel Mar 25, 2021
bdb3e5a
primitives - remove unexisting `spender` module
elpiel Mar 25, 2021
a752604
validator_worker - remove unnecessary `.clone()`s
elpiel Mar 29, 2021
02a84a4
Merge branch 'aip-61-all-around-generic-changes' into issue-381-spend…
elpiel Apr 5, 2021
42bd6ec
primitives - Campaign::find_validator
elpiel Apr 5, 2021
5ae2cd5
primitives - UnifiedNum - add const fn from_u64
elpiel Apr 5, 2021
53ddd4a
primitives & sentry - init spender modules
elpiel Apr 5, 2021
75e63e8
fix errors & rustfmt
elpiel Apr 6, 2021
3b4062d
Merge branch 'aip-61-adex-v5' into issue-381-spender-aggregates
elpiel Apr 9, 2021
55616d4
Issue #381 & #382 - sentry migrations:
elpiel Apr 9, 2021
77cc1e3
Merge branch 'issue-384-unified-precision' into issue-381-spender-agg…
elpiel Apr 9, 2021
da56536
sentry - Cargo - add deps for postgres tests
elpiel Apr 14, 2021
8764182
sentry - migrations - initial-tables - fix types & typos
elpiel Apr 14, 2021
99de2f5
sentry - db - postgres_pool - Test pool with migration setup fn
elpiel Apr 14, 2021
b3578ea
sentry - Makefile - setup postgres DB for running tests
elpiel Apr 14, 2021
9c39059
sentry - db - spendable - insert & fetch Spendable
elpiel Apr 14, 2021
359bb84
Merge branch 'aip-61-adex-v5' into issue-381-spender-aggregates
elpiel Apr 14, 2021
2afcf32
primitives - Makafile - start a postgres container on local test flow
elpiel Apr 14, 2021
94fced6
sentry - spendable - use primitives::spender::Spendable
elpiel Apr 14, 2021
910971a
sentry - migrations - initial-tables - add campaign.creator index
elpiel Apr 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 26 additions & 80 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions primitives/Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[tasks.dev-test-flow]
description = "Development testing flow will first format the code, and than run cargo build and test"
category = "Development"
dependencies = [
"format-flow",
"format-toml-conditioned-flow",
"pre-build",
"build",
"post-build",
"services-up",
"test-flow",
"services-down",
]

[tasks.test]
env = { "POSTGRES_DB" = "sentry_leader" }

[tasks.services-up]
script = "docker-compose -f ../docker-compose.ci.yml up -d postgres-leader"

[tasks.services-down]
script = "docker-compose -f ../docker-compose.ci.yml down"
10 changes: 9 additions & 1 deletion primitives/src/campaign.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
channel_v5::Channel, targeting::Rules, AdUnit, Address, EventSubmission, UnifiedNum,
ValidatorDesc,
ValidatorDesc, ValidatorId,
};

use chrono::{
Expand Down Expand Up @@ -184,6 +184,14 @@ pub struct Campaign {
}

impl Campaign {
pub fn find_validator(&self, validator: ValidatorId) -> Option<&'_ ValidatorDesc> {
match (self.leader(), self.follower()) {
(Some(leader), _) if leader.id == validator => Some(leader),
(_, Some(follower)) if follower.id == validator => Some(follower),
_ => None,
}
}

/// Matches the Channel.leader to the Campaign.spec.leader
/// If they match it returns `Some`, otherwise, it returns `None`
pub fn leader(&self) -> Option<&'_ ValidatorDesc> {
Expand Down
1 change: 1 addition & 0 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub mod ipfs;
pub mod market;
pub mod merkle_tree;
pub mod sentry;
pub mod spender;
pub mod supermarket;
pub mod targeting;
mod unified_num;
Expand Down
7 changes: 0 additions & 7 deletions primitives/src/sentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,6 @@ impl fmt::Display for Event {
}
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct Earner {
#[serde(rename = "publisher")]
pub address: String,
pub promilles: u64,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EventAggregate {
Expand Down
49 changes: 49 additions & 0 deletions primitives/src/spender.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use crate::{channel_v5::Channel, Address, BalancesMap, UnifiedNum};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Deposit {
pub total: UnifiedNum,
pub still_on_create2: UnifiedNum,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Spendable {
pub spender: Address,
pub channel: Channel,
#[serde(flatten)]
pub deposit: Deposit,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Aggregate {
pub spender: Address,
pub channel: Channel,
pub balances: BalancesMap,
pub created: DateTime<Utc>,
}
#[cfg(feature = "postgres")]
mod postgres {
use std::convert::TryFrom;
use tokio_postgres::{Error, Row};

use super::*;

impl TryFrom<Row> for Spendable {
type Error = Error;

fn try_from(row: Row) -> Result<Self, Self::Error> {
Ok(Spendable {
spender: row.try_get("spender")?,
channel: row.try_get("channel")?,
deposit: Deposit {
total: row.try_get("total")?,
still_on_create2: row.try_get("still_on_create2")?,
},
})
}
}
}
5 changes: 4 additions & 1 deletion primitives/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,13 @@ impl TryFrom<Value> for ValidatorId {
#[serde(rename_all = "camelCase")]
pub struct ValidatorDesc {
pub id: ValidatorId,
/// The validator fee in pro milles (per 1000)
pub fee: UnifiedNum,
#[serde(default, skip_serializing_if = "Option::is_none")]
/// The address which will receive the fees
pub fee_addr: Option<Address>,
/// The url of the Validator on which is the API
pub url: String,
pub fee: UnifiedNum,
}

/// Validator Message Types
Expand Down
9 changes: 7 additions & 2 deletions sentry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "sentry"
version = "0.1.0"
authors = ["Omidiora Samuel <[email protected]>"]
authors = ["Lachezar Lechev <[email protected]>", "Omidiora Samuel <[email protected]>"]
edition = "2018"

[dependencies]
Expand All @@ -27,7 +27,7 @@ bb8 = "0.7"
bb8-postgres = { version = "0.7", features = ["with-chrono-0_4", "with-serde_json-1"] }

# Migrations
migrant_lib = { version = "^0.30", features = ["d-postgres"] }
migrant_lib = { version = "^0.32", features = ["d-postgres"] }
# Logger
slog = { version = "^2.2.3", features = ["max_level_trace"] }
# Serde
Expand All @@ -37,5 +37,10 @@ serde_urlencoded = "^0.7"
# Other
lazy_static = "1.4.0"
thiserror = "^1.0"
tokio-postgres = { version = "0.7.0", features = ["with-chrono-0_4", "with-serde_json-1"] }

[dev-dependencies]
# todo: Replace `bb8` once we update all places.
deadpool = "0.7.0"
deadpool-postgres = "0.7.0"
once_cell = "1.5.2"
5 changes: 4 additions & 1 deletion sentry/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ dependencies = [
"services-down",
]

[tasks.test]
env = { "POSTGRES_DB" = "sentry_leader" }

[tasks.services-up]
script = "docker-compose -f ../docker-compose.ci.yml up -d redis-leader"
script = "docker-compose -f ../docker-compose.ci.yml up -d redis-leader postgres-leader"

[tasks.services-down]
script = "docker-compose -f ../docker-compose.ci.yml down"
Loading