Skip to content

Commit

Permalink
Merge a8ed496 into 058bdab
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Leshiy committed May 25, 2023
2 parents 058bdab + a8ed496 commit b2f8553
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 182 deletions.
11 changes: 5 additions & 6 deletions Makefiles/db.toml
Expand Up @@ -47,12 +47,11 @@ psql -U catalyst-event-dev -d CatalystEventDev -f test_data/02_snapshot_table.sq
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/03_voter_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/04_contribution_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/05_goal_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/06_voting_group_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/07_objective_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/08_proposal_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/09_proposal_review_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/10_review_rating_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/11_objective_review_metric_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/06_objective_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/07_proposal_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/08_proposal_review_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/09_review_rating_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/10_objective_review_metric_table.sql ${@}
'''

# Install historic data for past events
Expand Down
5 changes: 0 additions & 5 deletions book/src/07_web_api/openapi/core_backend_api.yaml
Expand Up @@ -722,11 +722,6 @@ components:
schedule:
$ref: '#/components/schemas/EventSchedule'
description: The schedule of the voting Event
groups:
type: array
description: The valid voter groups for this voting event.
items:
$ref: '#/components/schemas/VoterGroup'
Event:
allOf:
- $ref: '#/components/schemas/EventSummary'
Expand Down
14 changes: 2 additions & 12 deletions src/cat-data-service/src/service/v1/event/mod.rs
Expand Up @@ -85,8 +85,8 @@ mod tests {
};
use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, Utc};
use event_db::types::event::{
EventDetails, EventGoal, EventId, EventRegistration, EventSchedule, VoterGroup,
VotingPowerAlgorithm, VotingPowerSettings,
EventDetails, EventGoal, EventId, EventRegistration, EventSchedule, VotingPowerAlgorithm,
VotingPowerSettings,
};
use rust_decimal::Decimal;
use tower::ServiceExt;
Expand Down Expand Up @@ -238,16 +238,6 @@ mod tests {
name: "goal 4".to_string(),
}
],
groups: vec![
VoterGroup {
id: "rep".to_string(),
voting_token: "rep token".to_string()
},
VoterGroup {
id: "direct".to_string(),
voting_token: "direct token".to_string()
}
]
},
},)
.unwrap()
Expand Down
28 changes: 12 additions & 16 deletions src/event-db/migrations/V5__vote_plan.sql
Expand Up @@ -23,37 +23,33 @@ COMMENT ON COLUMN voteplan_category.public_key IS 'Does this vote plan category
-- groups

CREATE TABLE voting_group (
row_id SERIAL PRIMARY KEY,
group_id VARCHAR NOT NULL,
event_id INTEGER NOT NULL,
token_id VARCHAR,

FOREIGN KEY(event_id) REFERENCES event(row_id) ON DELETE CASCADE
name TEXT PRIMARY KEY
);

CREATE UNIQUE INDEX token_event_id ON voting_group (token_id, event_id);
INSERT INTO voting_group (name)
VALUES
('direct'), -- Direct Voters
('rep'); -- Delegated Voter (Check what is the real name for this group we already use in snapshot)

COMMENT ON TABLE voting_group IS 'All Groups.';
COMMENT ON COLUMN voting_group.row_id IS 'Synthetic Unique Key.';
COMMENT ON COLUMN voting_group.group_id IS 'The ID of this voting group.';
COMMENT ON COLUMN voting_group.event_id IS 'The event this voting group belongs to.';
COMMENT ON COLUMN voting_group.token_id IS 'The ID of the voting token used by this group.';
COMMENT ON COLUMN voting_group.name IS 'The ID of this voting group.';

-- Vote Plans

CREATE TABLE voteplan
(
row_id SERIAL PRIMARY KEY,
event_id INTEGER NOT NULL,
objective_id INTEGER NOT NULL,

id VARCHAR NOT NULL UNIQUE,
id VARCHAR NOT NULL,
category TEXT NOT NULL,
encryption_key VARCHAR,
group_id INTEGER,
group_id TEXT,
token_id TEXT,

FOREIGN KEY(event_id) REFERENCES event(row_id) ON DELETE CASCADE,
FOREIGN KEY(objective_id) REFERENCES objective(row_id) ON DELETE CASCADE,
FOREIGN KEY(category) REFERENCES voteplan_category(name) ON DELETE CASCADE,
FOREIGN KEY(group_id) REFERENCES voting_group(row_id) ON DELETE CASCADE
FOREIGN KEY(group_id) REFERENCES voting_group(name) ON DELETE CASCADE
);

COMMENT ON TABLE voteplan IS 'All Vote plans.';
Expand Down
20 changes: 11 additions & 9 deletions src/event-db/migrations/V9__vitss_compatibility.sql
Expand Up @@ -132,10 +132,10 @@ CREATE VIEW voteplans AS SELECT
voteplan.category AS chain_voteplan_payload,
voteplan.encryption_key AS chain_vote_encryption_key,
event.row_id AS fund_id,
voting_group.token_id AS token_identifier
voteplan.token_id AS token_identifier
FROM voteplan
INNER JOIN event ON voteplan.event_id = event.row_id
INNER JOIN voting_group ON voteplan.group_id = voting_group.row_id;
INNER JOIN objective ON voteplan.objective_id = objective.row_id
INNER JOIN event ON objective.event = event.row_id;

COMMENT ON VIEW voteplans IS
'@omit
Expand Down Expand Up @@ -214,10 +214,12 @@ Do not use this VIEW for new queries, its ONLY for backward compatibility.';
-- VIT-SS Compatibility View - groups.

CREATE VIEW groups AS SELECT
event_id AS fund_id,
token_id AS token_identifier,
group_id AS group_id
FROM voting_group;
objective.event AS fund_id,
voteplan.token_id AS token_identifier,
voting_group.name AS group_id
FROM voting_group
INNER JOIN voteplan ON voteplan.group_id = voting_group.name
INNER JOIN objective ON voteplan.objective_id = objective.row_id;

COMMENT ON VIEW groups IS
'@omit
Expand All @@ -244,12 +246,12 @@ SELECT
pccc.proposal_metrics,
pvp.chain_proposal_index,
pvp.chain_voteplan_id,
gr.group_id
voteplan.group_id
FROM proposals p
INNER JOIN proposals_voteplans pvp ON p.id::VARCHAR = pvp.proposal_id
INNER JOIN voteplans vp ON pvp.chain_voteplan_id = vp.chain_voteplan_id
INNER JOIN challenges ch ON ch.id = p.challenge_id
INNER JOIN groups gr ON vp.token_identifier = gr.token_identifier
INNER JOIN voteplan ON voteplan.id = vp.chain_voteplan_id
LEFT JOIN proposal_simple_challenge psc
ON p.proposal_id = psc.proposal_id
AND ch.challenge_type = 'catalyst-simple'
Expand Down
26 changes: 1 addition & 25 deletions src/event-db/src/queries/event/mod.rs
Expand Up @@ -2,7 +2,7 @@ use crate::{
error::Error,
types::event::{
Event, EventDetails, EventGoal, EventId, EventRegistration, EventSchedule, EventSummary,
VoterGroup, VotingPowerAlgorithm, VotingPowerSettings,
VotingPowerAlgorithm, VotingPowerSettings,
},
EventDB,
};
Expand Down Expand Up @@ -44,10 +44,6 @@ impl EventDB {
const EVENT_GOALS_QUERY: &'static str = "SELECT goal.idx, goal.name
FROM goal
WHERE goal.event_id = $1;";

const EVENT_GROUPS_QUERY: &'static str = "SELECT voting_group.group_id, voting_group.token_id
FROM voting_group
WHERE voting_group.event_id = $1;";
}

#[async_trait]
Expand Down Expand Up @@ -154,15 +150,6 @@ impl EventQueries for EventDB {
})
}

let rows = conn.query(Self::EVENT_GROUPS_QUERY, &[&event.0]).await?;
let mut groups = Vec::new();
for row in rows {
groups.push(VoterGroup {
id: row.try_get("group_id")?,
voting_token: row.try_get("token_id")?,
})
}

Ok(Event {
summary: EventSummary {
id: EventId(row.try_get("row_id")?),
Expand All @@ -180,7 +167,6 @@ impl EventQueries for EventDB {
voting_power,
schedule,
goals,
groups,
registration,
},
})
Expand Down Expand Up @@ -542,16 +528,6 @@ mod tests {
name: "goal 4".to_string(),
}
],
groups: vec![
VoterGroup {
id: "rep".to_string(),
voting_token: "rep token".to_string()
},
VoterGroup {
id: "direct".to_string(),
voting_token: "direct token".to_string()
}
]
},
},
);
Expand Down
21 changes: 0 additions & 21 deletions src/event-db/src/types/event/mod.rs
Expand Up @@ -134,7 +134,6 @@ pub struct EventDetails {
pub registration: EventRegistration,
pub schedule: EventSchedule,
pub goals: Vec<EventGoal>,
pub groups: Vec<VoterGroup>,
}

#[derive(Debug, Serialize, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -497,10 +496,6 @@ mod tests {
Utc,
)),
},
groups: vec![VoterGroup {
id: "rep".to_string(),
voting_token: "voting token 1".to_string(),
}],
};

let json = serde_json::to_value(&event_details).unwrap();
Expand Down Expand Up @@ -535,12 +530,6 @@ mod tests {
"tallying": "1970-01-01T00:00:00+00:00",
"tallying_end": "1970-01-01T00:00:00+00:00",
},
"groups": [
{
"id": "rep",
"voting_token": "voting token 1",
}
],
}
)
);
Expand Down Expand Up @@ -625,10 +614,6 @@ mod tests {
Utc,
)),
},
groups: vec![VoterGroup {
id: "rep".to_string(),
voting_token: "voting token 1".to_string(),
}],
},
};

Expand Down Expand Up @@ -670,12 +655,6 @@ mod tests {
"tallying": "1970-01-01T00:00:00+00:00",
"tallying_end": "1970-01-01T00:00:00+00:00",
},
"groups": [
{
"id": "rep",
"voting_token": "voting token 1",
}
],
}
)
);
Expand Down
13 changes: 0 additions & 13 deletions src/event-db/test_data/06_voting_group_table.sql

This file was deleted.

Expand Up @@ -3,6 +3,8 @@ use crate::common::data::ArbitraryValidVotingTemplateGenerator;
use crate::common::data::{Snapshot, ValidVotingTemplateGenerator};
use chain_impl_mockchain::certificate::ExternalProposalId;
use itertools::Itertools;
use snapshot_lib::voting_group::DEFAULT_DIRECT_VOTER_GROUP;
use snapshot_lib::voting_group::DEFAULT_REPRESENTATIVE_GROUP;
use std::collections::BTreeSet;
use std::iter;
use time::{Duration, OffsetDateTime};
Expand Down Expand Up @@ -82,10 +84,18 @@ impl ArbitrarySnapshotGenerator {

let groups: BTreeSet<Group> = std::iter::from_fn(|| Some(self.id_generator.next_i32()))
.take(2)
.map(|group_id| Group {
fund_id: id,
token_identifier: format!("group{group_id}-token"),
group_id: group_id.to_string(),
.map(|group_id| {
let group_id = if group_id % 2 == 0 {
DEFAULT_DIRECT_VOTER_GROUP.to_string()
} else {
DEFAULT_REPRESENTATIVE_GROUP.to_string()
};

Group {
fund_id: id,
token_identifier: format!("group{group_id}-token"),
group_id,
}
})
.collect();

Expand Down
@@ -1,4 +1,5 @@
use super::dates::FundDates;
use snapshot_lib::voting_group::{DEFAULT_DIRECT_VOTER_GROUP, DEFAULT_REPRESENTATIVE_GROUP};
use vit_servicing_station_lib::db::models::{funds::Fund, goals::Goal, groups::Group};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -66,12 +67,12 @@ impl Default for FundInfo {
Group {
fund_id: 1,
token_identifier: "00000000000000000000000000000000000000000000000000000000.0000000000000000000000000000000000000000000000000000000000000000".to_string(),
group_id: "12345".to_string(),
group_id: DEFAULT_DIRECT_VOTER_GROUP.to_string(),
},
Group {
fund_id: 1,
token_identifier: "00000000000000000000000000000000000000000000000000000001.0000000000000000000000000000000000000000000000000000000000000000".to_string(),
group_id: "12346".to_string(),
group_id: DEFAULT_REPRESENTATIVE_GROUP.to_string(),
},
],
}
Expand Down

0 comments on commit b2f8553

Please sign in to comment.