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

Refactor executor.

parent daa77d09
No related merge requests found
......@@ -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 {
......
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