It handles transaction payments through what is known as Signed Extensions in Substrate. Basically, a signed extension allows you to perform logic that pertains to validating the transaction received from the network/transaction pool, and also allows you to run some logic before and after an extrinsic is executed. The pre-dispatch method is called before a transaction is executed, and the validate method is called to put it in the Transaction Queue.
In the runtime code you have linked search for the type facilitating this behaviour is :
pallet_asset_tx_payment::ChargeAssetTxPayment<Runtime>
This is basically validating a transaction and computing the fees that should be charged for a transaction. Of interest are these two methods:
fn validate(
&self,
who: &Self::AccountId,
call: &Self::Call,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> TransactionValidity {
let (final_fee, _) = self.withdraw_fee(who, call, info, len)?;
let tip = self.0;
Ok(ValidTransaction {
priority: Self::get_priority(info, len, tip, final_fee),
..Default::default()
})
}
fn pre_dispatch(
self,
who: &Self::AccountId,
call: &Self::Call,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
let (_fee, imbalance) = self.withdraw_fee(who, call, info, len)?;
Ok((self.0, who.clone(), imbalance))
}
Then there is one more piece of the puzzle which is the query_info
method defined inside the pallet. It is used by the transaction payment runtime api to query for the extrinsic weight, runtime extrinsic base weight and current fee multiplier and compute a fee without having knowledge of additional tips and other charges (which will be obtained by the transaction information itself, i.e. the input to the signed extension):
https://github.com/paritytech/substrate/blob/e6768a3bd553ddbed12fe1a0e4a2ef8d4f8fdf52/bin/node/runtime/src/lib.rs#L2031-L2041
Finally,
The actual fee is deducted using a CurrencyAdapter type that is specified at the runtime configuration.
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;