From c33b86013c2d0e04b8cf99fb860e9905f6fdeb29 Mon Sep 17 00:00:00 2001 From: Kai <7630809+Kailai-Wang@users.noreply.github.com> Date: Fri, 5 Jul 2024 22:10:59 +0200 Subject: [PATCH] Add remove_vault in pallet-bitacross (#2863) * Add remove_vault * Do not pay fees for now --- pallets/bitacross/src/lib.rs | 26 ++++++++++++++++++++++---- pallets/teebag/src/lib.rs | 13 ++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/pallets/bitacross/src/lib.rs b/pallets/bitacross/src/lib.rs index 5f5d6669a8..d19c6f8ca0 100644 --- a/pallets/bitacross/src/lib.rs +++ b/pallets/bitacross/src/lib.rs @@ -72,6 +72,7 @@ pub mod pallet { RelayerRemoved { who: Identity }, BtcWalletGenerated { pub_key: PubKey, account_id: T::AccountId }, EthWalletGenerated { pub_key: PubKey }, + VaultRemoved { who: T::AccountId }, } #[pallet::error] @@ -81,6 +82,7 @@ pub mod pallet { UnsupportedRelayerType, BtcWalletAlreadyExist, EthWalletAlreadyExist, + VaultNotExist, } #[pallet::genesis_config] @@ -123,23 +125,39 @@ pub mod pallet { #[pallet::call_index(1)] #[pallet::weight({195_000_000})] - pub fn add_relayer(origin: OriginFor, account: Identity) -> DispatchResult { + pub fn add_relayer(origin: OriginFor, account: Identity) -> DispatchResultWithPostInfo { Self::ensure_admin_or_root(origin)?; ensure!(account.is_substrate() || account.is_evm(), Error::::UnsupportedRelayerType); // we don't care if `account` already exists Relayer::::insert(account.clone(), ()); Self::deposit_event(Event::RelayerAdded { who: account }); - Ok(()) + Ok(Pays::No.into()) } #[pallet::call_index(2)] #[pallet::weight({195_000_000})] - pub fn remove_relayer(origin: OriginFor, account: Identity) -> DispatchResult { + pub fn remove_relayer( + origin: OriginFor, + account: Identity, + ) -> DispatchResultWithPostInfo { Self::ensure_admin_or_root(origin)?; ensure!(Relayer::::contains_key(&account), Error::::RelayerNotExist); Relayer::::remove(account.clone()); Self::deposit_event(Event::RelayerRemoved { who: account }); - Ok(()) + Ok(Pays::No.into()) + } + + #[pallet::call_index(3)] + #[pallet::weight({195_000_000})] + pub fn remove_vault( + origin: OriginFor, + account: T::AccountId, + ) -> DispatchResultWithPostInfo { + Self::ensure_admin_or_root(origin)?; + ensure!(Vault::::contains_key(&account), Error::::VaultNotExist); + Vault::::remove(account.clone()); + Self::deposit_event(Event::VaultRemoved { who: account }); + Ok(Pays::No.into()) } /// --------------------------------------------------- diff --git a/pallets/teebag/src/lib.rs b/pallets/teebag/src/lib.rs index 7e6d90ced0..c1842f26eb 100644 --- a/pallets/teebag/src/lib.rs +++ b/pallets/teebag/src/lib.rs @@ -18,7 +18,7 @@ #![allow(clippy::too_many_arguments)] use frame_support::{ - dispatch::{DispatchErrorWithPostInfo, DispatchResult, DispatchResultWithPostInfo}, + dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo}, ensure, pallet_prelude::*, traits::Get, @@ -511,7 +511,7 @@ pub mod pallet { }, }; Self::add_enclave(&sender, &enclave)?; - Ok(().into()) + Ok(Pays::No.into()) } #[pallet::call_index(9)] @@ -519,7 +519,7 @@ pub mod pallet { pub fn unregister_enclave(origin: OriginFor) -> DispatchResultWithPostInfo { let sender = ensure_signed(origin)?; Self::remove_enclave(&sender)?; - Ok(().into()) + Ok(Pays::No.into()) } #[pallet::call_index(10)] @@ -560,10 +560,13 @@ pub mod pallet { #[pallet::call_index(20)] #[pallet::weight((195_000_000, DispatchClass::Normal))] - pub fn post_opaque_task(origin: OriginFor, request: RsaRequest) -> DispatchResult { + pub fn post_opaque_task( + origin: OriginFor, + request: RsaRequest, + ) -> DispatchResultWithPostInfo { let _ = ensure_signed(origin)?; Self::deposit_event(Event::OpaqueTaskPosted { request }); - Ok(()) + Ok(Pays::No.into()) } #[pallet::call_index(21)]