From 5508e2db6248d0edd20bc224e760f7cfbd4cda75 Mon Sep 17 00:00:00 2001 From: Web3 Philosopher Date: Tue, 6 Jun 2023 13:20:06 +0100 Subject: [PATCH] bump ismp (#55) * bump ismp * fix benchmarking * bump --- Cargo.lock | 60 ++++++++++++++++----------------- ismp-assets/src/lib.rs | 37 +++++++++++--------- pallet-ismp/src/benchmarking.rs | 2 +- 3 files changed, 52 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 124eed421..bb1df52bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -181,9 +181,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67fc08ce920c31afb70f013dcce1bfc3a3195de6a228474e45e1f145b36f8d04" +checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" dependencies = [ "memchr", ] @@ -834,9 +834,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.25" +version = "0.4.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdbc37d37da9e5bce8173f3a41b71d9bf3c674deebbaceacd0ebdabde76efb03" +checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" dependencies = [ "android-tzdata", "iana-time-zone", @@ -910,9 +910,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.3.0" +version = "4.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93aae7a4192245f70fe75dd9157fc7b4a5bf53e88d30bd4396f7d8f9284d5acc" +checksum = "b4ed2379f8603fa2b7509891660e802b88c70a79a6427a70abb5968054de2c28" dependencies = [ "clap_builder", "clap_derive", @@ -921,9 +921,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.3.0" +version = "4.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f423e341edefb78c9caba2d9c7f7687d0e72e89df3ce3394554754393ac3990" +checksum = "72394f3339a76daf211e57d4bcb374410f3965dcc606dd0e03738c7888766980" dependencies = [ "anstream", "anstyle", @@ -934,9 +934,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.3.0" +version = "4.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "191d9573962933b4027f932c600cd252ce27a8ad5979418fe78e43c07996f27b" +checksum = "59e9ef9a08ee1c0e1f2e162121665ac45ac3783b0f897db7244ae75ad9a8f65b" dependencies = [ "heck", "proc-macro2", @@ -2141,9 +2141,9 @@ dependencies = [ [[package]] name = "form_urlencoded" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" dependencies = [ "percent-encoding", ] @@ -2298,9 +2298,9 @@ dependencies = [ [[package]] name = "fs4" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7f5b6908aecca5812a4569056285e58c666588c9573ee59765bf1d3692699e2" +checksum = "7672706608ecb74ab2e055c68327ffc25ae4cac1e12349204fd5fb0f3487cce2" dependencies = [ "rustix 0.37.19", "windows-sys 0.48.0", @@ -2850,9 +2850,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -3029,7 +3029,7 @@ dependencies = [ [[package]] name = "ismp" version = "0.1.0" -source = "git+https://github.com/polytope-labs/ismp-rs?branch=main#1628c9d7519ae39b8badf02ed42b6c7fa23f28a0" +source = "git+https://github.com/polytope-labs/ismp-rs?branch=main#90e322bd235c78d929649076f831c2f555a0a028" dependencies = [ "derive_more", "parity-scale-codec", @@ -3152,7 +3152,7 @@ dependencies = [ [[package]] name = "ismp-testsuite" version = "0.1.0" -source = "git+https://github.com/polytope-labs/ismp-rs?branch=main#1628c9d7519ae39b8badf02ed42b6c7fa23f28a0" +source = "git+https://github.com/polytope-labs/ismp-rs?branch=main#90e322bd235c78d929649076f831c2f555a0a028" dependencies = [ "ismp", "parity-scale-codec", @@ -3350,9 +3350,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.144" +version = "0.2.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" +checksum = "fc86cde3ff845662b8f4ef6cb50ea0e20c524eb3d29ae048287e06a1b3fa6a81" [[package]] name = "libloading" @@ -4157,9 +4157,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.7" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eebffdb73fe72e917997fad08bdbf31ac50b0fa91cec93e69a0662e4264d454c" +checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", "wasi 0.11.0+wasi-snapshot-preview1", @@ -4557,9 +4557,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.17.2" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "opaque-debug" @@ -4874,9 +4874,9 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" +checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "petgraph" @@ -5702,7 +5702,7 @@ version = "1.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81ca098a9821bd52d6b24fd8b10bd081f47d39c22778cafaa75a2857a62c6390" dependencies = [ - "aho-corasick 1.0.1", + "aho-corasick 1.0.2", "memchr", "regex-syntax 0.7.2", ] @@ -8926,12 +8926,12 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.3.1" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" dependencies = [ "form_urlencoded", - "idna 0.3.0", + "idna 0.4.0", "percent-encoding", ] diff --git a/ismp-assets/src/lib.rs b/ismp-assets/src/lib.rs index 3ec6db017..943fab868 100644 --- a/ismp-assets/src/lib.rs +++ b/ismp-assets/src/lib.rs @@ -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::*; @@ -125,6 +125,16 @@ pub mod pallet { params: TransferParams::Balance>, ) -> DispatchResult { let origin = ensure_signed(origin)?; + + // first, burn the requested amount + >::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, @@ -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::::TransferFailed)?; - >::burn_from( - &origin, - params.amount.into(), - Precision::Exact, - Fortitude::Force, - )?; + + // let the user know, they've successfully sent the funds Self::deposit_event(Event::::BalanceTransferred { from: payload.from, to: payload.to, amount: payload.amount, dest_chain: params.dest_chain, }); + Ok(()) } @@ -217,16 +225,13 @@ fn ismp_dispatch_error(msg: &str) -> ismp::error::Error { } impl IsmpModule for Pallet { - 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 = - ::Balance> as codec::Decode>::decode(&mut &*data) - .map_err(|_| ismp_dispatch_error("Failed to decode request data"))?; + let payload = ::Balance> as codec::Decode>::decode( + &mut &*request.data, + ) + .map_err(|_| ismp_dispatch_error("Failed to decode request data"))?; >::mint_into(&payload.to, payload.amount.into()) .map_err(|_| ismp_dispatch_error("Failed to mint funds"))?; Pallet::::deposit_event(Event::::BalanceReceived { diff --git a/pallet-ismp/src/benchmarking.rs b/pallet-ismp/src/benchmarking.rs index c9d9fbd5e..aa8c891b0 100644 --- a/pallet-ismp/src/benchmarking.rs +++ b/pallet-ismp/src/benchmarking.rs @@ -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(()) }