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

dispatch to evm #89

Merged
merged 3 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
uses: arduino/setup-protoc@v1
with:
version: '3.9.1'
repo-token: ${{ secrets.GH_TOKEN }}

- name: Build
run: |
Expand Down
40 changes: 40 additions & 0 deletions ismp-demo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use ismp::{
};
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"));
Expand Down Expand Up @@ -189,6 +190,30 @@ pub mod pallet {
.map_err(|_| Error::<T>::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<T>, 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::<T>::TransferFailed)?;

Ok(())
}
}

/// Transfer payload
Expand Down Expand Up @@ -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
Expand Down