diff --git a/client/encointer-api-client-extension/src/ceremonies.rs b/client/encointer-api-client-extension/src/ceremonies.rs index 17853441..00596220 100644 --- a/client/encointer-api-client-extension/src/ceremonies.rs +++ b/client/encointer-api-client-extension/src/ceremonies.rs @@ -83,6 +83,18 @@ pub trait CeremoniesApi { &self, community_ceremony: CommunityCeremony, ) -> Result; + + fn get_attestees( + &self, + community_ceremony: CommunityCeremony, + participant_index: ParticipantIndexType, + ) -> Result>; + + fn get_meetup_participant_count_vote( + &self, + community_ceremony: CommunityCeremony, + account_id: AccountId, + ) -> Result; } impl CeremoniesApi for Api { @@ -347,6 +359,36 @@ impl CeremoniesApi for Api { meetups, )) } + + fn get_attestees( + &self, + community_ceremony: CommunityCeremony, + p_index: ParticipantIndexType, + ) -> Result> { + 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 { + 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( @@ -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, +} + +impl AttestationState { + pub fn new( + community_ceremony: CommunityCeremony, + meetup_index: MeetupIndexType, + vote: u32, + attestation_index: u64, + attestor: AccountId, + attestees: Vec, + ) -> Self { + Self { community_ceremony, meetup_index, vote, attestation_index, attestor, attestees } + } +} + #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Meetup { diff --git a/client/src/main.rs b/client/src/main.rs index 05cc1889..e2eb406b 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -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::{ @@ -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(); @@ -1608,15 +1627,6 @@ fn get_attestee_count(api: &Api, key: CommunityCeremony) -> ParticipantIndexType .unwrap() } -fn get_attestees( - api: &Api, - key: CommunityCeremony, - windex: ParticipantIndexType, -) -> Option> { - api.get_storage_double_map("EncointerCeremonies", "AttestationRegistry", key, windex, None) - .unwrap() -} - fn get_participant_attestation_index( api: &Api, key: CommunityCeremony,