diff --git a/substrate/frame/atomic-swap/src/lib.rs b/substrate/frame/atomic-swap/src/lib.rs index 7e8354f8b6..65794792d0 100644 --- a/substrate/frame/atomic-swap/src/lib.rs +++ b/substrate/frame/atomic-swap/src/lib.rs @@ -74,61 +74,55 @@ pub type HashedProof = [u8; 32]; /// succeeds with best efforts. /// - **Claim**: claim any resources reserved in the first phrase. /// - **Cancel**: cancel any resources reserved in the first phrase. -pub trait SwapAction { +pub trait SwapAction { /// Reserve the resources needed for the swap, from the given `source`. The reservation is /// allowed to fail. If that is the case, the the full swap creation operation is cancelled. - fn reserve(&self, source: &T::AccountId) -> DispatchResult; + fn reserve(&self, source: &AccountId) -> DispatchResult; /// Claim the reserved resources, with `source` and `target`. Returns whether the claim /// succeeds. - fn claim(&self, source: &T::AccountId, target: &T::AccountId) -> bool; + fn claim(&self, source: &AccountId, target: &AccountId) -> bool; /// Weight for executing the operation. fn weight(&self) -> Weight; /// Cancel the resources reserved in `source`. - fn cancel(&self, source: &T::AccountId); + fn cancel(&self, source: &AccountId); } /// A swap action that only allows transferring balances. #[derive(Clone, RuntimeDebug, Eq, PartialEq, Encode, Decode)] -pub struct BalanceSwapAction> { - value: ::AccountId>>::Balance, +pub struct BalanceSwapAction> { + value: >::Balance, _marker: PhantomData, } -impl BalanceSwapAction where - C: ReservableCurrency, -{ +impl BalanceSwapAction where C: ReservableCurrency { /// Create a new swap action value of balance. - pub fn new(value: ::AccountId>>::Balance) -> Self { + pub fn new(value: >::Balance) -> Self { Self { value, _marker: PhantomData } } } -impl Deref for BalanceSwapAction where - C: ReservableCurrency, -{ - type Target = ::AccountId>>::Balance; +impl Deref for BalanceSwapAction where C: ReservableCurrency { + type Target = >::Balance; fn deref(&self) -> &Self::Target { &self.value } } -impl DerefMut for BalanceSwapAction where - C: ReservableCurrency, -{ +impl DerefMut for BalanceSwapAction where C: ReservableCurrency { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.value } } -impl SwapAction for BalanceSwapAction where - C: ReservableCurrency, +impl SwapAction for BalanceSwapAction + where C: ReservableCurrency { - fn reserve(&self, source: &T::AccountId) -> DispatchResult { + fn reserve(&self, source: &AccountId) -> DispatchResult { C::reserve(&source, self.value) } - fn claim(&self, source: &T::AccountId, target: &T::AccountId) -> bool { + fn claim(&self, source: &AccountId, target: &AccountId) -> bool { C::repatriate_reserved(source, target, self.value, BalanceStatus::Free).is_ok() } @@ -136,7 +130,7 @@ impl SwapAction for BalanceSwapAction where T::DbWeight::get().reads_writes(1, 1) } - fn cancel(&self, source: &T::AccountId) { + fn cancel(&self, source: &AccountId) { C::unreserve(source, self.value); } } @@ -146,7 +140,7 @@ pub trait Trait: frame_system::Trait { /// The overarching event type. type Event: From> + Into<::Event>; /// Swap action. - type SwapAction: SwapAction + Parameter; + type SwapAction: SwapAction + Parameter; /// Limit of proof size. /// /// Atomic swap is only atomic if once the proof is revealed, both parties can submit the proofs diff --git a/substrate/frame/atomic-swap/src/tests.rs b/substrate/frame/atomic-swap/src/tests.rs index 82cd30d5d3..6690a24d36 100644 --- a/substrate/frame/atomic-swap/src/tests.rs +++ b/substrate/frame/atomic-swap/src/tests.rs @@ -68,7 +68,7 @@ parameter_types! { } impl Trait for Test { type Event = (); - type SwapAction = BalanceSwapAction; + type SwapAction = BalanceSwapAction; type ProofLimit = ProofLimit; } type System = frame_system::Module;