pub fn save<T: Trait>(
	original_code: Vec<u8>,
	gas_meter: &mut GasMeter<T>,
	schedule: &Schedule<T::Gas>,
) -> Result<CodeHash<T>, &'static str> {
	// The first time instrumentation is on the user. However, consequent reinstrumentation
	// due to the schedule changes is on governance system.
	if gas_meter
		.charge(schedule, PutCodeToken(original_code.len() as u64))
		.is_out_of_gas()
	{
		return Err("there is not enough gas for storing the code");
	}

	let prefab_module = prepare::prepare_contract::<T, Env>(&original_code, schedule)?;
	let code_hash = T::Hashing::hash(&original_code);

	// TODO: #1416 validate the code. If the code is not valid, then don't store it.

	<CodeStorage<T>>::insert(code_hash, prefab_module);
	<PristineCode<T>>::insert(code_hash, original_code);

	Ok(code_hash)
}
/// Put code in the storage. The hash of code is used as a key and is returned
/// as a result of this function.
///
/// This function instruments the given code and caches it in the storage.
Put code in the storage. The hash of code is used as a key and is returned
as a result of this function.

This function instruments the given code and caches it in the storage.
Put code in the storage . The hash of code is used as a key and is returned as a result of this function . This function instruments the given code and caches it in the storage .
pub fn save<T: Trait>(
	original_code: Vec<u8>,
	gas_meter: &mut GasMeter<T>,
	schedule: &Schedule<T::Gas>,
) -> Result<CodeHash<T>, &'static str> {
	// The first time instrumentation is on the user. However, consequent reinstrumentation
	// due to the schedule changes is on governance system.
	if gas_meter
		.charge(schedule, PutCodeToken(original_code.len() as u64))
		.is_out_of_gas()
	{
		return Err("there is not enough gas for storing the code");
	}
	let prefab_module = prepare::prepare_contract::<T, Env>(&original_code, schedule)?;
	let code_hash = T::Hashing::hash(&original_code);
	// TODO: #1416 validate the code. If the code is not valid, then don't store it.
	<CodeStorage<T>>::insert(code_hash, prefab_module);
	<PristineCode<T>>::insert(code_hash, original_code);
	Ok(code_hash)
}
pub fn save < T : Trait > ( original_code : Vec < u8 > , gas_meter : & mut GasMeter < T > , schedule : & Schedule < T :: Gas > , ) -> Result < CodeHash < T > , & ' static str > { // The first time instrumentation is on the user. However, consequent reinstrumentation // due to the schedule changes is on governance system. if gas_meter . charge ( schedule , PutCodeToken ( original_code . len ( ) as u64 ) ) . is_out_of_gas ( ) { return Err ( " " ) ; } let prefab_module = prepare :: prepare_contract :: < T , Env > ( & original_code , schedule ) ? ; let code_hash = T :: Hashing :: hash ( & original_code ) ; // TODO: #1416 validate the code. If the code is not valid, then don't store it. < CodeStorage < T > > :: insert ( code_hash , prefab_module ) ; < PristineCode < T > > :: insert ( code_hash , original_code ) ; Ok ( code_hash ) }
Put code in the storage.
Put code in the storage .
original_code
Vec<u8>
gas_meter
&mut GasMeter<T>
schedule
&Schedule<T::Gas>
original_code
Vec<u8>
gas_meter
&mut GasMeter<T>
schedule
&Schedule<T::Gas>