diff --git a/node/src/chain_spec/gdev.rs b/node/src/chain_spec/gdev.rs index 5365ec715c48880e6055fc17f4c0bf8b0d3da880..fcf508ce93c6dee00b66d738ae7954206942ea79 100644 --- a/node/src/chain_spec/gdev.rs +++ b/node/src/chain_spec/gdev.rs @@ -310,10 +310,10 @@ fn gen_genesis_conf( .enumerate() .map(|(i, (name, owner_key))| GenesisIdty { index: i as u32 + 1, - owner_key: owner_key.clone(), name: name.clone(), value: IdtyValue { next_creatable_identity_on: Default::default(), + owner_key: owner_key.clone(), removable_on: 0, status: IdtyStatus::Validated, }, @@ -440,10 +440,10 @@ fn genesis_data_to_gdev_genesis_conf( .enumerate() .map(|(i, (name, pubkey))| common_runtime::GenesisIdty { index: i as u32 + 1, - owner_key: pubkey, name: common_runtime::IdtyName::from(name.as_str()), value: common_runtime::IdtyValue { next_creatable_identity_on: 0, + owner_key: pubkey, removable_on: 0, status: IdtyStatus::Validated, }, diff --git a/pallets/duniter-wot/src/mock.rs b/pallets/duniter-wot/src/mock.rs index e0683621f9709ceac619c119849d5ea2377c1081..08dc319fbf51b7aaa2412c0e8a4ffac4ae773770 100644 --- a/pallets/duniter-wot/src/mock.rs +++ b/pallets/duniter-wot/src/mock.rs @@ -178,10 +178,10 @@ pub fn new_test_ext(initial_identities_len: usize) -> sp_io::TestExternalities { identities: (1..=initial_identities_len) .map(|i| pallet_identity::GenesisIdty { index: i as u32, - owner_key: i as u64, name: pallet_identity::IdtyName::from(NAMES[i - 1]), value: pallet_identity::IdtyValue { next_creatable_identity_on: 0, + owner_key: i as u64, removable_on: 0, status: pallet_identity::IdtyStatus::Validated, }, diff --git a/pallets/duniter-wot/src/tests.rs b/pallets/duniter-wot/src/tests.rs index 9d5b2618152322833947c63e4cabac6623ab2a49..910991c656a19f181f186c2d0ffd31c12c29ec46 100644 --- a/pallets/duniter-wot/src/tests.rs +++ b/pallets/duniter-wot/src/tests.rs @@ -60,17 +60,25 @@ fn test_create_idty_ok() { assert_ok!(Identity::create_identity(Origin::signed(1), 6)); // 2 events should have occurred: IdtyCreated and NewCert let events = System::events(); - assert_eq!(events.len(), 2); + assert_eq!(events.len(), 3); assert_eq!( events[0], EventRecord { phase: Phase::Initialization, - event: Event::Identity(pallet_identity::Event::IdtyCreated(6, 6)), + event: Event::System(frame_system::Event::NewAccount { account: 6 }), topics: vec![], } ); assert_eq!( events[1], + EventRecord { + phase: Phase::Initialization, + event: Event::Identity(pallet_identity::Event::IdtyCreated(6, 6)), + topics: vec![], + } + ); + assert_eq!( + events[2], EventRecord { phase: Phase::Initialization, event: Event::Cert(pallet_certification::Event::NewCert { diff --git a/pallets/identity/src/lib.rs b/pallets/identity/src/lib.rs index 50d70f1dc2e5aa28c43245c292dab17fb8451c14..c35f8f4acc77dc1e2b91473b0271a052990460e6 100644 --- a/pallets/identity/src/lib.rs +++ b/pallets/identity/src/lib.rs @@ -98,9 +98,8 @@ pub mod pallet { #[derive(Encode, Decode, Clone, PartialEq, Eq)] pub struct GenesisIdty<T: Config> { pub index: T::IdtyIndex, - pub owner_key: T::AccountId, pub name: IdtyName, - pub value: IdtyValue<T::BlockNumber>, + pub value: IdtyValue<T::BlockNumber, T::AccountId>, } #[pallet::genesis_config] @@ -144,7 +143,7 @@ pub mod pallet { } <Identities<T>>::insert(idty_index, idty.value.clone()); IdentitiesNames::<T>::insert(idty.name.clone(), ()); - IdentityIndexOf::<T>::insert(idty.owner_key, idty_index); + IdentityIndexOf::<T>::insert(idty.value.owner_key, idty_index); } } } @@ -153,8 +152,13 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn identity)] - pub type Identities<T: Config> = - CountedStorageMap<_, Twox64Concat, T::IdtyIndex, IdtyValue<T::BlockNumber>, OptionQuery>; + pub type Identities<T: Config> = CountedStorageMap< + _, + Twox64Concat, + T::IdtyIndex, + IdtyValue<T::BlockNumber, T::AccountId>, + OptionQuery, + >; #[pallet::storage] #[pallet::getter(fn identity_index_of)] @@ -240,7 +244,7 @@ pub mod pallet { } // Apply phase // - + frame_system::Pallet::<T>::inc_sufficients(&owner_key); <Identities<T>>::mutate_exists(creator, |idty_val_opt| { if let Some(ref mut idty_val) = idty_val_opt { idty_val.next_creatable_identity_on = @@ -255,6 +259,7 @@ pub mod pallet { idty_index, IdtyValue { next_creatable_identity_on: T::BlockNumber::zero(), + owner_key: owner_key.clone(), removable_on, status: IdtyStatus::Created, }, @@ -440,9 +445,10 @@ pub mod pallet { impl<T: Config> Pallet<T> { pub(super) fn do_remove_identity(idty_index: T::IdtyIndex) -> Weight { - <Identities<T>>::remove(idty_index); + if let Some(idty_val) = Identities::<T>::take(idty_index) { + frame_system::Pallet::<T>::dec_sufficients(&idty_val.owner_key); + } T::OnIdtyChange::on_idty_change(idty_index, IdtyEvent::Removed); - 0 } fn get_next_idty_index() -> T::IdtyIndex { diff --git a/pallets/identity/src/tests.rs b/pallets/identity/src/tests.rs index b63345b56aadcb7f24f4d19ec8092c7ed6bb5e5f..5397d74ee23349b31e60f56cba4284d77927f53b 100644 --- a/pallets/identity/src/tests.rs +++ b/pallets/identity/src/tests.rs @@ -20,15 +20,15 @@ use crate::{Error, GenesisIdty, IdtyName, IdtyValue}; use frame_support::assert_ok; use frame_system::{EventRecord, Phase}; -type IdtyVal = IdtyValue<u64>; +type IdtyVal = IdtyValue<u64, u64>; fn alice() -> GenesisIdty<Test> { GenesisIdty { index: 1, - owner_key: 1, name: IdtyName::from("Alice"), value: IdtyVal { next_creatable_identity_on: 0, + owner_key: 1, removable_on: 0, status: crate::IdtyStatus::Validated, }, diff --git a/pallets/identity/src/types.rs b/pallets/identity/src/types.rs index ecae172f7317deffcb9f5c0dcf74ca4edc410aa5..629a81ce65b06581c6ed8d62b3618642d6d1e7eb 100644 --- a/pallets/identity/src/types.rs +++ b/pallets/identity/src/types.rs @@ -79,8 +79,9 @@ impl Default for IdtyStatus { #[cfg_attr(feature = "std", derive(Deserialize, Serialize))] #[derive(Encode, Decode, Clone, PartialEq, Eq, TypeInfo)] -pub struct IdtyValue<BlockNumber: Decode + Encode + TypeInfo> { +pub struct IdtyValue<BlockNumber, AccountId> { pub next_creatable_identity_on: BlockNumber, + pub owner_key: AccountId, pub removable_on: BlockNumber, pub status: IdtyStatus, }