Skip to content
Snippets Groups Projects
Commit b104f5e6 authored by Gav's avatar Gav
Browse files

Compile polkadot-runtime both for Wasm ad native, allowing for testing and direct usage.

parent 5ab59bb1
No related merge requests found
Showing
with 67 additions and 17 deletions
......@@ -499,6 +499,13 @@ dependencies = [
"ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "native-runtime"
version = "0.1.0"
dependencies = [
"runtime-support 0.1.0",
]
[[package]]
name = "net2"
version = "0.2.31"
......@@ -808,6 +815,10 @@ dependencies = [
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "runtime-support"
version = "0.1.0"
[[package]]
name = "rustc-demangle"
version = "0.1.5"
......
......@@ -16,10 +16,11 @@ members = [
"primitives",
"rpc",
"rpc_servers",
"native-runtime",
"serializer",
"state_machine",
"validator",
]
exclude = [
"runtime"
"wasm-runtime"
]
......@@ -136,7 +136,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
} else { 0 }
} else { 0 }
},
ext_deposit_log(_log_data: *const u8, _log_len: u32) {
ext_deposit_log(_log_data: *const u8, _log_len: u32) => {
unimplemented!()
}
=> <'e, E: Externalities + 'e>
......@@ -175,8 +175,8 @@ impl CodeExecutor for WasmExecutor {
let returned = program
.params_with_external("env", &mut fec)
.map(|p| p
.add_argument(I32(offset as u32))
.add_argument(I32(size as u32)))
.add_argument(I32(offset as i32))
.add_argument(I32(size as i32)))
.and_then(|p| module.execute_export(method, p))
.map_err(|_| -> Error { ErrorKind::Runtime.into() })?;
......@@ -233,8 +233,8 @@ mod tests {
let returned = program
.params_with_external("env", &mut fec)
.map(|p| p
.add_argument(I32(offset as u32))
.add_argument(I32(size as u32)))
.add_argument(I32(offset as i32))
.add_argument(I32(size as i32)))
.and_then(|p| module.execute_export("test_data_in", p))
.map_err(|_| -> Error { ErrorKind::Runtime.into() }).expect("function should be callable");
......
[package]
name = "native-runtime"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
[features]
default = ["with-std"]
with-std = []
without-std = []
[dependencies]
runtime-support = { path = "./support", version = "0.1" }
../wasm-runtime/polkadot/src
\ No newline at end of file
[package]
name = "runtime-support"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
[features]
strict = []
pub use std::vec::Vec;
pub fn storage(_key: &[u8]) -> Vec<u8> { vec![] }
pub fn storage_into<T: Sized>(_key: &[u8]) -> Option<T> { None }
pub fn set_storage(_key: &[u8], _value: &[u8]) {}
#[macro_export]
macro_rules! impl_stubs {
($( $name:ident ),*) => {}
}
File moved
File moved
File moved
File moved
......@@ -8,3 +8,8 @@ crate-type = ["cdylib"]
[dependencies]
runtime-support = { path = "../support", version = "0.1" }
[features]
default = ["without-std"]
with-std = []
without-std = []
#![no_std]
#![feature(lang_items)]
#![cfg_attr(feature = "without-std", no_std)]
#![cfg_attr(feature = "strict", deny(warnings))]
#![feature(alloc)]
extern crate alloc;
use alloc::vec::Vec;
#[macro_use]
extern crate runtime_support;
use runtime_support::{set_storage, storage, storage_into};
use runtime_support::{set_storage, storage, storage_into, Vec};
/// The hash of an ECDSA pub key which is used to identify an external transactor.
pub type AccountID = [u8; 32];
......@@ -116,12 +111,12 @@ fn get_environment() -> EnvironmentHolder {
// TODO: include RLP implementation
// TODO: add keccak256 (or some better hashing scheme) & ECDSA-recover (or some better sig scheme)
fn execute_block(_input: Vec<u8>) -> Vec<u8> {
pub fn execute_block(_input: Vec<u8>) -> Vec<u8> {
let block = Block::from_rlp(&_input);
environment::execute_block(&block)
}
fn execute_transaction(_input: Vec<u8>) -> Vec<u8> {
pub fn execute_transaction(_input: Vec<u8>) -> Vec<u8> {
let tx = Transaction::from_rlp(&_input);
environment::execute_transaction(&tx)
}
......@@ -235,6 +230,11 @@ mod consensus {
unimplemented!()
}
/// The number of blocks in each session.
pub fn session_length() -> BlockNumber {
10
}
/// Sets the session key of `_validator` to `_session`. This doesn't take effect until the next
/// session.
pub fn set_session_key(_validator: AccountID, _session: AccountID) {
......@@ -260,11 +260,14 @@ mod staking {
use super::*;
/// The length of a staking era in blocks.
fn era_length() -> BlockNumber { unimplemented!() }
pub fn era_length() -> BlockNumber { sessions_per_era() * consensus::session_length() }
/// The length of a staking era in sessions.
pub fn sessions_per_era() -> BlockNumber { 10 }
/// The era has changed - enact new staking set.
///
/// NOTE: This is always a session change.
/// NOTE: This always happens on a session change.
fn next_era() { unimplemented!() }
/// The balance of a given account.
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment