Skip to content

Commit

Permalink
Fix payer account in 'protocolFee.FeeCharged' event. (#1481)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neopallium authored and adamdossa committed Jun 26, 2023
1 parent 01c1f37 commit f1f1bc4
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions pallets/protocol-fee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,24 +190,28 @@ impl<T: Config> Module<T> {
let subsidiser = T::Subsidiser::check_subsidy(&account, fee, None)
.map_err(|_| Error::<T>::InsufficientSubsidyBalance)?;

// Withdraw protocol `fee` from the `account` or their `subsidiser`.
let fee_key = subsidiser.as_ref().unwrap_or(&account);
// `fee_key` is either a subsidiser or the original payer.
let fee_key = if let Some(subsidiser_key) = subsidiser {
// Debit the protocol `fee` from the subsidy if there was a subsidiser.
// This shouldn't fail, since the subsidy was already checked.
T::Subsidiser::debit_subsidy(&account, fee)
.map_err(|_| Error::<T>::InsufficientSubsidyBalance)?;
subsidiser_key
} else {
// No subsidy.
account
};

// Withdraw protocol `fee` from the payer `fee_key.
let ret = T::Currency::withdraw(
fee_key,
&fee_key,
fee,
WithdrawReasons::FEE,
ExistenceRequirement::KeepAlive,
)
.map_err(|_| Error::<T>::InsufficientAccountBalance)?;

// Debit the protocol `fee` from the subsidy if there was a subsidiser.
if subsidiser.is_some() {
// This shouldn't fail, since the subsidy was already checked.
T::Subsidiser::debit_subsidy(&account, fee)
.map_err(|_| Error::<T>::InsufficientSubsidyBalance)?;
}

Self::deposit_event(RawEvent::FeeCharged(account, fee));
Self::deposit_event(RawEvent::FeeCharged(fee_key, fee));
Ok(ret)
}

Expand Down

0 comments on commit f1f1bc4

Please sign in to comment.