use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::DispatchError;
use sp_weights::Weight;
use attestation::AttestationAccessControl;
use public_credentials::PublicCredentialsAccessControl;
#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
pub enum AuthorizationId<DelegationId> {
Delegation(DelegationId),
}
#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
pub enum PalletAuthorize<DelegationAc> {
Delegation(DelegationAc),
}
impl<AttesterId, DelegationAc, DelegationId, Ctype, ClaimHash>
AttestationAccessControl<AttesterId, AuthorizationId<DelegationId>, Ctype, ClaimHash> for PalletAuthorize<DelegationAc>
where
DelegationAc: AttestationAccessControl<AttesterId, DelegationId, Ctype, ClaimHash>,
{
fn can_attest(&self, who: &AttesterId, ctype: &Ctype, claim: &ClaimHash) -> Result<Weight, DispatchError> {
let PalletAuthorize::Delegation(ac) = self;
ac.can_attest(who, ctype, claim)
}
fn can_revoke(
&self,
who: &AttesterId,
ctype: &Ctype,
claim: &ClaimHash,
auth_id: &AuthorizationId<DelegationId>,
) -> Result<Weight, DispatchError> {
let (PalletAuthorize::Delegation(ac), AuthorizationId::Delegation(auth_id)) = (self, auth_id);
ac.can_revoke(who, ctype, claim, auth_id)
}
fn can_remove(
&self,
who: &AttesterId,
ctype: &Ctype,
claim: &ClaimHash,
auth_id: &AuthorizationId<DelegationId>,
) -> Result<Weight, DispatchError> {
let (PalletAuthorize::Delegation(ac), AuthorizationId::Delegation(auth_id)) = (self, auth_id);
ac.can_remove(who, ctype, claim, auth_id)
}
fn authorization_id(&self) -> AuthorizationId<DelegationId> {
let PalletAuthorize::Delegation(ac) = self;
AuthorizationId::Delegation(ac.authorization_id())
}
fn can_attest_weight(&self) -> Weight {
let PalletAuthorize::Delegation(ac) = self;
ac.can_attest_weight()
}
fn can_revoke_weight(&self) -> Weight {
let PalletAuthorize::Delegation(ac) = self;
ac.can_revoke_weight()
}
fn can_remove_weight(&self) -> Weight {
let PalletAuthorize::Delegation(ac) = self;
ac.can_remove_weight()
}
}
impl<AttesterId, DelegationAc, DelegationId, Ctype, CredentialId>
PublicCredentialsAccessControl<AttesterId, AuthorizationId<DelegationId>, Ctype, CredentialId>
for PalletAuthorize<DelegationAc>
where
DelegationAc: PublicCredentialsAccessControl<AttesterId, DelegationId, Ctype, CredentialId>,
{
fn can_issue(
&self,
who: &AttesterId,
ctype: &Ctype,
credential_id: &CredentialId,
) -> Result<Weight, DispatchError> {
let PalletAuthorize::Delegation(ac) = self;
ac.can_issue(who, ctype, credential_id)
}
fn can_revoke(
&self,
who: &AttesterId,
ctype: &Ctype,
credential_id: &CredentialId,
auth_id: &AuthorizationId<DelegationId>,
) -> Result<Weight, DispatchError> {
let (PalletAuthorize::Delegation(ac), AuthorizationId::Delegation(auth_id)) = (self, auth_id);
ac.can_revoke(who, ctype, credential_id, auth_id)
}
fn can_unrevoke(
&self,
who: &AttesterId,
ctype: &Ctype,
credential_id: &CredentialId,
auth_id: &AuthorizationId<DelegationId>,
) -> Result<Weight, DispatchError> {
let (PalletAuthorize::Delegation(ac), AuthorizationId::Delegation(auth_id)) = (self, auth_id);
ac.can_unrevoke(who, ctype, credential_id, auth_id)
}
fn can_remove(
&self,
who: &AttesterId,
ctype: &Ctype,
credential_id: &CredentialId,
auth_id: &AuthorizationId<DelegationId>,
) -> Result<Weight, DispatchError> {
let (PalletAuthorize::Delegation(ac), AuthorizationId::Delegation(auth_id)) = (self, auth_id);
ac.can_remove(who, ctype, credential_id, auth_id)
}
fn authorization_id(&self) -> AuthorizationId<DelegationId> {
let PalletAuthorize::Delegation(ac) = self;
AuthorizationId::Delegation(ac.authorization_id())
}
fn can_issue_weight(&self) -> Weight {
let PalletAuthorize::Delegation(ac) = self;
ac.can_issue_weight()
}
fn can_revoke_weight(&self) -> Weight {
let PalletAuthorize::Delegation(ac) = self;
ac.can_revoke_weight()
}
fn can_unrevoke_weight(&self) -> Weight {
let PalletAuthorize::Delegation(ac) = self;
ac.can_unrevoke_weight()
}
fn can_remove_weight(&self) -> Weight {
let PalletAuthorize::Delegation(ac) = self;
ac.can_remove_weight()
}
}