-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add omni_account to primitives * fix ci
- Loading branch information
1 parent
b656376
commit 2dbaa33
Showing
25 changed files
with
326 additions
and
514 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2020-2024 Trust Computing GmbH. | ||
// This file is part of Litentry. | ||
// | ||
// Litentry is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Litentry is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Litentry. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
use crate::{AccountId, Hash, Identity, Vec}; | ||
use parity_scale_codec::{Decode, Encode}; | ||
use scale_info::TypeInfo; | ||
use sp_io::hashing::blake2_256; | ||
use sp_runtime::{BoundedVec, RuntimeDebug}; | ||
|
||
#[derive(Encode, Decode, TypeInfo, Clone, PartialEq, Eq, RuntimeDebug)] | ||
pub enum MemberAccount { | ||
Public(Identity), | ||
Private(Vec<u8>, Hash), | ||
} | ||
|
||
impl MemberAccount { | ||
pub fn is_public(&self) -> bool { | ||
matches!(self, Self::Public(..)) | ||
} | ||
|
||
pub fn hash(&self) -> Hash { | ||
match self { | ||
Self::Public(id) => id.hash(), | ||
Self::Private(_, h) => *h, | ||
} | ||
} | ||
} | ||
|
||
impl From<Identity> for MemberAccount { | ||
fn from(identity: Identity) -> Self { | ||
Self::Public(identity) | ||
} | ||
} | ||
|
||
pub trait GetAccountStoreHash { | ||
fn hash(&self) -> Hash; | ||
} | ||
|
||
pub trait OmniAccountConverter { | ||
type OmniAccount; | ||
fn convert(identity: &Identity) -> Self::OmniAccount; | ||
} | ||
|
||
pub struct DefaultOmniAccountConverter; | ||
|
||
impl OmniAccountConverter for DefaultOmniAccountConverter { | ||
type OmniAccount = AccountId; | ||
fn convert(identity: &Identity) -> AccountId { | ||
identity.to_omni_account() | ||
} | ||
} | ||
|
||
impl<T> GetAccountStoreHash for BoundedVec<MemberAccount, T> { | ||
fn hash(&self) -> Hash { | ||
let hashes: Vec<Hash> = self.iter().map(|member| member.hash()).collect(); | ||
hashes.using_encoded(blake2_256).into() | ||
} | ||
} | ||
|
||
impl GetAccountStoreHash for Vec<MemberAccount> { | ||
fn hash(&self) -> Hash { | ||
let hashes: Vec<Hash> = self.iter().map(|member| member.hash()).collect(); | ||
hashes.using_encoded(blake2_256).into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.