fn call_in_wasm_module_with_custom_signature<
		E: Externalities<Blake2Hasher>,
		F: FnOnce(&mut FnMut(&[u8]) -> Result<u32>) -> Result<Vec<RuntimeValue>>,
		FR: FnOnce(Option<RuntimeValue>, &MemoryRef) -> Result<Option<R>>,
		R,
	>(
		&self,
		ext: &mut E,
		module_instance: &ModuleRef,
		method: &str,
		create_parameters: F,
		filter_result: FR,
	) -> Result<R> {
		// extract a reference to a linear memory, optional reference to a table
		// and then initialize FunctionExecutor.
		let memory = Self::get_mem_instance(module_instance)?;
		let table: Option<TableRef> = module_instance
			.export_by_name("__indirect_function_table")
			.and_then(|e| e.as_table().cloned());

		let low = memory.lowest_used();
		let used_mem = memory.used_size();
		let mut fec = FunctionExecutor::new(memory.clone(), table, ext)?;
		let parameters = create_parameters(&mut |data: &[u8]| {
			let offset = fec.heap.allocate(data.len() as u32).map_err(|_| ErrorKind::Runtime)?;
			memory.set(offset, &data)?;
			Ok(offset)
		})?;

		let result = module_instance.invoke_export(
			method,
			&parameters,
			&mut fec
		);
		let result = match result {
			Ok(val) => match filter_result(val, &memory)? {
				Some(val) => Ok(val),
				None => Err(ErrorKind::InvalidReturn.into()),
			},
			Err(e) => {
				trace!(target: "wasm-executor", "Failed to execute code with {} pages", memory.current_size().0);
				Err(e.into())
			},
		};

		// cleanup module instance for next use
		let new_low = memory.lowest_used();
		if new_low < low {
			memory.zero(new_low as usize, (low - new_low) as usize)?;
			memory.reset_lowest_used(low);
		}
		memory.with_direct_access_mut(|buf| buf.resize(used_mem.0, 0));
		result
	}
/// Call a given method in the given wasm-module runtime.
Call a given method in the given wasm-module runtime.
Call a given method in the given wasm - module runtime .
fn call_in_wasm_module_with_custom_signature<
		E: Externalities<Blake2Hasher>,
		F: FnOnce(&mut FnMut(&[u8]) -> Result<u32>) -> Result<Vec<RuntimeValue>>,
		FR: FnOnce(Option<RuntimeValue>, &MemoryRef) -> Result<Option<R>>,
		R,
	>(
		&self,
		ext: &mut E,
		module_instance: &ModuleRef,
		method: &str,
		create_parameters: F,
		filter_result: FR,
	) -> Result<R> {
		// extract a reference to a linear memory, optional reference to a table
		// and then initialize FunctionExecutor.
		let memory = Self::get_mem_instance(module_instance)?;
		let table: Option<TableRef> = module_instance
			.export_by_name("__indirect_function_table")
			.and_then(|e| e.as_table().cloned());
		let low = memory.lowest_used();
		let used_mem = memory.used_size();
		let mut fec = FunctionExecutor::new(memory.clone(), table, ext)?;
		let parameters = create_parameters(&mut |data: &[u8]| {
			let offset = fec.heap.allocate(data.len() as u32).map_err(|_| ErrorKind::Runtime)?;
			memory.set(offset, &data)?;
			Ok(offset)
		})?;
		let result = module_instance.invoke_export(
			method,
			&parameters,
			&mut fec
		);
		let result = match result {
			Ok(val) => match filter_result(val, &memory)? {
				Some(val) => Ok(val),
				None => Err(ErrorKind::InvalidReturn.into()),
			},
			Err(e) => {
				trace!(target: "wasm-executor", "Failed to execute code with {} pages", memory.current_size().0);
				Err(e.into())
			},
		};
		// cleanup module instance for next use
		let new_low = memory.lowest_used();
		if new_low < low {
			memory.zero(new_low as usize, (low - new_low) as usize)?;
			memory.reset_lowest_used(low);
		}
		memory.with_direct_access_mut(|buf| buf.resize(used_mem.0, 0));
		result
	}
fn call_in_wasm_module_with_custom_signature < E : Externalities < Blake2Hasher > , F : FnOnce ( & mut FnMut ( & [ u8 ] ) -> Result < u32 > ) -> Result < Vec < RuntimeValue > > , FR : FnOnce ( Option < RuntimeValue > , & MemoryRef ) -> Result < Option < R > > , R , > ( & self , ext : & mut E , module_instance : & ModuleRef , method : & str , create_parameters : F , filter_result : FR , ) -> Result < R > { // extract a reference to a linear memory, optional reference to a table // and then initialize FunctionExecutor. let memory = Self :: get_mem_instance ( module_instance ) ? ; let table : Option < TableRef > = module_instance . export_by_name ( " " ) . and_then ( | e | e . as_table ( ) . cloned ( ) ) ; let low = memory . lowest_used ( ) ; let used_mem = memory . used_size ( ) ; let mut fec = FunctionExecutor :: new ( memory . clone ( ) , table , ext ) ? ; let parameters = create_parameters ( & mut | data : & [ u8 ] | { let offset = fec . heap . allocate ( data . len ( ) as u32 ) . map_err ( | _ | ErrorKind :: Runtime ) ? ; memory . set ( offset , & data ) ? ; Ok ( offset ) } ) ? ; let result = module_instance . invoke_export ( method , & parameters , & mut fec ) ; let result = match result { Ok ( val ) => match filter_result ( val , & memory ) ? { Some ( val ) => Ok ( val ) , None => Err ( ErrorKind :: InvalidReturn . into ( ) ) , } , Err ( e ) => { trace ! ( target " " " " memory current_size ( ) 0 ) ; Err ( e . into ( ) ) } , } ; // cleanup module instance for next use let new_low = memory . lowest_used ( ) ; if new_low < low { memory . zero ( new_low as usize , ( low - new_low ) as usize ) ? ; memory . reset_lowest_used ( low ) ; } memory . with_direct_access_mut ( | buf | buf . resize ( used_mem . 0 , 0 ) ) ; result }
Call a given method in the given wasm-module runtime.
Call a given method in the given wasm - module runtime .
&self
ext
&mut E
module_instance
&ModuleRef
method
&str
create_parameters
F
filter_result
FR
&self
ext
&mut E
module_instance
&ModuleRef
method
&str
create_parameters
F
filter_result
FR