Skip to content

Commit

Permalink
bump ismp (#55)
Browse files Browse the repository at this point in the history
* bump ismp

* fix benchmarking

* bump
  • Loading branch information
seunlanlege authored Jun 6, 2023
1 parent 332f2f7 commit 5508e2d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 47 deletions.
60 changes: 30 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 21 additions & 16 deletions ismp-assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use alloc::string::ToString;
use frame_support::{traits::fungible::Mutate, PalletId};
use ismp::{
module::IsmpModule,
router::{Request, Response},
router::{Post, Request, Response},
};
pub use pallet::*;

Expand Down Expand Up @@ -125,6 +125,16 @@ pub mod pallet {
params: TransferParams<T::AccountId, <T as Config>::Balance>,
) -> DispatchResult {
let origin = ensure_signed(origin)?;

// first, burn the requested amount
<T::NativeCurrency as Mutate<T::AccountId>>::burn_from(
&origin,
params.amount.into(),
Precision::Exact,
Fortitude::Force,
)?;

// next, construct the request to be sent out
let payload = Payload { to: params.to, from: origin.clone(), amount: params.amount };
let post = DispatchPost {
dest_chain: params.dest_chain,
Expand All @@ -134,22 +144,20 @@ pub mod pallet {
data: payload.encode(),
};

// dispatch the request
let dispatcher = T::IsmpDispatcher::default();
dispatcher
.dispatch_request(DispatchRequest::Post(post))
.map_err(|_| Error::<T>::TransferFailed)?;
<T::NativeCurrency as Mutate<T::AccountId>>::burn_from(
&origin,
params.amount.into(),
Precision::Exact,
Fortitude::Force,
)?;

// let the user know, they've successfully sent the funds
Self::deposit_event(Event::<T>::BalanceTransferred {
from: payload.from,
to: payload.to,
amount: payload.amount,
dest_chain: params.dest_chain,
});

Ok(())
}

Expand Down Expand Up @@ -217,16 +225,13 @@ fn ismp_dispatch_error(msg: &str) -> ismp::error::Error {
}

impl<T: Config> IsmpModule for Pallet<T> {
fn on_accept(request: Request) -> Result<(), ismp::error::Error> {
let source_chain = request.source_chain();
let data = match request {
Request::Post(post) => post.data,
_ => Err(ismp_dispatch_error("Only Post requests allowed, found Get"))?,
};
fn on_accept(request: Post) -> Result<(), ismp::error::Error> {
let source_chain = request.source_chain;

let payload =
<Payload<T::AccountId, <T as Config>::Balance> as codec::Decode>::decode(&mut &*data)
.map_err(|_| ismp_dispatch_error("Failed to decode request data"))?;
let payload = <Payload<T::AccountId, <T as Config>::Balance> as codec::Decode>::decode(
&mut &*request.data,
)
.map_err(|_| ismp_dispatch_error("Failed to decode request data"))?;
<T::NativeCurrency as Mutate<T::AccountId>>::mint_into(&payload.to, payload.amount.into())
.map_err(|_| ismp_dispatch_error("Failed to mint funds"))?;
Pallet::<T>::deposit_event(Event::<T>::BalanceReceived {
Expand Down
2 changes: 1 addition & 1 deletion pallet-ismp/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub mod benchmarks {
/// module id for the mock benchmarking module
pub const MODULE_ID: PalletId = PalletId(*b"benchmak");
impl IsmpModule for BenchmarkIsmpModule {
fn on_accept(_request: Request) -> Result<(), IsmpError> {
fn on_accept(_request: Post) -> Result<(), IsmpError> {
Ok(())
}

Expand Down

0 comments on commit 5508e2d

Please sign in to comment.