From 7b0b8f1ffc0894f45bfa67ca9600261ca07dd00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=ADdac=20Sement=C3=A9=20Fern=C3=A1ndez?= Date: Wed, 29 Nov 2023 15:59:42 +0100 Subject: [PATCH 1/2] * Addet set_administrator and set_parameters extrinsics --- pallets/ajuna-wildcard/src/lib.rs | 80 +++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/pallets/ajuna-wildcard/src/lib.rs b/pallets/ajuna-wildcard/src/lib.rs index 104e88b2..600af2b1 100644 --- a/pallets/ajuna-wildcard/src/lib.rs +++ b/pallets/ajuna-wildcard/src/lib.rs @@ -56,6 +56,9 @@ pub mod pallet { pub(crate) type NftAddressOf = NftAddress<::CollectionId, ::ItemId>; + #[pallet::storage] + pub type Administrator = StorageValue<_, T::AccountId, OptionQuery>; + #[pallet::storage] pub type StartTime = StorageValue<_, MomentOf, OptionQuery>; @@ -112,6 +115,8 @@ pub mod pallet { #[pallet::error] pub enum Error { + AdministratorNotSet, + AccountIsNotAdministrator, InvalidInput, UnknownDeposit, InsufficientReserveFunds, @@ -136,6 +141,14 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { + AdministratorSet { + administrator: T::AccountId, + }, + ParametersSet { + start_time: Option>, + epoch_duration: Option>, + signer_key: Option, + }, AssetDeposit { epoch: EpochNumber, depositor: T::AccountId, @@ -229,8 +242,59 @@ pub mod pallet { #[pallet::call] impl Pallet { + /// Set a administrator account. + /// + /// This call allows setting an account to act as an administrator. It must be called with + /// root privilege. #[pallet::weight({10_000})] #[pallet::call_index(0)] + pub fn set_administrator( + origin: OriginFor, + administrator: T::AccountId, + ) -> DispatchResult { + ensure_root(origin)?; + Administrator::::put(&administrator); + + Self::deposit_event(Event::AdministratorSet { administrator }); + Ok(()) + } + + #[pallet::weight({10_000})] + #[pallet::call_index(1)] + pub fn set_parameters( + origin: OriginFor, + start_time: Option>, + epoch_duration: Option>, + signer_key: Option, + ) -> DispatchResult { + let admin = Administrator::::get(); + ensure!(admin.is_some(), Error::::AdministratorNotSet); + + let account = ensure_signed(origin)?; + ensure!(admin.unwrap() == account, Error::::AccountIsNotAdministrator); + + if let Some(start_time) = start_time { + StartTime::::put(start_time); + } + + if let Some(epoch_duration) = epoch_duration { + EpochDuration::::put(epoch_duration); + } + + if let Some(signer_key) = signer_key { + SignerKey::::put(signer_key); + } + + Self::deposit_event(Event::ParametersSet { + start_time: StartTime::::get(), + epoch_duration: EpochDuration::::get(), + signer_key: SignerKey::::get(), + }); + Ok(()) + } + + #[pallet::weight({10_000})] + #[pallet::call_index(2)] pub fn deposit(origin: OriginFor, asset_deposit: AssetDeposit) -> DispatchResult { ensure!(!Frozen::::exists(), Error::::PalletFrozen); @@ -264,7 +328,7 @@ pub mod pallet { } #[pallet::weight({10_000})] - #[pallet::call_index(1)] + #[pallet::call_index(3)] pub fn withdraw( origin: OriginFor, balance_proof: BalanceProof, @@ -296,7 +360,7 @@ pub mod pallet { } #[pallet::weight({10_000})] - #[pallet::call_index(2)] + #[pallet::call_index(4)] pub fn withdraw_frozen( origin: OriginFor, balance_proof: BalanceProof, @@ -336,7 +400,7 @@ pub mod pallet { } #[pallet::weight({10_000})] - #[pallet::call_index(3)] + #[pallet::call_index(5)] pub fn refund_frozen(origin: OriginFor) -> DispatchResult { let withdrawer = ensure_signed(origin)?; @@ -381,7 +445,7 @@ pub mod pallet { } #[pallet::weight({10_000})] - #[pallet::call_index(4)] + #[pallet::call_index(6)] pub fn challenge(origin: OriginFor) -> DispatchResult { let challenger = ensure_signed(origin)?; @@ -409,7 +473,7 @@ pub mod pallet { } #[pallet::weight({10_000})] - #[pallet::call_index(5)] + #[pallet::call_index(7)] pub fn respond_challenge( origin: OriginFor, balance_proof: BalanceProof, @@ -447,7 +511,7 @@ pub mod pallet { } #[pallet::weight({10_000})] - #[pallet::call_index(6)] + #[pallet::call_index(8)] pub fn freeze(origin: OriginFor) -> DispatchResult { let _ = ensure_signed(origin)?; @@ -465,7 +529,7 @@ pub mod pallet { } #[pallet::weight({10_000})] - #[pallet::call_index(7)] + #[pallet::call_index(9)] pub fn propagate_freeze( origin: OriginFor, freeze_proof: FreezeProof, @@ -504,7 +568,7 @@ pub mod pallet { } #[pallet::weight({10_000})] - #[pallet::call_index(8)] + #[pallet::call_index(10)] pub fn respond_zero_challenge( origin: OriginFor, zero_proof: ZeroBalanceProof, From 94aa6a03e4f5ea851cdd2246c5f529fb505b6c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=ADdac=20Sement=C3=A9=20Fern=C3=A1ndez?= Date: Wed, 29 Nov 2023 16:02:45 +0100 Subject: [PATCH 2/2] * Updated workflows --- .github/workflows/check-pull-request.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/check-pull-request.yml b/.github/workflows/check-pull-request.yml index 2339a0d8..3501d822 100644 --- a/.github/workflows/check-pull-request.yml +++ b/.github/workflows/check-pull-request.yml @@ -4,6 +4,7 @@ on: pull_request: branches: - develop + - develop-erdstall paths: - "**/*.rs" - "**/Cargo.toml"