Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Remove unnecessary type aliases
  • Loading branch information
sorpaas committed Jun 20, 2020
commit 45cbe62944e73f6875242b04b1ee23aa1d1c9d99
30 changes: 12 additions & 18 deletions frame/atomic-swap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,13 @@ use sp_runtime::RuntimeDebug;
#[derive(Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode)]
pub struct PendingSwap<T: Trait> {
/// Source of the swap.
pub source: AccountIdFor<T>,
pub source: T::AccountId,
/// Action of this swap.
pub action: T::SwapAction,
/// End block of the lock.
pub end_block: BlockNumberFor<T>,
pub end_block: T::BlockNumber,
}

/// AccountId type from the pallet's point of view.
pub type AccountIdFor<T> = <T as frame_system::Trait>::AccountId;

/// BlockNumber type from the pallet's point of view.
pub type BlockNumberFor<T> = <T as frame_system::Trait>::BlockNumber;

/// Hashed proof type.
pub type HashedProof = [u8; 32];

Expand All @@ -63,14 +57,14 @@ pub type HashedProof = [u8; 32];
pub trait SwapAction<T: Trait> {
/// 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: &AccountIdFor<T>) -> DispatchResult;
fn reserve(&self, source: &T::AccountId) -> DispatchResult;
/// Claim the reserved resources, with `source` and `target`. Returns whether the claim
/// succeeds.
fn claim(&self, source: &AccountIdFor<T>, target: &AccountIdFor<T>) -> bool;
fn claim(&self, source: &T::AccountId, target: &T::AccountId) -> bool;
/// Weight for executing the operation.
fn weight(&self) -> Weight;
/// Cancel the resources reserved in `source`.
fn cancel(&self, source: &AccountIdFor<T>);
fn cancel(&self, source: &T::AccountId);
}

/// A swap action that only allows transferring balances.
Expand Down Expand Up @@ -110,19 +104,19 @@ impl<T: Trait, C> DerefMut for BalanceSwapAction<T, C> where
impl<T: Trait, C> SwapAction<T> for BalanceSwapAction<T, C> where
C: ReservableCurrency<T::AccountId>,
{
fn reserve(&self, source: &AccountIdFor<T>) -> DispatchResult {
fn reserve(&self, source: &T::AccountId) -> DispatchResult {
C::reserve(&source, self.value)
}

fn claim(&self, source: &AccountIdFor<T>, target: &AccountIdFor<T>) -> bool {
fn claim(&self, source: &T::AccountId, target: &T::AccountId) -> bool {
C::repatriate_reserved(source, target, self.value, BalanceStatus::Free).is_ok()
}

fn weight(&self) -> Weight {
T::DbWeight::get().reads_writes(1, 1)
}

fn cancel(&self, source: &AccountIdFor<T>) {
fn cancel(&self, source: &T::AccountId) {
C::unreserve(source, self.value);
}
}
Expand Down Expand Up @@ -178,7 +172,7 @@ decl_error! {
decl_event!(
/// Event of atomic swap pallet.
pub enum Event<T> where
AccountId = AccountIdFor<T>,
AccountId = <T as system::Trait>::AccountId,
PendingSwap = PendingSwap<T>,
{
/// Swap created.
Expand Down Expand Up @@ -212,10 +206,10 @@ decl_module! {
#[weight = T::DbWeight::get().reads_writes(1, 1).saturating_add(40_000_000)]
fn create_swap(
origin,
target: AccountIdFor<T>,
target: T::AccountId,
hashed_proof: HashedProof,
action: T::SwapAction,
duration: BlockNumberFor<T>,
duration: T::BlockNumber,
) {
let source = ensure_signed(origin)?;
ensure!(
Expand Down Expand Up @@ -286,7 +280,7 @@ decl_module! {
#[weight = T::DbWeight::get().reads_writes(1, 1).saturating_add(40_000_000)]
fn cancel_swap(
origin,
target: AccountIdFor<T>,
target: T::AccountId,
hashed_proof: HashedProof,
) {
let source = ensure_signed(origin)?;
Expand Down