From b3931d3e2a98272f76913e25892a0eed7b09d34b Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 3 Apr 2019 10:59:03 +0100 Subject: [PATCH] Remove redundant Ok(()) and explicitly specify StorageKey buffer type (#2188) --- substrate/srml/contract/src/wasm/runtime.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/substrate/srml/contract/src/wasm/runtime.rs b/substrate/srml/contract/src/wasm/runtime.rs index ffd8c9894e..37ab9fa887 100644 --- a/substrate/srml/contract/src/wasm/runtime.rs +++ b/substrate/srml/contract/src/wasm/runtime.rs @@ -17,7 +17,7 @@ //! Environment definition of the wasm smart-contract runtime. use crate::{Schedule, Trait, CodeHash, ComputeDispatchFee, BalanceOf}; -use crate::exec::{Ext, VmExecResult, OutputBuf, EmptyOutputBuf, CallReceipt, InstantiateReceipt}; +use crate::exec::{Ext, VmExecResult, OutputBuf, EmptyOutputBuf, CallReceipt, InstantiateReceipt, StorageKey}; use crate::gas::{GasMeter, Token, GasMeterResult, approx_gas_for_balance}; use sandbox; use system; @@ -192,9 +192,7 @@ fn read_sandbox_memory_into_buf( ) -> Result<(), sandbox::HostError> { charge_gas(ctx.gas_meter, ctx.schedule, RuntimeToken::ReadMemory(buf.len() as u32))?; - ctx.memory().get(ptr, buf)?; - - Ok(()) + ctx.memory().get(ptr, buf).map_err(Into::into) } /// Write the given buffer to the designated location in the sandbox memory, consuming @@ -248,7 +246,7 @@ define_env!(Env, , // where the value to set is placed. If `value_non_null` is set to 0, then this parameter is ignored. // - value_len: the length of the value. If `value_non_null` is set to 0, then this parameter is ignored. ext_set_storage(ctx, key_ptr: u32, value_non_null: u32, value_ptr: u32, value_len: u32) => { - let mut key = [0; 32]; + let mut key: StorageKey = [0; 32]; read_sandbox_memory_into_buf(ctx, key_ptr, &mut key)?; let value = if value_non_null != 0 { @@ -268,7 +266,7 @@ define_env!(Env, , // - key_ptr: pointer into the linear memory where the key // of the requested value is placed. ext_get_storage(ctx, key_ptr: u32) -> u32 => { - let mut key = [0; 32]; + let mut key: StorageKey = [0; 32]; read_sandbox_memory_into_buf(ctx, key_ptr, &mut key)?; if let Some(value) = ctx.ext.get_storage(&key) { ctx.scratch_buf = value;