Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-Authored-By: Alex Siman <siman@users.noreply.github.com>
  • Loading branch information
F3Joule and siman committed Mar 29, 2024
1 parent 2dd373c commit ae9c22e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pallets/energy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,15 @@ pub mod pallet {

let fee_without_tip = fee.saturating_sub(tip);
let energy_fee = Self::native_token_to_energy(fee_without_tip);

let energy_consumer = match <T as Config>::RuntimeCall::from_ref(call).is_sub_type() {

let maybe_proxy_call = <T as Config>::RuntimeCall::from_ref(call).is_sub_type();

let energy_provider = match maybe_proxy_call {
Some(pallet_proxy::Call::proxy { real, .. }) => {
let real_account = T::Lookup::lookup(real.clone())?;
if pallet_proxy::Pallet::<T>::find_proxy(&real_account, who, None).is_ok() {
let is_who_a_proxy = pallet_proxy::Pallet::<T>::find_proxy(&real_account, who, None).is_ok();

if is_who_a_proxy {
real_account
} else {
who.clone()
Expand All @@ -385,7 +389,7 @@ pub mod pallet {
};

// if we don't have enough energy then fallback to paying with native token.
if Self::energy_balance(&energy_consumer) < energy_fee/* && real_account_energy < energy_fee*/ {
if Self::energy_balance(&energy_provider) < energy_fee {
return T::NativeOnChargeTransaction::withdraw_fee(
who,
call,
Expand All @@ -407,9 +411,9 @@ pub mod pallet {
.map_err(|_| -> InvalidTransaction { InvalidTransaction::Payment })?;
}

match Self::ensure_can_consume_energy(&energy_consumer, energy_fee) {
match Self::ensure_can_consume_energy(&energy_provider, energy_fee) {
Ok(()) => {
Self::consume_energy(&energy_consumer, energy_fee);
Self::consume_energy(&energy_provider, energy_fee);
Ok(LiquidityInfo::Energy(energy_fee))
},
Err(_) => Err(InvalidTransaction::Payment.into()),
Expand Down

0 comments on commit ae9c22e

Please sign in to comment.