Refactor executor.

This commit is contained in:
Gav
2018-01-28 13:48:24 +01:00
parent daa77d09a6
commit bc6eb7d70a
+6 -2
View File
@@ -8,6 +8,10 @@ use runtime_std;
pub struct NativeExecutor;
fn safe_call<F: ::std::panic::UnwindSafe + FnOnce() -> Vec<u8>>(f: F) -> Result<Vec<u8>> {
catch_unwind(f).map_err(|_| ErrorKind::Runtime.into())
}
impl CodeExecutor for NativeExecutor {
type Error = Error;
@@ -23,8 +27,8 @@ impl CodeExecutor for NativeExecutor {
let native_equivalent = include_bytes!("../../wasm-runtime/target/wasm32-unknown-unknown/release/runtime_polkadot.compact.wasm");
if code == &native_equivalent[..] {
runtime_std::with_externalities(ext, || match method {
"execute_block" => catch_unwind(|| runtime::execute_block(&data.0)).map_err(|_| ErrorKind::Runtime.into()),
"execute_transaction" => catch_unwind(|| runtime::execute_transaction(&data.0)).map_err(|_| ErrorKind::Runtime.into()),
"execute_block" => safe_call(|| runtime::execute_block(&data.0)),
"execute_transaction" => safe_call(|| runtime::execute_transaction(&data.0)),
_ => Err(ErrorKind::MethodNotFound(method.to_owned()).into()),
})
} else {