Skip to content

catalyst-contest simple tally procedure #731

@Mr-Leshiy

Description

@Mr-Leshiy

Summary

Implement a function which could perform a simple tally without any delegations. Just taking into account Contest Ballot, Contest Parameters, Proposal and some other needed documents but without any delegation part.
It should mainly follow the catalyst-libs/rust/catalyst-voting/tests/voting_test.rs but in terms of documents which were mentioned previously.

Acceptance criteria

  • implement a public function for catalyst-contest which would take as an argument Contest Parameters document and provider instance and returns tally result in the form of HashMap<DocumentRef, u64>. where DocumentRef is a reference to the corresponding Proposal document and u64 its a final "score" of it.
 fn tally(contest: &ContestParameters, provider: Provider) -> anyhow::Result<TallyResult>;
  • Added a unit test following mainly catalyst-libs/rust/catalyst-voting/tests/voting_test.rs by preparing all necessary documents and submitting them to the provider and calling tally function to get the expected result.

Important notes

  • How to determine which Proposal document assigned to the contest ?
    Get the Contest Parameters parameters metadata field value, find all Proposal documents which are referencing to the to exactly the same document under the parameters metadata field. Consider ONLY latest by ver field of Proposal document.
let param = contest_param.doc_meta().parameters();
let search_query = CatalystSignedDocumentSearchQuery {
        doc_type: PROPOSAL,
        parameters: Some(DocumentRefSelector::Eq(param)),
    };
let proposals = provider.try_search_docs(search_query)?;
  • How to get the list of voted "users" with their voting power ?
    Go through all Contest Ballot documents and collect its authors/singers at the point of voting_start.
type VotingPower = HashMap<CatalystId, u64>;
let voting_end = contest_param.voting_end();
let voting_power = ballots.iter().map(|b|  (b.voter(), provider.try_get_voting_power_up_to(b.voter(), voting_end))).collect()
  • What if the same user was voted twice (double vote) ?
    Take into account only the latest Contest Ballot document by the id and ver fields

Metadata

Metadata

Assignees

Labels

squad: gatekeepersCatalyst App Backend, System Development & Integration Team

Type

Projects

Status

🏗 In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions