Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Feb 27, 2024
1 parent 14e5d74 commit 54ffa22
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
26 changes: 14 additions & 12 deletions primitives/src/ceremonies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Encointer. If not, see <http://www.gnu.org/licenses/>.

#[cfg(feature = "serde_derive")]
use serde::{Deserialize, Serialize};

use crate::communities::{CommunityIdentifier, Location};

pub use crate::scheduler::CeremonyIndexType;
use crate::scheduler::{CeremonyIndexShort, CeremonyPhaseType};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
#[cfg(feature = "serde_derive")]
use serde::{Deserialize, Serialize};
use sp_core::{Pair, RuntimeDebug};
use sp_runtime::traits::{IdentifyAccount, Verify};

pub use crate::scheduler::CeremonyIndexType;
#[cfg(not(feature = "std"))]
use sp_std::vec::Vec;

pub type ParticipantIndexType = u64;
pub type MeetupIndexType = u64;
Expand All @@ -33,16 +33,14 @@ pub type AttestationIndexType = u64;
pub type CommunityCeremony = (CommunityIdentifier, CeremonyIndexType);
pub type InactivityTimeoutType = u32;
pub type EndorsementTicketsType = u8;

/// reputation lifetime may not be longer than CeremonyIndexShort::MAX, otherwise double-using reputation is possible. therefore, we restrict the type to u8
pub type ReputationLifetimeType = u32;
pub type MeetupTimeOffsetType = i32;
pub type MeetupData<AccountId, Moment> =
(CeremonyIndexType, MeetupIndexType, Vec<AccountId>, Location, Moment);
pub type ReputationCountType = u128;

use crate::scheduler::CeremonyPhaseType;
#[cfg(not(feature = "std"))]
use sp_std::vec::Vec;

#[derive(
Default, Encode, Decode, Copy, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen,
)]
Expand All @@ -56,12 +54,16 @@ pub enum Reputation {
// verified former attendance that has not yet been linked to a new registration
VerifiedUnlinked,
// verified former attendance that has already been linked to a new registration
VerifiedLinked,
VerifiedLinked(CeremonyIndexType),
}

impl Reputation {
pub fn is_verified(self) -> bool {
self == Self::VerifiedLinked || self == Self::VerifiedUnlinked
match self {
Self::VerifiedLinked(_) => true,
Self::VerifiedUnlinked => true,
_ => false,
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions primitives/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ use serde::{Deserialize, Serialize};

pub type CeremonyIndexType = u32;

/// a very short type for ceremony index which can be wrapped in an enum variant
#[derive(Default, Encode, Decode, Copy, Clone, PartialEq, Eq, Debug, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "serde_derive", derive(Serialize, Deserialize))]
pub struct CeremonyIndexShort(u8);

impl From<CeremonyIndexType> for CeremonyIndexShort {
fn from(cindex: CeremonyIndexType) -> Self {
Self((cindex % 256) as u8)
}
}

#[derive(Default, Encode, Decode, Copy, Clone, PartialEq, Eq, Debug, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "serde_derive", derive(Serialize, Deserialize))]
pub enum CeremonyPhaseType {
Expand Down

0 comments on commit 54ffa22

Please sign in to comment.