use codec::{
Codec,
Decode,
Encode,
};
use sp_runtime::{
traits::Zero,
RuntimeDebug,
};
use sp_std::prelude::*;
#[derive(new, PartialEq, Eq, Default, Clone, Encode, Decode, RuntimeDebug)]
pub struct Organization<
AccountId,
Id: Codec + PartialEq + Zero + From<u32> + Copy,
Hash,
> {
sudo: Option<AccountId>,
parent_id: Option<Id>,
constitution: Hash,
}
impl<
AccountId: Clone + PartialEq,
Id: Codec + PartialEq + Zero + From<u32> + Copy,
Hash: Clone,
> Organization<AccountId, Id, Hash>
{
pub fn parent(&self) -> Option<Id> {
self.parent_id
}
pub fn constitution(&self) -> Hash {
self.constitution.clone()
}
pub fn is_parent(&self, cmp: Id) -> bool {
if let Some(unwrapped_parent) = self.parent_id {
unwrapped_parent == cmp
} else {
false
}
}
pub fn is_sudo(&self, cmp: &AccountId) -> bool {
if let Some(unwrapped_sudo) = &self.sudo {
unwrapped_sudo == cmp
} else {
false
}
}
pub fn clear_sudo(&self) -> Self {
Organization {
sudo: None,
parent_id: self.parent_id,
constitution: self.constitution.clone(),
}
}
pub fn put_sudo(&self, new_sudo: AccountId) -> Self {
Organization {
sudo: Some(new_sudo),
parent_id: self.parent_id,
constitution: self.constitution.clone(),
}
}
}
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
pub enum OrganizationSource<AccountId, Shares> {
Accounts(Vec<AccountId>),
AccountsWeighted(Vec<(AccountId, Shares)>),
}
impl<AccountId: PartialEq, Shares> From<Vec<(AccountId, Shares)>>
for OrganizationSource<AccountId, Shares>
{
fn from(
other: Vec<(AccountId, Shares)>,
) -> OrganizationSource<AccountId, Shares> {
OrganizationSource::AccountsWeighted(other)
}
}
impl<AccountId: PartialEq, Shares> Default
for OrganizationSource<AccountId, Shares>
{
fn default() -> OrganizationSource<AccountId, Shares> {
OrganizationSource::Accounts(Vec::new())
}
}
#[derive(new, PartialEq, Eq, Default, Clone, Encode, Decode, RuntimeDebug)]
pub struct TermsOfAgreement<AccountId, Shares, Hash> {
constitution: Hash,
supervisor: Option<AccountId>,
share_metadata: Vec<(AccountId, Shares)>,
}
impl<AccountId: Clone, Shares: Clone, Hash: Clone>
TermsOfAgreement<AccountId, Shares, Hash>
{
pub fn constitution(&self) -> Hash {
self.constitution.clone()
}
pub fn supervisor(&self) -> Option<AccountId> {
self.supervisor.clone()
}
pub fn flat(&self) -> Vec<AccountId> {
self.share_metadata
.clone()
.into_iter()
.map(|(account, _)| account)
.collect::<Vec<AccountId>>()
}
pub fn weighted(&self) -> Vec<(AccountId, Shares)> {
self.share_metadata.clone()
}
}
#[derive(PartialEq, Eq, Default, Clone, Encode, Decode, RuntimeDebug)]
pub struct FullTermsOfAgreement<AccountId, Rules, Decisions, Outcomes> {
basic_terms: Rules,
allowed_changes:
Vec<(Catalyst<AccountId>, Option<Decisions>, Option<Outcomes>)>,
}
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
pub enum Catalyst<AccountId> {
ReportBadBehavior(AccountId),
SubmitMilestone(AccountId),
RequestMilestoneAdjustment(AccountId),
SwapRole(AccountId, AccountId),
}
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
pub enum VoteConfig<AccountId, OrgId, BlockNumber> {
OneSupervisorApprovalWithFullOrgShareVetoRights(
AccountId,
OrgId,
BlockNumber,
),
TwoSupervisorsApprovalWithFullOrgShareVetoRights(
AccountId,
AccountId,
OrgId,
BlockNumber,
),
OneSupervisorApprovalWith1P1VCountThresholdVetoRights(
AccountId,
OrgId,
u32,
BlockNumber,
),
TwoSupervisorsApprovalWith1P1VCountThresholdVetoRights(
AccountId,
AccountId,
OrgId,
u32,
BlockNumber,
),
OneSupervisorApprovalWithShareWeightedVetoRights(
AccountId,
OrgId,
u32,
BlockNumber,
),
TwoSupervisorsApprovalWithShareWeightedVetoRights(
AccountId,
AccountId,
OrgId,
u32,
BlockNumber,
),
OnePersonOneVoteThresholdWithOneSupervisorVetoRights(
OrgId,
u32,
AccountId,
BlockNumber,
),
OnePersonOneVoteThresholdWithTwoSupervisorsVetoRights(
OrgId,
u32,
AccountId,
AccountId,
BlockNumber,
),
ShareWeightedVoteThresholdWithOneSupervisorVetoRights(
OrgId,
u32,
AccountId,
BlockNumber,
),
ShareWeightedVoteThresholdWithTwoSupervisorsVetoRights(
OrgId,
u32,
AccountId,
AccountId,
BlockNumber,
),
OnePersonOneVoteThresholdWithFullOrgShareVetoRights(
OrgId,
u32,
BlockNumber,
),
OnePersonOneVoteThresholdANDVetoEnabledGroup(
OrgId,
u32,
OrgId,
BlockNumber,
),
ShareWeightedVoteThresholdWithFullOrgShareVetoRights(
OrgId,
u32,
BlockNumber,
),
ShareWeightedVoteThresholdANDVetoEnabledGroup(
OrgId,
u32,
OrgId,
BlockNumber,
),
}
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
pub enum EnforcedOutcome<AccountId> {
GrantPayoutBasedOnShareDistribution(u32, u32, u32, u32),
RemoveMemberForBadBehavior(u32, u32, AccountId),
SwapRoleOnGrantTeam(u32, u32, AccountId, AccountId),
}