From ab4c93e5d130126af3e80b9a6cde0ef472232bc9 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Wed, 20 Dec 2023 17:34:06 +0600 Subject: [PATCH] Genesis config for `pallet-ddc-payouts` (#207) --- node/service/chain-specs/example.json | 12 +++++++++++- node/service/src/chain_spec.rs | 1 + pallets/ddc-payouts/src/lib.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/node/service/chain-specs/example.json b/node/service/chain-specs/example.json index 6014d0a00..961ae7795 100644 --- a/node/service/chain-specs/example.json +++ b/node/service/chain-specs/example.json @@ -193,7 +193,7 @@ "mode": "Storage" } } - ], + ] }, "ddcClusters": { "clusters": [ @@ -233,6 +233,16 @@ ] ] ] + }, + "ddcPayouts": { + "authorisedCaller": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + "debtorCustomers": [ + [ + "0x0000000000000000000000000000000000000001", + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + 10000000000 + ] + ] } } } diff --git a/node/service/src/chain_spec.rs b/node/service/src/chain_spec.rs index 12859a2c6..45f26873e 100644 --- a/node/service/src/chain_spec.rs +++ b/node/service/src/chain_spec.rs @@ -235,6 +235,7 @@ pub fn cere_dev_genesis( nomination_pools: Default::default(), ddc_clusters: Default::default(), ddc_nodes: Default::default(), + ddc_payouts: Default::default(), } } diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index 9d7b12003..51eb7bc15 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -286,6 +286,33 @@ pub mod pallet { Finalized = 7, } + #[pallet::genesis_config] + pub struct GenesisConfig { + pub authorised_caller: Option, + pub debtor_customers: Vec<(ClusterId, T::AccountId, u128)>, + } + + #[cfg(feature = "std")] + impl Default for GenesisConfig { + fn default() -> Self { + GenesisConfig { + authorised_caller: Default::default(), + debtor_customers: Default::default(), + } + } + } + + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig { + fn build(&self) { + AuthorisedCaller::::set(self.authorised_caller.clone()); + + for (cluster_id, customer_id, debt) in &self.debtor_customers { + DebtorCustomers::::insert(cluster_id, customer_id, debt); + } + } + } + #[pallet::call] impl Pallet { #[pallet::weight(T::WeightInfo::set_authorised_caller())]