diff --git a/pallets/identity/src/lib.rs b/pallets/identity/src/lib.rs index 71edc84561eb453ff307017c84f0be7275ee435a..a2684bbf101cb855021452eada3d1fa64ee5ec07 100644 --- a/pallets/identity/src/lib.rs +++ b/pallets/identity/src/lib.rs @@ -30,10 +30,13 @@ mod benchmarking;*/ pub use pallet::*; use crate::traits::*; +use codec::Codec; use frame_support::dispatch::Weight; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; +use sp_runtime::traits::{AtLeast32BitUnsigned, One, Saturating, Zero}; use sp_std::collections::btree_map::BTreeMap; +use sp_std::fmt::Debug; use sp_std::prelude::*; #[frame_support::pallet] @@ -60,6 +63,16 @@ pub mod pallet { type IdtyData: IdtyData; /// Identity decentralized identifier type IdtyDid: IdtyDid; + /// A short identity index. + type IdtyIndex: Parameter + + Member + + AtLeast32BitUnsigned + + Codec + + Default + + Copy + + MaybeSerializeDeserialize + + Debug + + MaxEncodedLen; /// Origin allowed to validate identity type IdtyValidationOrigin: EnsureOrigin<Self::Origin>; /// Rights that an identity can have @@ -115,6 +128,7 @@ pub mod pallet { #[cfg_attr(feature = "std", derive(Deserialize, Serialize))] #[derive(Encode, Decode, Clone, PartialEq, Eq)] pub struct IdtyValue<T: Config> { + pub index: T::IdtyIndex, pub owner_key: T::AccountId, pub removable_on: Option<T::BlockNumber>, pub rights: Vec<(T::IdtyRight, Option<T::AccountId>)>, @@ -124,6 +138,7 @@ pub mod pallet { impl<T: Config> IdtyValue<T> { pub fn new_valid(owner_key: T::AccountId, rights: Vec<T::IdtyRight>) -> Self { Self { + index: Default::default(), owner_key, removable_on: None, rights: rights.into_iter().map(|right| (right, None)).collect(), @@ -135,6 +150,7 @@ pub mod pallet { impl<T: Config> Default for IdtyValue<T> { fn default() -> Self { Self { + index: Default::default(), owner_key: Default::default(), removable_on: None, rights: Default::default(), @@ -172,6 +188,15 @@ pub mod pallet { pub type Identities<T: Config> = StorageMap<_, Blake2_128Concat, T::IdtyDid, IdtyValue<T>, ValueQuery>; + /// IdentitiesByIndex + #[pallet::storage] + #[pallet::getter(fn identity_did_of_index)] + pub type IdentitiesByIndex<T: Config> = + StorageMap<_, Blake2_128Concat, T::IdtyIndex, T::IdtyDid, ValueQuery>; + + #[pallet::storage] + pub(super) type NextIdtyIndex<T: Config> = StorageValue<_, T::IdtyIndex, ValueQuery>; + #[pallet::storage] #[pallet::getter(fn identities_count)] pub(super) type IdentitiesCount<T: Config> = StorageValue<_, u64, ValueQuery>; @@ -298,14 +323,17 @@ pub mod pallet { let block_number = frame_system::pallet::Pallet::<T>::block_number(); let removable_on = block_number + T::ConfirmPeriod::get(); + let idty_index = Self::get_next_idty_index(); <Identities<T>>::insert( idty_did, IdtyValue { + index: idty_index, owner_key: owner_key.clone(), removable_on: Some(removable_on), ..Default::default() }, ); + <IdentitiesByIndex<T>>::insert(idty_index, idty_did); IdentitiesRemovableOn::<T>::append(removable_on, (idty_did, IdtyStatus::Created)); Self::inc_identities_counter(); Self::deposit_event(Event::IdtyCreated(idty_did, owner_key)); @@ -591,6 +619,15 @@ pub mod pallet { } else { panic!("storage corrupted") } + } //NextIdtyIndex + fn get_next_idty_index() -> T::IdtyIndex { + if let Ok(next_index) = <NextIdtyIndex<T>>::try_get() { + <NextIdtyIndex<T>>::put(next_index.saturating_add(T::IdtyIndex::one())); + next_index + } else { + <NextIdtyIndex<T>>::put(T::IdtyIndex::one()); + T::IdtyIndex::zero() + } } fn inc_identities_counter() { if let Ok(counter) = <IdentitiesCount<T>>::try_get() { diff --git a/pallets/identity/src/mock.rs b/pallets/identity/src/mock.rs index 03ca27fd448eaabe1671d533df0f27ab1c0c7db0..c8973aaad3dda9388f69f140ddcd050868ea0f3f 100644 --- a/pallets/identity/src/mock.rs +++ b/pallets/identity/src/mock.rs @@ -113,6 +113,7 @@ impl pallet_identity::Config for Test { type EnsureIdtyCallAllowed = (); type IdtyData = (); type IdtyDid = IdtyDid; + type IdtyIndex = u64; type IdtyValidationOrigin = system::EnsureRoot<AccountId>; type IdtyRight = IdtyRight; type OnIdtyConfirmed = (); diff --git a/pallets/identity/src/tests.rs b/pallets/identity/src/tests.rs index f6cdf389d105a3819fc221672d47cc95e6493547..ba6f183d0cad074c1d63f40e22ab0942e5a0452b 100644 --- a/pallets/identity/src/tests.rs +++ b/pallets/identity/src/tests.rs @@ -37,19 +37,23 @@ fn test_two_identities() { identities.insert( Did(1), crate::IdtyValue { + index: 0, owner_key: 1, removable_on: None, rights: vec![(Right::Right2, Some(10))], status: crate::IdtyStatus::Validated, + data: (), }, ); identities.insert( Did(2), crate::IdtyValue { + index: 1, owner_key: 2, removable_on: None, rights: vec![(Right::Right1, Some(20))], status: crate::IdtyStatus::Validated, + data: (), }, ); new_test_ext(IdentityConfig { identities }).execute_with(|| { diff --git a/pallets/strong-certs/Cargo.toml b/pallets/strong-certs/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..507fe8d40c5d7742b9ef131943952390c0b56d0d --- /dev/null +++ b/pallets/strong-certs/Cargo.toml @@ -0,0 +1,81 @@ +[package] +authors = ['librelois <c@elo.tf>'] +description = 'FRAME pallet strong certifications.' +edition = '2018' +homepage = 'https://substrate.dev' +license = 'AGPL-3.0' +name = 'pallet-strong-certs' +readme = 'README.md' +repository = 'https://git.duniter.org/nodes/rust/lc-core-substrate' +version = '3.0.0' + +[features] +default = ['std'] +runtime-benchmarks = ['frame-benchmarking'] +std = [ + 'codec/std', + 'frame-support/std', + 'frame-system/std', + 'frame-benchmarking/std', + 'serde', + 'sp-core/std', + 'sp-runtime/std', + 'sp-std/std', +] +try-runtime = ['frame-support/try-runtime'] + +[dependencies.codec] +default-features = false +features = ['derive'] +package = 'parity-scale-codec' +version = '2.1.0' + +[dependencies.frame-benchmarking] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +optional = true +tag = 'monthly-2021-07' + +[dependencies.frame-support] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-07' + +[dependencies.frame-system] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-07' + +[dependencies.serde] +version = "1.0.101" +optional = true +features = ["derive"] + +[dependencies.sp-core] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-07' + +[dependencies.sp-runtime] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-07' + +[dependencies.sp-std] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-07' + +### DOC ### + +[package.metadata.docs.rs] +targets = ['x86_64-unknown-linux-gnu'] +[dev-dependencies.serde] +version = '1.0.119' + +### DEV ### + +[dev-dependencies.sp-io] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-07' diff --git a/pallets/strong-certs/src/lib.rs b/pallets/strong-certs/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/pallets/universal-dividend/src/mock.rs b/pallets/universal-dividend/src/mock.rs index 0ae4a9605a5acaedf697370d647dc4167fdb8442..2866933acf8927f21b0b792b2261754e2bc89616 100644 --- a/pallets/universal-dividend/src/mock.rs +++ b/pallets/universal-dividend/src/mock.rs @@ -41,7 +41,7 @@ frame_support::construct_runtime!( { System: frame_system::{Pallet, Call, Config, Storage, Event<T>}, Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>}, - UniversalDividend: pallet_universal_dividend::{Pallet, Call, Storage, Config<T>, Event<T>}, + UniversalDividend: pallet_universal_dividend::{Pallet, Storage, Config<T>, Event<T>}, } ); diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 84cf9617737f3800bc572bb438cf2218d7761738..2e3423d19f9e4ed8edfd53969ceb11e4827334cf 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -82,6 +82,9 @@ pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::Account /// Balance of an account. pub type Balance = u64; +/// Index of an identity +pub type IdtyIndex = u64; + /// Index of a transaction in the chain. pub type Index = u32; @@ -331,6 +334,7 @@ impl pallet_identity::Config for Runtime { type EnsureIdtyCallAllowed = crate::authorizations::EnsureIdtyCallAllowedImpl; type IdtyData = (); type IdtyDid = IdtyDid; + type IdtyIndex = IdtyIndex; type IdtyValidationOrigin = EnsureRoot<Self::AccountId>; type IdtyRight = IdtyRight; type OnIdtyConfirmed = ();