Skip to content

Commit

Permalink
Add transactional for gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
AAweidai committed Mar 16, 2022
1 parent 79daec6 commit 651f047
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
25 changes: 13 additions & 12 deletions xpallets/gateway/bitcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ macro_rules! log {
pub mod pallet {
use sp_std::marker::PhantomData;

use frame_support::{dispatch::DispatchResult, pallet_prelude::*, traits::UnixTime};
use frame_support::{
dispatch::DispatchResult, pallet_prelude::*, traits::UnixTime, transactional,
};
use frame_system::pallet_prelude::*;
use sp_runtime::traits::Saturating;

Expand Down Expand Up @@ -226,6 +228,7 @@ pub mod pallet {
/// Dangerous! remove current withdrawal proposal directly. Please check business logic before
/// do this operation.
#[pallet::weight(<T as Config>::WeightInfo::remove_proposal())]
#[transactional]
pub fn remove_proposal(origin: OriginFor<T>) -> DispatchResult {
T::CouncilOrigin::try_origin(origin)
.map(|_| ())
Expand Down Expand Up @@ -758,18 +761,16 @@ pub mod pallet {
}

pub(crate) fn apply_remove_proposal() -> DispatchResult {
with_transaction_result(|| {
if let Some(proposal) = WithdrawalProposal::<T>::take() {
for id in proposal.withdrawal_id_list.iter() {
xpallet_gateway_records::Pallet::<T>::set_withdrawal_state_by_trustees(
*id,
Chain::Bitcoin,
xpallet_gateway_records::WithdrawalState::Applying,
)?;
}
if let Some(proposal) = WithdrawalProposal::<T>::take() {
for id in proposal.withdrawal_id_list.iter() {
xpallet_gateway_records::Pallet::<T>::set_withdrawal_state_by_trustees(
*id,
Chain::Bitcoin,
xpallet_gateway_records::WithdrawalState::Applying,
)?;
}
Ok(())
})
}
Ok(())
}
}

Expand Down
10 changes: 9 additions & 1 deletion xpallets/gateway/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub use weights::WeightInfo;
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_support::{pallet_prelude::*, transactional};
use frame_system::pallet_prelude::*;

#[pallet::config]
Expand Down Expand Up @@ -122,6 +122,7 @@ pub mod pallet {
///
/// NOTE: `ext` is for the compatibility purpose, e.g., EOS requires a memo when doing the transfer.
#[pallet::weight(<T as Config>::WeightInfo::withdraw())]
#[transactional]
pub fn withdraw(
origin: OriginFor<T>,
#[pallet::compact] asset_id: AssetId,
Expand All @@ -145,6 +146,7 @@ pub mod pallet {
///
/// WithdrawalRecord State: `Applying` ==> `NormalCancel`
#[pallet::weight(<T as Config>::WeightInfo::cancel_withdrawal())]
#[transactional]
pub fn cancel_withdrawal(origin: OriginFor<T>, id: WithdrawalRecordId) -> DispatchResult {
let from = ensure_signed(origin)?;
xpallet_gateway_records::Pallet::<T>::cancel_withdrawal(id, &from)
Expand Down Expand Up @@ -201,6 +203,7 @@ pub mod pallet {

/// Manual execution of the election by admin.
#[pallet::weight(0u64)]
#[transactional]
pub fn excute_trustee_election(origin: OriginFor<T>, chain: Chain) -> DispatchResult {
match ensure_signed(origin.clone()) {
Ok(who) => {
Expand All @@ -222,6 +225,7 @@ pub mod pallet {
///
/// This is called by the root.
#[pallet::weight(0u64)]
#[transactional]
pub fn cancel_trustee_election(origin: OriginFor<T>, chain: Chain) -> DispatchResult {
T::CouncilOrigin::try_origin(origin)
.map(|_| ())
Expand All @@ -242,6 +246,7 @@ pub mod pallet {
/// Since this is a root call and will go into trustee election, we assume full block for now.
/// # </weight>
#[pallet::weight(0u64)]
#[transactional]
pub fn move_trust_into_black_room(
origin: OriginFor<T>,
chain: Chain,
Expand Down Expand Up @@ -270,6 +275,8 @@ pub mod pallet {
for trustee in trustees.iter() {
l.push(trustee.clone());
}
l.sort_unstable();
l.dedup();
});
trustees.into_iter().for_each(|trustee| {
if TrusteeSigRecord::<T>::contains_key(chain, &trustee) {
Expand Down Expand Up @@ -331,6 +338,7 @@ pub mod pallet {
/// circumstances to not renew), but they want to receive
/// their award early, they can call this through the council.
#[pallet::weight(< T as Config >::WeightInfo::claim_trustee_reward())]
#[transactional]
pub fn claim_trustee_reward(
origin: OriginFor<T>,
chain: Chain,
Expand Down

0 comments on commit 651f047

Please sign in to comment.