Skip to content

Commit

Permalink
add to kyc accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Nov 30, 2024
1 parent 1630fd8 commit 7d32c9a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions custom-pallets/profile-validation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
31 changes: 27 additions & 4 deletions custom-pallets/profile-validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
/// </pre>
/// #[pallet::weight(<T as pallet::Config>::WeightInfo::add_citizen())]
#[pallet::call_index(0)]
#[pallet::weight(0)]
pub fn add_citizen(origin: OriginFor<T>, content: Content) -> DispatchResult {
Expand Down Expand Up @@ -882,9 +882,6 @@ pub mod pallet {
who.clone(),
profile_fund_info,
);
T::SharedStorageSource::add_approved_citizen_address(
profile_user_account,
)?;
} else {
Err(Error::<T>::ProfileFundAlreadyReturned)?;
}
Expand All @@ -897,5 +894,31 @@ pub mod pallet {

Ok(())
}

#[pallet::call_index(13)]
#[pallet::weight(0)]
pub fn add_to_kyc_accounts(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
let block_number = <ValidationBlock<T>>::get(&who);
let key = SumTreeName::ProfileValidation { citizen_address: who.clone(), block_number };
let now = <frame_system::Pallet<T>>::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(())
}
}
}
9 changes: 9 additions & 0 deletions custom-pallets/profile-validation/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -145,5 +151,8 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
} // new code
.assimilate_storage(&mut t)
.unwrap();
pallet_shared_storage::GenesisConfig::<Test> { approved_citizen_address: vec![] }
.assimilate_storage(&mut t)
.unwrap();
t.into()
}

0 comments on commit 7d32c9a

Please sign in to comment.