From 75cd51079f1b23dd210333f6c4d72336b84545eb Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Mon, 4 Sep 2023 14:10:55 +0100 Subject: [PATCH 1/3] dispatch to evm --- ismp-demo/src/lib.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/ismp-demo/src/lib.rs b/ismp-demo/src/lib.rs index 21e2fe0..096b3be 100644 --- a/ismp-demo/src/lib.rs +++ b/ismp-demo/src/lib.rs @@ -27,6 +27,7 @@ use ismp::{ module::IsmpModule, router::{Post, Request, Response}, }; +use sp_core::H160; pub use pallet::*; use pallet_ismp::primitives::ModuleId; @@ -189,6 +190,30 @@ pub mod pallet { .map_err(|_| Error::::GetDispatchFailed)?; Ok(()) } + + /// Dispatch request to a connected EVM chain. + #[pallet::weight(Weight::from_parts(1_000_000, 0))] + #[pallet::call_index(2)] + pub fn disptach_to_evm(origin: OriginFor, params: EvmParams) -> DispatchResult { + ensure_signed(origin)?; + + let post = DispatchPost { + dest: params.destination, + from: PALLET_ID.to_bytes(), + to: params.module.0.to_vec(), + timeout_timestamp: params.timeout, + data: b"Hello from polkadot".to_vec(), + gas_limit: 10_000_000, + }; + + // dispatch the request + let dispatcher = T::IsmpDispatcher::default(); + dispatcher + .dispatch_request(DispatchRequest::Post(post)) + .map_err(|_| Error::::TransferFailed)?; + + Ok(()) + } } /// Transfer payload @@ -237,6 +262,21 @@ pub mod pallet { /// Timeout timestamp on destination chain in seconds pub timeout: u64, } + + /// Extrisnic params for evm dispatch + #[derive( + Clone, codec::Encode, codec::Decode, scale_info::TypeInfo, PartialEq, Eq, RuntimeDebug, + )] + pub struct EvmParams { + /// Destination module + pub module: H160, + + /// Destination parachain + pub destination: StateMachine, + + /// Timeout timestamp on destination chain in seconds + pub timeout: u64, + } } /// Module callback for the pallet From f4c74f9a22ab37ab6af7a3153af9eec88eeec059 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Mon, 4 Sep 2023 14:12:27 +0100 Subject: [PATCH 2/3] cargo fmt --- ismp-demo/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ismp-demo/src/lib.rs b/ismp-demo/src/lib.rs index 096b3be..9ecad25 100644 --- a/ismp-demo/src/lib.rs +++ b/ismp-demo/src/lib.rs @@ -27,9 +27,9 @@ use ismp::{ module::IsmpModule, router::{Post, Request, Response}, }; -use sp_core::H160; pub use pallet::*; use pallet_ismp::primitives::ModuleId; +use sp_core::H160; /// Constant Pallet ID pub const PALLET_ID: ModuleId = ModuleId::Pallet(PalletId(*b"ismp-ast")); From f29a265045d6a418eb5472201368cd50ddb00dda Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Mon, 4 Sep 2023 14:16:42 +0100 Subject: [PATCH 3/3] add GH token to protoc step --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a5f8058..eb9f3a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,7 @@ jobs: uses: arduino/setup-protoc@v1 with: version: '3.9.1' + repo-token: ${{ secrets.GH_TOKEN }} - name: Build run: |