Repository: paritytech/substrate
File: frame/contracts/src/wasm/runtime.rs (Rust)

Code before:
	EcdsaRecovery,
	/// Weight charged by a chain extension through `seal_call_chain_extension`.
	ChainExtension(u64),
	/// Weight charged for calling into the runtime.
	CallRuntime(Weight),
	/// Weight of calling `seal_set_code_hash`
	SetCodeHash,
	/// Weight of calling `ecdsa_to_eth_address`
	EcdsaToEthAddress,
	/// Weight of calling `reentrance_count`
	ReentrantCount,
	/// Weight of calling `account_reentrance_count`
	AccountEntranceCount,
	/// Weight of calling `instantiation_nonce`
	InstantationNonce,
}

impl RuntimeCosts {
	fn token<T>(&self, s: &HostFnWeights<T>) -> RuntimeToken
	where
		T: Config,
		T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
	{
		use self::RuntimeCosts::*;
		let weight = match *self {
			MeteringBlock(amount) => Weight::from_ref_time(s.gas.saturating_add(amount)),
			CopyFromContract(len) =>
				Weight::from_ref_time(s.return_per_byte.saturating_mul(len.into())),
			CopyToContract(len) =>
				Weight::from_ref_time(s.input_per_byte.saturating_mul(len.into())),
			Caller => Weight::from_ref_time(s.caller),
			IsContract => Weight::from_ref_time(s.is_contract),
			CodeHash => Weight::from_ref_time(s.code_hash),
			OwnCodeHash => Weight::from_ref_time(s.own_code_hash),
			CallerIsOrigin => Weight::from_ref_time(s.caller_is_origin),
			Address => Weight::from_ref_time(s.address),
			GasLeft => Weight::from_ref_time(s.gas_left),
			Balance => Weight::from_ref_time(s.balance),
			ValueTransferred => Weight::from_ref_time(s.value_transferred),
			MinimumBalance => Weight::from_ref_time(s.minimum_balance),
			BlockNumber => Weight::from_ref_time(s.block_number),
			Now => Weight::from_ref_time(s.now),
			WeightToFee => Weight::from_ref_time(s.weight_to_fee),
			InputBase => Weight::from_ref_time(s.input),
			Return(len) => Weight::from_ref_time(
				s.r#return.saturating_add(s.return_per_byte.saturating_mul(len.into())),
			),
			Terminate => Weight::from_ref_time(s.terminate),
			Random => Weight::from_ref_time(s.random),
			DepositEvent { num_topic, len } => Weight::from_ref_time(
				s.deposit_event

Review comment (suggestion):
can't we wrap `weight` after:

```rust
let (weight, proof_size) = match *self {
    // ....
}
let weight = Weight::from_ref_time(weight)
if proof_size != 0 {
    weight.set_proof_size(proof_size)
}
```

Code after:
	/// Weight charged by a chain extension through `seal_call_chain_extension`.
	ChainExtension(Weight),
	/// Weight charged for calling into the runtime.
	CallRuntime(Weight),
	/// Weight of calling `seal_set_code_hash`
	SetCodeHash,
	/// Weight of calling `ecdsa_to_eth_address`
	EcdsaToEthAddress,
	/// Weight of calling `reentrance_count`
	ReentrantCount,
	/// Weight of calling `account_reentrance_count`
	AccountEntranceCount,
	/// Weight of calling `instantiation_nonce`
	InstantationNonce,
}

impl RuntimeCosts {
	fn token<T: Config>(&self, s: &HostFnWeights<T>) -> RuntimeToken {
		use self::RuntimeCosts::*;
		let weight = match *self {
			MeteringBlock(amount) => s.gas.saturating_add(Weight::from_ref_time(amount)),
			CopyFromContract(len) => s.return_per_byte.saturating_mul(len.into()),
			CopyToContract(len) => s.input_per_byte.saturating_mul(len.into()),
			Caller => s.caller,
			IsContract => s.is_contract,
			CodeHash => s.code_hash,
			OwnCodeHash => s.own_code_hash,
			CallerIsOrigin => s.caller_is_origin,
			Address => s.address,
			GasLeft => s.gas_left,
			Balance => s.balance,
			ValueTransferred => s.value_transferred,
			MinimumBalance => s.minimum_balance,
			BlockNumber => s.block_number,
			Now => s.now,
			WeightToFee => s.weight_to_fee,
			InputBase => s.input,
			Return(len) => s.r#return.saturating_add(s.return_per_byte.saturating_mul(len.into())),
			Terminate => s.terminate,
			Random => s.random,
			DepositEvent { num_topic, len } => s
				.deposit_event
				.saturating_add(s.deposit_event_per_topic.saturating_mul(num_topic.into()))
				.saturating_add(s.deposit_event_per_byte.saturating_mul(len.into())),
			DebugMessage => s.debug_message,
			SetStorage { new_bytes, old_bytes } => s
				.set_storage
				.saturating_add(s.set_storage_per_new_byte.saturating_mul(new_bytes.into()))
				.saturating_add(s.set_storage_per_old_byte.saturating_mul(old_bytes.into())),
			ClearStorage(len) => s
				.clear_storage