Skip to content

Commit

Permalink
list-attestees shows vote and is grouped by the meetup index (#268)
Browse files Browse the repository at this point in the history
* [client] add `AttestorState`

* [client] fetch attestor vote and put it into the `AttestationState`

* [client] add meetup index to attestation states and group the vector by the meetup index.

* [client] `AttestationState`: reorder fields for better readability.

* [client] `AttestationState`: add attestation index to fields
  • Loading branch information
clangenb authored Nov 21, 2022
1 parent a71cdbe commit 9e60397
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 14 deletions.
65 changes: 65 additions & 0 deletions client/encointer-api-client-extension/src/ceremonies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ pub trait CeremoniesApi {
&self,
community_ceremony: CommunityCeremony,
) -> Result<CommunityCeremonyStats>;

fn get_attestees(
&self,
community_ceremony: CommunityCeremony,
participant_index: ParticipantIndexType,
) -> Result<Vec<AccountId>>;

fn get_meetup_participant_count_vote(
&self,
community_ceremony: CommunityCeremony,
account_id: AccountId,
) -> Result<u32>;
}

impl CeremoniesApi for Api {
Expand Down Expand Up @@ -347,6 +359,36 @@ impl CeremoniesApi for Api {
meetups,
))
}

fn get_attestees(
&self,
community_ceremony: CommunityCeremony,
p_index: ParticipantIndexType,
) -> Result<Vec<AccountId>> {
self.get_storage_double_map(
"EncointerCeremonies",
"AttestationRegistry",
community_ceremony,
p_index,
None,
)?
.ok_or_else(|| ApiClientError::Other("Attestees don't exist".into()))
}

fn get_meetup_participant_count_vote(
&self,
community_ceremony: CommunityCeremony,
account_id: AccountId,
) -> Result<u32> {
self.get_storage_double_map(
"EncointerCeremonies",
"MeetupParticipantCountVote",
community_ceremony,
account_id,
None,
)?
.ok_or_else(|| ApiClientError::Other("MeetupParticipantCountVote don't exist".into()))
}
}

fn get_bootstrapper_or_reputable(
Expand Down Expand Up @@ -386,6 +428,29 @@ impl CommunityCeremonyStats {
}
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AttestationState {
pub community_ceremony: CommunityCeremony,
pub meetup_index: MeetupIndexType,
pub vote: u32,
pub attestation_index: u64,
pub attestor: AccountId,
pub attestees: Vec<AccountId>,
}

impl AttestationState {
pub fn new(
community_ceremony: CommunityCeremony,
meetup_index: MeetupIndexType,
vote: u32,
attestation_index: u64,
attestor: AccountId,
attestees: Vec<AccountId>,
) -> Self {
Self { community_ceremony, meetup_index, vote, attestation_index, attestor, attestees }
}
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Meetup {
Expand Down
38 changes: 24 additions & 14 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use clap_nested::{Command, Commander};
use cli_args::{EncointerArgs, EncointerArgsExtractor};
use codec::{Compact, Decode, Encode};
use encointer_api_client_extension::{
Api, CeremoniesApi, CommunitiesApi, CommunityCurrencyTip,
Api, AttestationState, CeremoniesApi, CommunitiesApi, CommunityCurrencyTip,
CommunityCurrencyTipExtrinsicParamsBuilder, EncointerXt, SchedulerApi, ENCOINTER_CEREMONIES,
};
use encointer_node_notee_runtime::{
Expand Down Expand Up @@ -861,13 +861,32 @@ fn main() {
}
}

let mut attestation_states = Vec::with_capacity(wcount as usize);

for w in 1..wcount + 1 {
let attestees = get_attestees(&api, (cid, cindex), w);
println!(
"AttestationRegistry[{}, {} ({})] = {:?}",
cindex, w, participants_windex[&w], attestees
let attestor = participants_windex[&w].clone();
let meetup_index = api.get_meetup_index(&(cid, cindex), &attestor).unwrap().unwrap();
let attestees = api.get_attestees((cid, cindex), w).unwrap();
let vote = api.get_meetup_participant_count_vote((cid, cindex), attestor.clone()).unwrap();
let attestation_state = AttestationState::new(
(cid, cindex),
meetup_index,
vote,
w,
attestor,
attestees,
);

attestation_states.push(attestation_state);
}

// Group attestation states by meetup index
attestation_states.sort_by(|a, b| a.meetup_index.partial_cmp(&b.meetup_index).unwrap());

for a in attestation_states.iter() {
println!("{:?}", a);
}

Ok(())
}
).unwrap();
Expand Down Expand Up @@ -1608,15 +1627,6 @@ fn get_attestee_count(api: &Api, key: CommunityCeremony) -> ParticipantIndexType
.unwrap()
}

fn get_attestees(
api: &Api,
key: CommunityCeremony,
windex: ParticipantIndexType,
) -> Option<Vec<AccountId>> {
api.get_storage_double_map("EncointerCeremonies", "AttestationRegistry", key, windex, None)
.unwrap()
}

fn get_participant_attestation_index(
api: &Api,
key: CommunityCeremony,
Expand Down

0 comments on commit 9e60397

Please sign in to comment.