Initial (non-functional) code.

- Kill Externalities Error type requirement.
This commit is contained in:
Gav
2018-01-23 17:27:43 +01:00
parent 68bdf72de7
commit 8ca5c09961
10 changed files with 72 additions and 30 deletions
+34
View File
@@ -0,0 +1,34 @@
use primitives::contract::CallData;
use state_machine::{Externalities, CodeExecutor};
use error::{Error, ErrorKind, Result};
use native_runtime as runtime;
use runtime_support;
struct NativeExecutor;
impl CodeExecutor for NativeExecutor {
type Error = Error;
fn call<E: Externalities>(
&self,
ext: &mut E,
code: &[u8],
method: &str,
data: &CallData,
) -> Result<Vec<u8>> {
// WARNING!!! This assumes that the runtime was built *before* the main project. Until we
// get a proper build script, this must be strictly adhered to or things will go wrong.
let native_equivalent = include_bytes!("../../wasm-runtime/target/wasm32-unknown-unknown/release/runtime_polkadot.compact.wasm");
if code == &native_equivalent[..] {
runtime_support::with_externalities(ext, || match method {
// TODO: Panic handler that comes back with error.
"execute_block" => Ok(runtime::execute_block(data.0)),
"execute_transaction" => Ok(runtime::execute_transaction(data.0)),
_ => Err(ErrorKind::MethodNotFound(method.to_owned()).into()),
})
} else {
// call into wasm.
unimplemented!()
}
}
}