fix: tiki pallet - burn cleanup, remove on_initialize, scoring fixes
- burn_citizen_nft now clears UserTikis and TikiHolder entries - Removed on_initialize O(n) per-block scan (uses CitizenNftProvider hooks) - Added Peseng role score (80 points) - Removed catch-all match arm for compile-time safety on new roles - Removed duplicate cfg benchmark/non-benchmark blocks in mint
This commit is contained in:
@@ -325,14 +325,9 @@ pub mod pezpallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[pezpallet::hooks]
|
#[pezpallet::hooks]
|
||||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pezpallet<T> {
|
impl<T: Config> Hooks<BlockNumberFor<T>> for Pezpallet<T> {}
|
||||||
fn on_initialize(_block_number: BlockNumberFor<T>) -> Weight {
|
// Citizenship NFT minting is handled by CitizenNftProvider hooks,
|
||||||
// Check newly KYC-approved users and mint citizenship NFT
|
// no per-block scanning needed.
|
||||||
Self::check_and_mint_citizen_nfts();
|
|
||||||
|
|
||||||
T::DbWeight::get().reads_writes(10, 5)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[pezpallet::call]
|
#[pezpallet::call]
|
||||||
impl<T: Config> Pezpallet<T> {
|
impl<T: Config> Pezpallet<T> {
|
||||||
@@ -468,23 +463,6 @@ pub mod pezpallet {
|
|||||||
|
|
||||||
// Pezpallet's helper functions
|
// Pezpallet's helper functions
|
||||||
impl<T: Config> Pezpallet<T> {
|
impl<T: Config> Pezpallet<T> {
|
||||||
/// Checks newly KYC-completed users and mints citizenship NFT
|
|
||||||
fn check_and_mint_citizen_nfts() {
|
|
||||||
// Check all approved users in KYC pezpallet
|
|
||||||
for (account, kyc_status) in pezpallet_identity_kyc::KycStatuses::<T>::iter() {
|
|
||||||
// Check if KYC is approved
|
|
||||||
if kyc_status == pezpallet_identity_kyc::types::KycLevel::Approved {
|
|
||||||
// Check if citizenship NFT exists
|
|
||||||
if Self::citizen_nft(&account).is_none() {
|
|
||||||
// Mint NFT (log error but continue on failure)
|
|
||||||
if Self::mint_citizen_nft_for_user(&account).is_err() {
|
|
||||||
log::warn!("Failed to mint citizen NFT for account: {account:?}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Mints citizenship NFT for specific user
|
/// Mints citizenship NFT for specific user
|
||||||
pub fn mint_citizen_nft_for_user(user: &T::AccountId) -> DispatchResult {
|
pub fn mint_citizen_nft_for_user(user: &T::AccountId) -> DispatchResult {
|
||||||
// Check if NFT already exists
|
// Check if NFT already exists
|
||||||
@@ -493,17 +471,7 @@ pub mod pezpallet {
|
|||||||
let collection_id = T::TikiCollectionId::get();
|
let collection_id = T::TikiCollectionId::get();
|
||||||
let next_id_u32 = Self::next_item_id();
|
let next_id_u32 = Self::next_item_id();
|
||||||
|
|
||||||
// Mint the NFT - use force_mint in benchmarks to bypass balance/origin requirements
|
// Mint the NFT via force_mint (root origin, no deposit needed)
|
||||||
#[cfg(feature = "runtime-benchmarks")]
|
|
||||||
pezpallet_nfts::Pezpallet::<T>::force_mint(
|
|
||||||
T::RuntimeOrigin::from(pezframe_system::RawOrigin::Root),
|
|
||||||
collection_id,
|
|
||||||
next_id_u32,
|
|
||||||
T::Lookup::unlookup(user.clone()),
|
|
||||||
Default::default(),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
#[cfg(not(feature = "runtime-benchmarks"))]
|
|
||||||
pezpallet_nfts::Pezpallet::<T>::force_mint(
|
pezpallet_nfts::Pezpallet::<T>::force_mint(
|
||||||
T::RuntimeOrigin::from(pezframe_system::RawOrigin::Root),
|
T::RuntimeOrigin::from(pezframe_system::RawOrigin::Root),
|
||||||
collection_id,
|
collection_id,
|
||||||
@@ -825,12 +793,11 @@ impl<T: Config> Pezpallet<T> {
|
|||||||
Tiki::Qeydkar => 25,
|
Tiki::Qeydkar => 25,
|
||||||
Tiki::ParêzvaneÇandî => 25,
|
Tiki::ParêzvaneÇandî => 25,
|
||||||
Tiki::Sêwirmend => 20,
|
Tiki::Sêwirmend => 20,
|
||||||
Tiki::Bazargan => 60, // Yeni eklenen ekonomik rol
|
Tiki::Bazargan => 60,
|
||||||
|
Tiki::Pêseng => 80,
|
||||||
|
|
||||||
// Temel Vatandaşlık ve Diğerleri
|
// Temel Vatandaşlık
|
||||||
Tiki::Welati => 10,
|
Tiki::Welati => 10,
|
||||||
// Yukarıdaki listede olmayan diğer tüm roller 5 puan alır.
|
|
||||||
_ => 5,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -858,7 +825,16 @@ impl<T: Config> pezpallet_identity_kyc::types::CitizenNftProvider<T::AccountId>
|
|||||||
item_id,
|
item_id,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Remove from our storage
|
// Clear unique role mappings before removing roles
|
||||||
|
let user_tikis = UserTikis::<T>::get(who);
|
||||||
|
for tiki in user_tikis.iter() {
|
||||||
|
if Self::is_unique_role(tiki) {
|
||||||
|
TikiHolder::<T>::remove(tiki);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove all roles and citizen NFT mapping
|
||||||
|
UserTikis::<T>::remove(who);
|
||||||
CitizenNft::<T>::remove(who);
|
CitizenNft::<T>::remove(who);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -204,6 +204,13 @@ impl pezpallet_identity_kyc::types::CitizenNftProvider<AccountId> for MockCitize
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct DefaultReferrerAccount;
|
||||||
|
impl pezframe_support::traits::Get<AccountId> for DefaultReferrerAccount {
|
||||||
|
fn get() -> AccountId {
|
||||||
|
100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl pezpallet_identity_kyc::Config for Test {
|
impl pezpallet_identity_kyc::Config for Test {
|
||||||
type Currency = Balances;
|
type Currency = Balances;
|
||||||
type WeightInfo = ();
|
type WeightInfo = ();
|
||||||
@@ -214,6 +221,7 @@ impl pezpallet_identity_kyc::Config for Test {
|
|||||||
type OnKycApproved = MockOnKycApproved;
|
type OnKycApproved = MockOnKycApproved;
|
||||||
type OnCitizenshipRevoked = MockOnCitizenshipRevoked;
|
type OnCitizenshipRevoked = MockOnCitizenshipRevoked;
|
||||||
type CitizenNftProvider = MockCitizenNftProvider;
|
type CitizenNftProvider = MockCitizenNftProvider;
|
||||||
|
type DefaultReferrer = DefaultReferrerAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
parameter_types! {
|
parameter_types! {
|
||||||
|
|||||||
@@ -373,8 +373,7 @@ fn scoring_system_comprehensive() {
|
|||||||
assert_eq!(TikiPallet::get_bonus_for_tiki(&TikiEnum::Feqî), 50);
|
assert_eq!(TikiPallet::get_bonus_for_tiki(&TikiEnum::Feqî), 50);
|
||||||
assert_eq!(TikiPallet::get_bonus_for_tiki(&TikiEnum::Welati), 10);
|
assert_eq!(TikiPallet::get_bonus_for_tiki(&TikiEnum::Welati), 10);
|
||||||
|
|
||||||
// Test default score for unspecified roles
|
assert_eq!(TikiPallet::get_bonus_for_tiki(&TikiEnum::Pêseng), 80);
|
||||||
assert_eq!(TikiPallet::get_bonus_for_tiki(&TikiEnum::Pêseng), 5);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user