Don't panic if parameter can not be converted between node and native runtime (#1659)

* Don't panic if parameter can not be converted between node and native runtime

* FIxes after merge

* Use correct copyright year
This commit is contained in:
Bastian Köcher
2019-02-02 14:13:50 +01:00
committed by Gav Wood
parent 4983f113e6
commit ef4dc12a5d
21 changed files with 216 additions and 67 deletions
+4 -2
View File
@@ -23,8 +23,10 @@
use state_machine;
use serializer;
use wasmi;
use error_chain::{error_chain, error_chain_processing, impl_error_chain_processed,
impl_extract_backtrace, impl_error_chain_kind};
use error_chain::{
error_chain, error_chain_processing, impl_error_chain_processed,
impl_extract_backtrace, impl_error_chain_kind
};
error_chain! {
foreign_links {
@@ -14,8 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use std::borrow::BorrowMut;
use std::cell::{RefMut, RefCell};
use std::{borrow::BorrowMut, result, cell::{RefMut, RefCell}};
use crate::error::{Error, ErrorKind, Result};
use state_machine::{CodeExecutor, Externalities};
use crate::wasm_executor::WasmExecutor;
@@ -109,7 +108,7 @@ fn safe_call<F, U>(f: F) -> Result<U>
///
/// If the inner closure panics, it will be caught and return an error.
pub fn with_native_environment<F, U>(ext: &mut Externalities<Blake2Hasher>, f: F) -> Result<U>
where F: UnwindSafe + FnOnce() -> U
where F: UnwindSafe + FnOnce() -> U
{
::runtime_io::with_externalities(ext, move || safe_call(f))
}
@@ -186,7 +185,7 @@ impl<D: NativeExecutionDispatch> CodeExecutor<Blake2Hasher> for NativeExecutor<D
<
E: Externalities<Blake2Hasher>,
R:Decode + Encode + PartialEq,
NC: FnOnce() -> R + UnwindSafe
NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe
>(
&self,
ext: &mut E,
@@ -242,7 +241,8 @@ impl<D: NativeExecutionDispatch> CodeExecutor<Blake2Hasher> for NativeExecutor<D
.map_or_else(||"<None>".into(), |v| format!("{}", v))
);
(
with_native_environment(ext, move || (call)()).map(NativeOrEncoded::Native),
with_native_environment(ext, move || (call)())
.and_then(|r| r.map(NativeOrEncoded::Native).map_err(Into::into)),
true
)
}