diff --git a/custom-pallets/profile-validation/Cargo.toml b/custom-pallets/profile-validation/Cargo.toml index a50cd9a..63b3581 100644 --- a/custom-pallets/profile-validation/Cargo.toml +++ b/custom-pallets/profile-validation/Cargo.toml @@ -50,6 +50,7 @@ std = [ "pallet-support/std", "pallet-schelling-game-shared/std", "pallet-sortition-sum-game/std", + "pallet-shared-storage/std", "frame-support-test/std", ] runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/custom-pallets/profile-validation/src/lib.rs b/custom-pallets/profile-validation/src/lib.rs index a83b9b4..6265f60 100644 --- a/custom-pallets/profile-validation/src/lib.rs +++ b/custom-pallets/profile-validation/src/lib.rs @@ -265,7 +265,7 @@ pub mod pallet { /// If CitizenId exists update the content, only if `ProfileTotalFundCollected` is zero /// If CitizenId doesn't exists insert the content, and increment the `NextCitizenId` /// - /// #[pallet::weight(::WeightInfo::add_citizen())] + #[pallet::call_index(0)] #[pallet::weight(0)] pub fn add_citizen(origin: OriginFor, content: Content) -> DispatchResult { @@ -882,9 +882,6 @@ pub mod pallet { who.clone(), profile_fund_info, ); - T::SharedStorageSource::add_approved_citizen_address( - profile_user_account, - )?; } else { Err(Error::::ProfileFundAlreadyReturned)?; } @@ -897,5 +894,31 @@ pub mod pallet { Ok(()) } + + #[pallet::call_index(13)] + #[pallet::weight(0)] + pub fn add_to_kyc_accounts(origin: OriginFor) -> DispatchResult { + let who = ensure_signed(origin)?; + let block_number = >::get(&who); + let key = SumTreeName::ProfileValidation { citizen_address: who.clone(), block_number }; + let now = >::block_number(); + let phase_data = Self::get_phase_data(); + + let period = T::SchellingGameSharedSource::get_period_link(key.clone()).unwrap(); + + if period == Period::Execution { + let decision: WinningDecision = + T::SchellingGameSharedSource::get_winning_decision_value(key.clone())?; + if decision == WinningDecision::WinnerNo { + T::SharedStorageSource::add_approved_citizen_address(who.clone())?; + } + } else if period == Period::Evidence { + T::SchellingGameSharedSource::ensure_time_for_staking_over_link( + key, phase_data, now, + )?; + T::SharedStorageSource::add_approved_citizen_address(who.clone())?; + } + Ok(()) + } } } diff --git a/custom-pallets/profile-validation/src/mock.rs b/custom-pallets/profile-validation/src/mock.rs index b445ec0..73f6ac3 100644 --- a/custom-pallets/profile-validation/src/mock.rs +++ b/custom-pallets/profile-validation/src/mock.rs @@ -22,6 +22,7 @@ frame_support::construct_runtime!( Timestamp: pallet_timestamp, SchellingGameShared: pallet_schelling_game_shared, SortitionSumGame: pallet_sortition_sum_game, + SharedStorage: pallet_shared_storage, } ); @@ -84,10 +85,15 @@ impl pallet_template::Config for Test { type WeightInfo = (); type Currency = Balances; // New code type SchellingGameSharedSource = SchellingGameShared; + type SharedStorageSource = SharedStorage; type Slash = (); type Reward = (); } +impl pallet_shared_storage::Config for Test { + type RuntimeEvent = RuntimeEvent; +} + impl pallet_schelling_game_shared::Config for Test { type RuntimeEvent = RuntimeEvent; type Currency = Balances; // New code @@ -145,5 +151,8 @@ pub fn new_test_ext() -> sp_io::TestExternalities { } // new code .assimilate_storage(&mut t) .unwrap(); + pallet_shared_storage::GenesisConfig:: { approved_citizen_address: vec![] } + .assimilate_storage(&mut t) + .unwrap(); t.into() }