From a4a65f6d7258223ec58cab681c8ec73bc73f88c7 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Tue, 5 Sep 2023 09:56:43 +0100 Subject: [PATCH 1/2] log request --- ismp-demo/src/lib.rs | 65 ++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/ismp-demo/src/lib.rs b/ismp-demo/src/lib.rs index 9ecad25..adf2a1a 100644 --- a/ismp-demo/src/lib.rs +++ b/ismp-demo/src/lib.rs @@ -24,6 +24,7 @@ use alloc::string::ToString; use frame_support::{traits::fungible::Mutate, PalletId}; use ismp::{ error::Error as IsmpError, + host::StateMachine, module::IsmpModule, router::{Post, Request, Response}, }; @@ -47,7 +48,7 @@ pub mod pallet { }; use frame_system::pallet_prelude::*; use ismp::{ - host::StateMachine, + host::{Ethereum, StateMachine}, router::{DispatchGet, DispatchPost, DispatchRequest, IsmpDispatcher}, }; @@ -94,6 +95,14 @@ pub mod pallet { source_chain: StateMachine, }, + /// Request data receieved + Request { + /// Source of the request + source: StateMachine, + /// utf-8 decoded data + data: String, + }, + /// Get response recieved GetResponse(Vec>>), } @@ -198,7 +207,7 @@ pub mod pallet { ensure_signed(origin)?; let post = DispatchPost { - dest: params.destination, + dest: StateMachine::Ethereum(params.destination), from: PALLET_ID.to_bytes(), to: params.module.0.to_vec(), timeout_timestamp: params.timeout, @@ -271,8 +280,8 @@ pub mod pallet { /// Destination module pub module: H160, - /// Destination parachain - pub destination: StateMachine, + /// Destination EVM host + pub destination: Ethereum, /// Timeout timestamp on destination chain in seconds pub timeout: u64, @@ -292,20 +301,40 @@ impl IsmpModule for IsmpModuleCallback { fn on_accept(&self, request: Post) -> Result<(), IsmpError> { let source_chain = request.source; - let payload = ::Balance> as codec::Decode>::decode( - &mut &*request.data, - ) - .map_err(|_| { - IsmpError::ImplementationSpecific("Failed to decode request data".to_string()) - })?; - >::mint_into(&payload.to, payload.amount.into()) - .map_err(|_| IsmpError::ImplementationSpecific("Failed to mint funds".to_string()))?; - Pallet::::deposit_event(Event::::BalanceReceived { - from: payload.from, - to: payload.to, - amount: payload.amount, - source_chain, - }); + match source_chain { + StateMachine::Ethereum(_) => Pallet::::deposit_event(Event::Request { + source: source_chain, + data: unsafe { String::from_utf8_unchecked(request.data) }, + }), + StateMachine::Polkadot(_) | StateMachine::Kusama(_) => { + let payload = + ::Balance> as codec::Decode>::decode( + &mut &*request.data, + ) + .map_err(|_| { + IsmpError::ImplementationSpecific( + "Failed to decode request data".to_string(), + ) + })?; + >::mint_into( + &payload.to, + payload.amount.into(), + ) + .map_err(|_| { + IsmpError::ImplementationSpecific("Failed to mint funds".to_string()) + })?; + Pallet::::deposit_event(Event::::BalanceReceived { + from: payload.from, + to: payload.to, + amount: payload.amount, + source_chain, + }); + } + source => { + Err(IsmpError::ImplementationSpecific(format!("Unsupported source {source:?}")))? + } + } + Ok(()) } From da385924242ace29bda59759e4f504614212a7e1 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Tue, 5 Sep 2023 10:10:12 +0100 Subject: [PATCH 2/2] alloc imports --- ismp-demo/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ismp-demo/src/lib.rs b/ismp-demo/src/lib.rs index adf2a1a..ebd3e3e 100644 --- a/ismp-demo/src/lib.rs +++ b/ismp-demo/src/lib.rs @@ -20,7 +20,10 @@ extern crate alloc; -use alloc::string::ToString; +use alloc::{ + format, + string::{String, ToString}, +}; use frame_support::{traits::fungible::Mutate, PalletId}; use ismp::{ error::Error as IsmpError,