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

Commit

Permalink
dispatch to evm (#89)
Browse files Browse the repository at this point in the history
* dispatch to evm

* cargo fmt

* add GH token to protoc step
  • Loading branch information
seunlanlege authored Sep 4, 2023
1 parent 4b5c465 commit 57a2465
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
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

0 comments on commit 57a2465

Please sign in to comment.