Refactor executor.
@@ -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 {
