mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 06:41:02 +00:00
Refactor executor.
This commit is contained in:
@@ -8,6 +8,10 @@ use runtime_std;
|
|||||||
|
|
||||||
pub struct NativeExecutor;
|
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 {
|
impl CodeExecutor for NativeExecutor {
|
||||||
type Error = Error;
|
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");
|
let native_equivalent = include_bytes!("../../wasm-runtime/target/wasm32-unknown-unknown/release/runtime_polkadot.compact.wasm");
|
||||||
if code == &native_equivalent[..] {
|
if code == &native_equivalent[..] {
|
||||||
runtime_std::with_externalities(ext, || match method {
|
runtime_std::with_externalities(ext, || match method {
|
||||||
"execute_block" => catch_unwind(|| runtime::execute_block(&data.0)).map_err(|_| ErrorKind::Runtime.into()),
|
"execute_block" => safe_call(|| runtime::execute_block(&data.0)),
|
||||||
"execute_transaction" => catch_unwind(|| runtime::execute_transaction(&data.0)).map_err(|_| ErrorKind::Runtime.into()),
|
"execute_transaction" => safe_call(|| runtime::execute_transaction(&data.0)),
|
||||||
_ => Err(ErrorKind::MethodNotFound(method.to_owned()).into()),
|
_ => Err(ErrorKind::MethodNotFound(method.to_owned()).into()),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user