Skip to content

Commit

Permalink
perform meetup: attest attendees and list attestees (#39)
Browse files Browse the repository at this point in the history
* perform meetup: attest attendees and list attestees

* clippy

* changes from review

---------

Co-authored-by: echevrier <[email protected]>
  • Loading branch information
echevrier and echevrier authored Jan 30, 2023
1 parent 53c7400 commit 5c6fdba
Show file tree
Hide file tree
Showing 9 changed files with 606 additions and 144 deletions.
130 changes: 111 additions & 19 deletions app-libs/stf/src/getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
use crate::{AccountId, KeyPair, Signature};
use codec::{Decode, Encode};
use encointer_primitives::{
ceremonies::ParticipantIndexType, communities::CommunityIdentifier,
ceremonies::{AttestationIndexType, ParticipantIndexType},
communities::CommunityIdentifier,
scheduler::CeremonyIndexType,
};
use ita_sgx_runtime::System;
Expand Down Expand Up @@ -66,6 +67,7 @@ impl From<TrustedGetterSigned> for Getter {
pub enum PublicGetter {
some_value,
ceremonies_assignment_counts(CommunityIdentifier, CeremonyIndexType),
ceremonies_attestation_count(CommunityIdentifier, CeremonyIndexType),
ceremonies_meetup_count(CommunityIdentifier, CeremonyIndexType),
ceremonies_meetup_time_offset(),
ceremonies_registered_bootstrappers_count(CommunityIdentifier, CeremonyIndexType),
Expand All @@ -91,12 +93,29 @@ pub enum TrustedGetter {
//encointer_balance(AccountId, CommunityIdentifier),
//ceremonies_participant_index(AccountId, CommunityIdentifier),
//Not public : ceremonies_meetup_index(AccountId, CommunityIdentifier),
ceremonies_aggregated_account_data(AccountId, CommunityIdentifier, CeremonyIndexType),
ceremonies_aggregated_account_data(AccountId, CommunityIdentifier, AccountId),
ceremonies_assignments(AccountId, CommunityIdentifier, CeremonyIndexType),
//ceremonies_meetup_locations(AccountId, CommunityIdentifier, CeremonyIndexType, MeetupIndexType),
//ceremonies_reputations(AccountId, CommunityIdentifier),
//ceremonies_attestations(AccountId, CommunityIdentifier),
//ceremonies_participant_reputation(AccountId, CommunityIdentifier, CeremonyIndexType),
ceremonies_meetup_participant_count_vote(
AccountId,
CommunityIdentifier,
CeremonyIndexType,
AccountId,
),
ceremonies_participant_attestees(
AccountId,
CommunityIdentifier,
CeremonyIndexType,
AttestationIndexType,
),
ceremonies_participant_attestation_index(
AccountId,
CommunityIdentifier,
CeremonyIndexType,
AccountId,
),
ceremonies_registered_bootstrapper(
AccountId,
CommunityIdentifier,
Expand Down Expand Up @@ -152,6 +171,12 @@ impl TrustedGetter {
sender_account,
TrustedGetter::ceremonies_assignments(sender_account, _, _) => sender_account,
//TrustedGetter::ceremonies_meetup_locations(sender_account, _, _, _) => sender_account,
TrustedGetter::ceremonies_meetup_participant_count_vote(sender_account, _, _, _) =>
sender_account,
TrustedGetter::ceremonies_participant_attestees(sender_account, _, _, _) =>
sender_account,
TrustedGetter::ceremonies_participant_attestation_index(sender_account, _, _, _) =>
sender_account,
TrustedGetter::ceremonies_registered_bootstrapper(sender_account, _, _, _) =>
sender_account,
TrustedGetter::ceremonies_registered_bootstrappers(sender_account, _, _) =>
Expand Down Expand Up @@ -269,27 +294,92 @@ impl ExecuteGetter for TrustedGetterSigned {
Some(attestations.encode())
},
*/
TrustedGetter::ceremonies_aggregated_account_data(
who,
community_id,
_ceremony_index,
) => {
error!("TrustedGetter ceremonies_aggregated_account_data");
TrustedGetter::ceremonies_aggregated_account_data(who, community_id, account_id) => {
debug!("TrustedGetter ceremonies_aggregated_account_data");
//Todo Master or Me?
if !is_ceremony_master(who) {
debug!("TrustedGetter ceremonies_aggregated_account_data, return: No master");
return None
}
let aggregated_account_data =
EncointerCeremonies::get_aggregated_account_data(community_id, &who);
//aggregated_account_data.personal.map(|p| p.encode())
EncointerCeremonies::get_aggregated_account_data(community_id, &account_id);
Some(aggregated_account_data.encode())
},
TrustedGetter::ceremonies_assignments(who, community_id, ceremony_index) => {
error!("TrustedGetter ceremonies_assignments");
debug!("TrustedGetter ceremonies_assignments");
// Block getter of confidential data if it is not the CeremonyMaster.
if !is_ceremony_master(who) {
error!("TrustedGetter ceremonies_assignments, return: No master");
debug!("TrustedGetter ceremonies_assignments, return: No master");
return None
}
let assignments = EncointerCeremonies::assignments((community_id, ceremony_index));
Some(assignments.encode())
},
TrustedGetter::ceremonies_meetup_participant_count_vote(
who,
community_id,
ceremony_index,
participant_account_id,
) => {
debug!("TrustedGetter ceremonies_meetup_participant_count_vote");
// Todo Master or Me?
// Block getter of confidential data if it is not the CeremonyMaster
if !is_ceremony_master(who) {
return None
}
Some(
EncointerCeremonies::meetup_participant_count_vote(
(community_id, ceremony_index),
&participant_account_id,
)
.encode(),
)
},
TrustedGetter::ceremonies_participant_attestees(
who,
community_id,
ceremony_index,
attestation_index,
) => {
debug!("TrustedGetter ceremonies_participant_attestees");
// Block getter of confidential data if it is not the CeremonyMaster
if !is_ceremony_master(who) {
return None
}
match EncointerCeremonies::attestation_registry(
(community_id, ceremony_index),
&attestation_index,
) {
Some(b) => Some(b.encode()),
_ => {
warn!(
"no attestees for {}, {}, {}",
community_id, ceremony_index, attestation_index
);
None
},
}
},
TrustedGetter::ceremonies_participant_attestation_index(
who,
community_id,
ceremony_index,
participant_account_id,
) => {
debug!("TrustedGetter ceremonies_participant_attestation_index");
//Todo Master or Me?
// Block getter of confidential data if it is not the CeremonyMaster
if !is_ceremony_master(who) {
return None
}
Some(
EncointerCeremonies::attestation_index(
(community_id, ceremony_index),
&participant_account_id,
)
.encode(),
)
},
TrustedGetter::ceremonies_registered_bootstrapper(
who,
community_id,
Expand Down Expand Up @@ -576,17 +666,13 @@ impl ExecuteGetter for TrustedGetterSigned {
fn get_storage_hashes_to_update(self) -> Vec<Vec<u8>> {
let mut key_hashes = Vec::new();
match self.getter {
TrustedGetter::ceremonies_aggregated_account_data(
_,
_community_id,
_ceremony_index,
) => {
TrustedGetter::ceremonies_aggregated_account_data(_, _, _) => {
key_hashes.push(storage_value_key("EncointerScheduler", "CurrentCeremonyIndex"));
let current_phase =
pallet_encointer_scheduler::Pallet::<ita_sgx_runtime::Runtime>::current_phase(); // updated im block import
key_hashes.push(storage_map_key(
"EncointerScheduler",
"PhaseDuration",
"PhaseDurations",
&current_phase,
&StorageHasher::Blake2_128Concat,
));
Expand All @@ -608,6 +694,12 @@ impl ExecuteGetter for PublicGetter {
let count = EncointerCeremonies::assignment_counts((community_id, ceremony_index));
Some(count.encode())
},
PublicGetter::ceremonies_attestation_count(community_id, ceremony_index) => {
let count = pallet_encointer_ceremonies::Pallet::<
ita_sgx_runtime::Runtime,
>::attestation_count((community_id, ceremony_index));
Some(count.encode())
},
PublicGetter::ceremonies_meetup_count(community_id, ceremony_index) => {
let count = EncointerCeremonies::meetup_count((community_id, ceremony_index));
Some(count.encode())
Expand Down
98 changes: 28 additions & 70 deletions app-libs/stf/src/trusted_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub enum TrustedCall {
encointer_set_fee_conversion_factor(AccountId, FeeConversionFactorType),
encointer_transfer_all(AccountId, AccountId, CommunityIdentifier),
*/
ceremonies_attest_attendees(AccountId, CommunityIdentifier, u32, Vec<AccountId>),
ceremonies_register_participant(
AccountId,
CommunityIdentifier,
Expand All @@ -76,13 +77,6 @@ pub enum TrustedCall {
ProofOfAttendance<Signature, AccountId>,
),
ceremonies_unregister_participant(AccountId, CommunityIdentifier, Option<CommunityCeremony>),
ceremonies_attest_attendees(
AccountId,
CommunityIdentifier,
u32,
CeremonyIndexType,
Vec<AccountId>,
),
ceremonies_endorse_newcomer(AccountId, CommunityIdentifier, AccountId),
ceremonies_claim_rewards(AccountId, CommunityIdentifier, Option<MeetupIndexType>),
ceremonies_set_inactivity_timeout(AccountId, InactivityTimeoutType),
Expand Down Expand Up @@ -152,6 +146,7 @@ impl TrustedCall {
//TrustedCall::encointer_balance_transfer(sender_account, ..) => sender_account,
//TrustedCall::encointer_set_fee_conversion_factor(sender_account, ..) => sender_account,
//TrustedCall::encointer_transfer_all(sender_account, ..) => sender_account,
TrustedCall::ceremonies_attest_attendees(sender_account, ..) => sender_account,
TrustedCall::ceremonies_register_participant(sender_account, ..) => sender_account,
TrustedCall::ceremonies_migrate_to_private_community(sender_account, ..) =>
sender_account,
Expand All @@ -160,7 +155,6 @@ impl TrustedCall {
TrustedCall::ceremonies_upgrade_registration(sender_account, ..) => sender_account,
TrustedCall::ceremonies_unregister_participant(sender_account, ..) => sender_account,
TrustedCall::ceremonies_attest_attendees(sender_account, ..) => sender_account,
TrustedCall::ceremonies_endorse_newcomer(sender_account, ..) => sender_account,
TrustedCall::ceremonies_claim_rewards(sender_account, ..) => sender_account,
TrustedCall::ceremonies_set_inactivity_timeout(sender_account, ..) => sender_account,
Expand Down Expand Up @@ -384,6 +378,28 @@ impl ExecuteCall for TrustedCallSigned {
},
*/
TrustedCall::ceremonies_attest_attendees(
who,
cid,
number_of_participants_vote,
attestations,
) => {
let origin = ita_sgx_runtime::Origin::signed(who);

ita_sgx_runtime::EncointerCeremoniesCall::<Runtime>::attest_attendees {
cid,
number_of_participants_vote,
attestations,
}
.dispatch_bypass_filter(origin)
.map_err(|e| {
Self::Error::Dispatch(format!(
"Ceremonies attendees attestation error: {:?}",
e.error
))
})?;
Ok(())
},
TrustedCall::ceremonies_register_participant(who, cid, proof) => {
let origin = ita_sgx_runtime::Origin::signed(who);

Expand All @@ -393,15 +409,6 @@ impl ExecuteCall for TrustedCallSigned {
))
}

if pallet_encointer_scheduler::Pallet::<ita_sgx_runtime::Runtime>::current_phase()
== CeremonyPhaseType::Assigning
{
return Err(Self::Error::Dispatch(
"registering a participant can only be done during registering or attesting phase"
.to_string(),
))
}

ita_sgx_runtime::EncointerCeremoniesCall::<Runtime>::register_participant {
cid,
proof,
Expand Down Expand Up @@ -472,14 +479,6 @@ impl ExecuteCall for TrustedCallSigned {
))
}

if pallet_encointer_scheduler::Pallet::<ita_sgx_runtime::Runtime>::current_phase()
!= CeremonyPhaseType::Registering
{
return Err(Self::Error::Dispatch(
"adding a location can only be done during the registering phase"
.to_string(),
))
}
ita_sgx_runtime::EncointerCommunitiesCall::<Runtime>::add_location {
cid,
location,
Expand Down Expand Up @@ -546,37 +545,6 @@ impl ExecuteCall for TrustedCallSigned {
})?;
Ok(())
},
TrustedCall::ceremonies_attest_attendees(
who,
cid,
number_of_participants_vote,
_ceremony_index,
attestations,
) => {
let origin = ita_sgx_runtime::Origin::signed(who);
if pallet_encointer_scheduler::Pallet::<ita_sgx_runtime::Runtime>::current_phase()
!= CeremonyPhaseType::Attesting
{
return Err(Self::Error::Dispatch(
"attendees attestation can only be done during attesting phase".to_string(),
))
}
ita_sgx_runtime::EncointerCeremoniesCall::<Runtime>::attest_attendees {
cid,
number_of_participants_vote,
attestations,
}
.dispatch_bypass_filter(origin)
.map_err(|e| {
Self::Error::Dispatch(format!(
"Ceremonies attendees attestation error: {:?}",
e.error
))
})?;
Ok(())
},
TrustedCall::ceremonies_endorse_newcomer(who, cid, newbie) => {
let origin = ita_sgx_runtime::Origin::signed(who);
Expand Down Expand Up @@ -926,6 +894,10 @@ impl ExecuteCall for TrustedCallSigned {
| TrustedCall::ceremonies_upgrade_registration(_, cid, _)
| TrustedCall::ceremonies_unregister_participant(_, cid, _) => {
*/
TrustedCall::ceremonies_attest_attendees(_, _, _, _) => {
key_hashes.push(storage_value_key("EncointerScheduler", "PhaseDurations"));
key_hashes.push(storage_value_key("EncointerScheduler", "CurrentCeremonyIndex"));
},
TrustedCall::ceremonies_register_participant(_, _, _) => {
key_hashes.push(storage_value_key("EncointerScheduler", "CurrentCeremonyIndex"));
},
Expand Down Expand Up @@ -970,20 +942,6 @@ impl ExecuteCall for TrustedCallSigned {
TrustedCall::communities_add_location(_, _, _) =>
debug!("No storage updates needed..."),
/*
//get_aggregated_account_data ?
TrustedCall::ceremonies_attest_attendees(_, cid, _, ceremony_index, _) => {
key_hashes.push(storage_value_key("EncointerScheduler", "PhaseDurations"));
key_hashes.push(storage_value_key("EncointerScheduler", "CurrentCeremonyIndex"));
key_hashes.push(storage_value_key("EncointerCommunities", "CommunityIdentifiers"));
key_hashes.push(storage_double_map_key(
"EncointerCommunities",
"Locations",
&cid,
&StorageHasher::Blake2_128Concat,
&ceremony_index,
&StorageHasher::Identity,
));
},
TrustedCall::ceremonies_claim_rewards(_, cid, _) => {
key_hashes.push(storage_value_key("EncointerCommunities", "CommunityIdentifiers"));
key_hashes.push(storage_value_key("EncointerCommunities", "NominalIncome"));
Expand Down
Loading

0 comments on commit 5c6fdba

Please sign in to comment.