Skip to content

Commit

Permalink
Add remove_vault in pallet-bitacross (#2863)
Browse files Browse the repository at this point in the history
* Add remove_vault

* Do not pay fees for now
  • Loading branch information
Kailai-Wang authored Jul 5, 2024
1 parent 610ea48 commit c33b860
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
26 changes: 22 additions & 4 deletions pallets/bitacross/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -81,6 +82,7 @@ pub mod pallet {
UnsupportedRelayerType,
BtcWalletAlreadyExist,
EthWalletAlreadyExist,
VaultNotExist,
}

#[pallet::genesis_config]
Expand Down Expand Up @@ -123,23 +125,39 @@ pub mod pallet {

#[pallet::call_index(1)]
#[pallet::weight({195_000_000})]
pub fn add_relayer(origin: OriginFor<T>, account: Identity) -> DispatchResult {
pub fn add_relayer(origin: OriginFor<T>, account: Identity) -> DispatchResultWithPostInfo {
Self::ensure_admin_or_root(origin)?;
ensure!(account.is_substrate() || account.is_evm(), Error::<T>::UnsupportedRelayerType);
// we don't care if `account` already exists
Relayer::<T>::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<T>, account: Identity) -> DispatchResult {
pub fn remove_relayer(
origin: OriginFor<T>,
account: Identity,
) -> DispatchResultWithPostInfo {
Self::ensure_admin_or_root(origin)?;
ensure!(Relayer::<T>::contains_key(&account), Error::<T>::RelayerNotExist);
Relayer::<T>::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<T>,
account: T::AccountId,
) -> DispatchResultWithPostInfo {
Self::ensure_admin_or_root(origin)?;
ensure!(Vault::<T>::contains_key(&account), Error::<T>::VaultNotExist);
Vault::<T>::remove(account.clone());
Self::deposit_event(Event::VaultRemoved { who: account });
Ok(Pays::No.into())
}

/// ---------------------------------------------------
Expand Down
13 changes: 8 additions & 5 deletions pallets/teebag/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#![allow(clippy::too_many_arguments)]

use frame_support::{
dispatch::{DispatchErrorWithPostInfo, DispatchResult, DispatchResultWithPostInfo},
dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo},
ensure,
pallet_prelude::*,
traits::Get,
Expand Down Expand Up @@ -511,15 +511,15 @@ pub mod pallet {
},
};
Self::add_enclave(&sender, &enclave)?;
Ok(().into())
Ok(Pays::No.into())
}

#[pallet::call_index(9)]
#[pallet::weight((195_000_000, DispatchClass::Normal))]
pub fn unregister_enclave(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let sender = ensure_signed(origin)?;
Self::remove_enclave(&sender)?;
Ok(().into())
Ok(Pays::No.into())
}

#[pallet::call_index(10)]
Expand Down Expand Up @@ -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<T>, request: RsaRequest) -> DispatchResult {
pub fn post_opaque_task(
origin: OriginFor<T>,
request: RsaRequest,
) -> DispatchResultWithPostInfo {
let _ = ensure_signed(origin)?;
Self::deposit_event(Event::OpaqueTaskPosted { request });
Ok(())
Ok(Pays::No.into())
}

#[pallet::call_index(21)]
Expand Down

0 comments on commit c33b860

Please sign in to comment.