From 1f18c5bc9b3bb634847b4ee2a695e5cc37dc9b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Eng=C3=A9libert?= <tuxmain@zettascript.org> Date: Fri, 10 Jan 2025 15:38:15 +0100 Subject: [PATCH] Fix UD eligibility at genesis --- node/src/chain_spec/g1.rs | 7 ++++++- node/src/chain_spec/gdev.rs | 7 ++++++- node/src/chain_spec/gtest.rs | 7 ++++++- pallets/universal-dividend/src/types.rs | 10 +++++++++- runtime/common/src/entities.rs | 9 --------- runtime/gdev/tests/common/mod.rs | 4 +++- 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/node/src/chain_spec/g1.rs b/node/src/chain_spec/g1.rs index 8ad20d230..5cfc42125 100644 --- a/node/src/chain_spec/g1.rs +++ b/node/src/chain_spec/g1.rs @@ -198,7 +198,12 @@ fn genesis_data_to_g1_genesis_conf( index: idty_index, name: common_runtime::IdtyName::from(name.as_str()), value: common_runtime::IdtyValue { - data: IdtyData::new(), + data: IdtyData { + first_eligible_ud: match status { + common_runtime::IdtyStatus::Member => 1_u16.into(), + _ => g1_runtime::pallet_universal_dividend::FirstEligibleUd(None), + } + }, next_creatable_identity_on: 0, old_owner_key: None, owner_key, diff --git a/node/src/chain_spec/gdev.rs b/node/src/chain_spec/gdev.rs index c78154891..36c906c11 100644 --- a/node/src/chain_spec/gdev.rs +++ b/node/src/chain_spec/gdev.rs @@ -286,7 +286,12 @@ fn genesis_data_to_gdev_genesis_conf( index: idty_index, name: common_runtime::IdtyName::from(name.as_str()), value: common_runtime::IdtyValue { - data: IdtyData::new(), + data: IdtyData { + first_eligible_ud: match status { + common_runtime::IdtyStatus::Member => 1_u16.into(), + _ => gdev_runtime::pallet_universal_dividend::FirstEligibleUd(None), + } + }, next_creatable_identity_on: 0, old_owner_key: None, owner_key, diff --git a/node/src/chain_spec/gtest.rs b/node/src/chain_spec/gtest.rs index 2b4020664..80a5705fb 100644 --- a/node/src/chain_spec/gtest.rs +++ b/node/src/chain_spec/gtest.rs @@ -291,7 +291,12 @@ fn genesis_data_to_gtest_genesis_conf( index: idty_index, name: common_runtime::IdtyName::from(name.as_str()), value: common_runtime::IdtyValue { - data: IdtyData::new(), + data: IdtyData { + first_eligible_ud: match status { + common_runtime::IdtyStatus::Member => 1_u16.into(), + _ => gtest_runtime::pallet_universal_dividend::FirstEligibleUd(None), + } + }, next_creatable_identity_on: 0, old_owner_key: None, owner_key, diff --git a/pallets/universal-dividend/src/types.rs b/pallets/universal-dividend/src/types.rs index 12fb017cf..b5b5907e6 100644 --- a/pallets/universal-dividend/src/types.rs +++ b/pallets/universal-dividend/src/types.rs @@ -22,10 +22,18 @@ use sp_runtime::RuntimeDebug; pub type UdIndex = u16; /// Represents the first eligible Universal Dividend. -#[derive(Clone, Default, Eq, PartialEq, RuntimeDebug, serde::Deserialize, serde::Serialize)] +#[derive(Clone, Eq, PartialEq, RuntimeDebug, serde::Deserialize, serde::Serialize)] pub struct FirstEligibleUd(pub Option<NonZeroU16>); +/// Default is not eligible +impl Default for FirstEligibleUd { + fn default() -> Self { + FirstEligibleUd(None) + } +} + impl FirstEligibleUd { + /// Eligible at the first UD index pub fn min() -> Self { Self(Some(NonZeroU16::new(1).expect("unreachable"))) } diff --git a/runtime/common/src/entities.rs b/runtime/common/src/entities.rs index 4f21fa71b..8884f399f 100644 --- a/runtime/common/src/entities.rs +++ b/runtime/common/src/entities.rs @@ -53,15 +53,6 @@ pub struct IdtyData { pub first_eligible_ud: pallet_universal_dividend::FirstEligibleUd, } -#[cfg(feature = "std")] -impl IdtyData { - pub fn new() -> Self { - Self { - first_eligible_ud: pallet_universal_dividend::FirstEligibleUd::min(), - } - } -} - impl From<IdtyData> for pallet_universal_dividend::FirstEligibleUd { fn from(idty_data: IdtyData) -> Self { idty_data.first_eligible_ud diff --git a/runtime/gdev/tests/common/mod.rs b/runtime/gdev/tests/common/mod.rs index ae5c557d7..192857d11 100644 --- a/runtime/gdev/tests/common/mod.rs +++ b/runtime/gdev/tests/common/mod.rs @@ -223,7 +223,9 @@ impl ExtBuilder { index: i as u32 + 1, name: name.clone(), value: IdtyValue { - data: IdtyData::new(), + data: IdtyData { + first_eligible_ud: 1_u16.into(), + }, next_creatable_identity_on: Default::default(), owner_key: owner_key.clone(), old_owner_key: None, -- GitLab