Skip to content

Commit

Permalink
migrate precompile db reads: assets-erc20::eip2612
Browse files Browse the repository at this point in the history
  • Loading branch information
tgmichel committed May 31, 2023
1 parent ffa061b commit 6801477
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions precompiles/assets-erc20/src/eip2612.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use pallet_assets::pallet::{
Instance1, Instance10, Instance11, Instance12, Instance13, Instance14, Instance15, Instance16,
Instance2, Instance3, Instance4, Instance5, Instance6, Instance7, Instance8, Instance9,
};
use parity_scale_codec::MaxEncodedLen;
use scale_info::prelude::string::ToString;
use sp_core::H256;
use sp_io::hashing::keccak_256;
Expand Down Expand Up @@ -129,6 +130,7 @@ where
<Runtime as pallet_timestamp::Config>::Moment: Into<U256>,
AssetIdOf<Runtime, Instance>: Display,
Runtime::AccountId: Into<H160>,
BoundedVec<u8, <Runtime as pallet_assets::Config<Instance>>::StringLimit>: MaxEncodedLen,
{
fn compute_domain_separator(address: H160, asset_id: AssetIdOf<Runtime, Instance>) -> [u8; 32] {
let asset_name = pallet_assets::Pallet::<Runtime, Instance>::name(asset_id);
Expand Down Expand Up @@ -197,7 +199,9 @@ where
r: H256,
s: H256,
) -> EvmResult {
handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;
handle.record_db_read::<Runtime>(
H160::max_encoded_len().saturating_add(U256::max_encoded_len()),
)?;

let owner: H160 = owner.into();
let spender: H160 = spender.into();
Expand Down Expand Up @@ -251,7 +255,9 @@ where
handle: &mut impl PrecompileHandle,
owner: Address,
) -> EvmResult<U256> {
handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;
handle.record_db_read::<Runtime>(
H160::max_encoded_len().saturating_add(U256::max_encoded_len()),
)?;

let owner: H160 = owner.into();

Expand All @@ -264,7 +270,13 @@ where
asset_id: AssetIdOf<Runtime, Instance>,
handle: &mut impl PrecompileHandle,
) -> EvmResult<H256> {
handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;
handle.record_db_read::<Runtime>(
16 + <Runtime as pallet_assets::Config<Instance>>::AssetId::max_encoded_len()
+ pallet_assets::AssetMetadata::<
BalanceOf<Runtime, Instance>,
BoundedVec<u8, <Runtime as pallet_assets::Config<Instance>>::StringLimit>,
>::max_encoded_len(),
)?;

let domain_separator: H256 =
Self::compute_domain_separator(handle.code_address(), asset_id).into();
Expand Down

0 comments on commit 6801477

Please sign in to comment.