Skip to content

Commit

Permalink
feat: apply code suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshvarma committed Oct 25, 2023
1 parent 8abdd65 commit 62d5104
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions chain-extensions/unified-accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ where
GetEvmAddress => {
let account_id: T::AccountId = env.read_as()?;
// charge weight
env.charge_weight(UAWeight::<T>::uam_to_h160())?;
env.charge_weight(UAWeight::<T>::to_h160())?;
// write to buffer
UA::to_h160(&account_id).using_encoded(|r| env.write(r, false, None))?;
}
GetEvmAddressOrDefault => {
let account_id: T::AccountId = env.read_as()?;
// charge weight
env.charge_weight(UAWeight::<T>::uam_to_h160_or_default())?;
env.charge_weight(UAWeight::<T>::to_h160_or_default())?;

let evm_address = if let Some(h160) = UA::to_h160(&account_id) {
UnifiedAddress::Mapped(h160)
Expand All @@ -78,14 +78,14 @@ where
GetNativeAddress => {
let evm_address: EvmAddress = env.read_as()?;
// charge weight
env.charge_weight(UAWeight::<T>::uam_to_account_id())?;
env.charge_weight(UAWeight::<T>::to_account_id())?;
// write to buffer
UA::to_account_id(&evm_address).using_encoded(|r| env.write(r, false, None))?;
}
GetNativeAddressOrDefault => {
let evm_address: EvmAddress = env.read_as()?;
// charge weight
env.charge_weight(UAWeight::<T>::uam_to_account_id_or_default())?;
env.charge_weight(UAWeight::<T>::to_account_id_or_default())?;

// read the storage item
let native_address = if let Some(native) = UA::to_account_id(&evm_address) {
Expand Down
2 changes: 1 addition & 1 deletion chain-extensions/xvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ where
if value > 0 {
// `UA::to_h160`.
actual_weight.saturating_accrue(
<T as pallet_unified_accounts::Config>::WeightInfo::uam_to_h160(),
<T as pallet_unified_accounts::Config>::WeightInfo::to_h160(),
);

if UA::to_h160(&source).is_none() {
Expand Down
8 changes: 4 additions & 4 deletions pallets/unified-accounts/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod benchmarks {
}

#[benchmark]
fn uam_to_account_id() {
fn to_account_id() {
let caller: T::AccountId = whitelisted_caller();
let evm_address = T::DefaultNativeToEvm::into_h160(caller.clone());
// claim mapping
Expand All @@ -100,7 +100,7 @@ mod benchmarks {
}

#[benchmark]
fn uam_to_account_id_or_default() {
fn to_account_id_or_default() {
let caller: T::AccountId = whitelisted_caller();
let evm_address = T::DefaultNativeToEvm::into_h160(caller.clone());
// claim mapping
Expand All @@ -117,7 +117,7 @@ mod benchmarks {
}

#[benchmark]
fn uam_to_h160() {
fn to_h160() {
let caller: T::AccountId = whitelisted_caller();
// claim mapping
assert_ok!(Pallet::<T>::claim_default_evm_address(
Expand All @@ -131,7 +131,7 @@ mod benchmarks {
}

#[benchmark]
fn uam_to_h160_or_default() {
fn to_h160_or_default() {
let caller: T::AccountId = whitelisted_caller();
// claim mapping
assert_ok!(Pallet::<T>::claim_default_evm_address(
Expand Down
24 changes: 12 additions & 12 deletions pallets/unified-accounts/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ use core::marker::PhantomData;
pub trait WeightInfo {
fn claim_evm_address() -> Weight;
fn claim_default_evm_address() -> Weight;
fn uam_to_account_id() -> Weight;
fn uam_to_account_id_or_default() -> Weight;
fn uam_to_h160() -> Weight;
fn uam_to_h160_or_default() -> Weight;
fn to_account_id() -> Weight;
fn to_account_id_or_default() -> Weight;
fn to_h160() -> Weight;
fn to_h160_or_default() -> Weight;
}

/// Weights for pallet_unified_accounts using the Substrate node and recommended hardware.
Expand Down Expand Up @@ -94,7 +94,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
}
/// Storage: UnifiedAccounts EvmToNative (r:1 w:0)
/// Proof: UnifiedAccounts EvmToNative (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
fn uam_to_account_id() -> Weight {
fn to_account_id() -> Weight {
// Proof Size summary in bytes:
// Measured: `170`
// Estimated: `3533`
Expand All @@ -104,7 +104,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
}
/// Storage: UnifiedAccounts EvmToNative (r:1 w:0)
/// Proof: UnifiedAccounts EvmToNative (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
fn uam_to_account_id_or_default() -> Weight {
fn to_account_id_or_default() -> Weight {
// Proof Size summary in bytes:
// Measured: `170`
// Estimated: `3533`
Expand All @@ -114,7 +114,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
}
/// Storage: UnifiedAccounts NativeToEvm (r:1 w:0)
/// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
fn uam_to_h160() -> Weight {
fn to_h160() -> Weight {
// Proof Size summary in bytes:
// Measured: `170`
// Estimated: `3533`
Expand All @@ -124,7 +124,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
}
/// Storage: UnifiedAccounts NativeToEvm (r:1 w:0)
/// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
fn uam_to_h160_or_default() -> Weight {
fn to_h160_or_default() -> Weight {
// Proof Size summary in bytes:
// Measured: `170`
// Estimated: `3533`
Expand Down Expand Up @@ -170,7 +170,7 @@ impl WeightInfo for () {
}
/// Storage: UnifiedAccounts EvmToNative (r:1 w:0)
/// Proof: UnifiedAccounts EvmToNative (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
fn uam_to_account_id() -> Weight {
fn to_account_id() -> Weight {
// Proof Size summary in bytes:
// Measured: `170`
// Estimated: `3533`
Expand All @@ -180,7 +180,7 @@ impl WeightInfo for () {
}
/// Storage: UnifiedAccounts EvmToNative (r:1 w:0)
/// Proof: UnifiedAccounts EvmToNative (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
fn uam_to_account_id_or_default() -> Weight {
fn to_account_id_or_default() -> Weight {
// Proof Size summary in bytes:
// Measured: `170`
// Estimated: `3533`
Expand All @@ -190,7 +190,7 @@ impl WeightInfo for () {
}
/// Storage: UnifiedAccounts NativeToEvm (r:1 w:0)
/// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
fn uam_to_h160() -> Weight {
fn to_h160() -> Weight {
// Proof Size summary in bytes:
// Measured: `170`
// Estimated: `3533`
Expand All @@ -200,7 +200,7 @@ impl WeightInfo for () {
}
/// Storage: UnifiedAccounts NativeToEvm (r:1 w:0)
/// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
fn uam_to_h160_or_default() -> Weight {
fn to_h160_or_default() -> Weight {
// Proof Size summary in bytes:
// Measured: `170`
// Estimated: `3533`
Expand Down

0 comments on commit 62d5104

Please sign in to comment.