Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Pallet: Atomic Swap #6349

Merged
merged 21 commits into from
Jun 18, 2020
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
Next Next commit
Add missing events
  • Loading branch information
sorpaas committed Jun 14, 2020
commit 8ce4cce7d49df15a4fd63f4069cf90cc86383f51
27 changes: 23 additions & 4 deletions frame/atomic-swap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ decl_error! {
AlreadyExist,
/// Swap proof is invalid.
InvalidProof,
/// Proof is too large.
ProofTooLarge,
/// Swap does not exist.
NotExist,
/// Duration has not yet passed for the swap to be cancelled.
Expand All @@ -101,7 +103,7 @@ decl_event!(
/// Swap claimed.
SwapClaimed(AccountId, HashedProof, Balance),
/// Swap cancelled.
SwapCancelled(AccountId, HashedProof, Balance),
SwapCancelled(AccountId, HashedProof),
}
);

Expand Down Expand Up @@ -133,14 +135,23 @@ decl_module! {
balance,
end_block: frame_system::Module::<T>::block_number() + duration,
};
PendingSwaps::<T>::insert(target, hashed_proof, swap);
PendingSwaps::<T>::insert(target.clone(), hashed_proof.clone(), swap.clone());

Self::deposit_event(
RawEvent::NewSwap(target, hashed_proof, swap)
);
}

#[weight = 0]
fn claim_swap(
origin,
proof: Vec<u8>,
) {
ensure!(
proof.len() <= T::ProofLimit::get() as usize,
Error::<T>::ProofTooLarge,
);

let target = ensure_signed(origin)?;
let hashed_proof = blake2_256(&proof);

Expand All @@ -152,7 +163,11 @@ decl_module! {
swap.balance,
BalanceStatus::Free,
)?;
PendingSwaps::<T>::remove(target, hashed_proof);
PendingSwaps::<T>::remove(target.clone(), hashed_proof.clone());

Self::deposit_event(
RawEvent::SwapClaimed(target, hashed_proof, swap.balance)
);
}

#[weight = 0]
Expand All @@ -174,7 +189,11 @@ decl_module! {
&swap.source,
swap.balance,
);
PendingSwaps::<T>::remove(&target, hashed_proof);
PendingSwaps::<T>::remove(&target, hashed_proof.clone());

Self::deposit_event(
RawEvent::SwapCancelled(target, hashed_proof)
);
}
}
}