Skip to content

Commit

Permalink
Test host functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tgmichel committed May 11, 2021
1 parent 42b97b6 commit c5f5466
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ tokio = { version = "0.2.13", features = ["macros", "sync"] }
moonbeam-runtime = { path = "../runtime" }
moonbeam-rpc-txpool = { path = "../client/rpc/txpool" }
moonbeam-rpc-primitives-txpool = { path = "../primitives/rpc/txpool" }
moonbeam-primitives-ext = { path = "../primitives/ext" }
moonbeam-rpc-debug = { path = "../client/rpc/debug" }
moonbeam-rpc-primitives-debug = { path = "../primitives/rpc/debug" }
moonbeam-rpc-trace = { path = "../client/rpc/trace" }
Expand Down
3 changes: 2 additions & 1 deletion node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ native_executor_instance!(
pub Executor,
moonbeam_runtime::api::dispatch,
moonbeam_runtime::native_version,
frame_benchmarking::benchmarking::HostFunctions,
// Make the executor aware of the custom host functions.
(frame_benchmarking::benchmarking::HostFunctions, moonbeam_primitives_ext::moonbeam_ext::HostFunctions),
);
use sc_telemetry::{Telemetry, TelemetryWorker, TelemetryWorkerHandle};

Expand Down
19 changes: 19 additions & 0 deletions primitives/ext/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "moonbeam-primitives-ext"
version = '0.1.0'
authors = ['PureStake']
edition = '2018'
homepage = 'https://moonbeam.network'
license = 'GPL-3.0-only'
repository = 'https://github.com/PureStake/moonbeam/'

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
sp-runtime-interface = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1",default-features = false }

[features]
default = ["std"]
std = [
"sp-runtime-interface/std",
]
10 changes: 10 additions & 0 deletions primitives/ext/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![cfg_attr(not(feature = "std"), no_std)]

use sp_runtime_interface::runtime_interface;

#[runtime_interface]
pub trait MoonbeamExt {
fn foo() {
println!("Called from the runtime!");
}
}
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pallet-collective = { git = "https://github.com/paritytech/substrate", default-f
moonbeam-extensions-evm = { path = "extensions/evm", default-features = false }
moonbeam-rpc-primitives-debug = { path = "../primitives/rpc/debug", default-features = false }
moonbeam-rpc-primitives-txpool = { path = "../primitives/rpc/txpool", default-features = false }
moonbeam-primitives-ext = { path = "../primitives/ext", default-features = false }

# Cumulus dependencies
cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "rococo-v1" }
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,8 @@ impl_runtime_apis! {

impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {
fn chain_id() -> u64 {
// Just find some place in the runtime to call it.
moonbeam_primitives_ext::moonbeam_ext::foo();
<Runtime as pallet_evm::Config>::ChainId::get()
}

Expand Down

0 comments on commit c5f5466

Please sign in to comment.