I have a module method that associates fixed fees to Calls from various pallets. So I'm trying to match a Call passed to my method as a parameter by pallet, Call name, and Call parameters.
Something similar to this:
impl<T: Config> Module<T>
{
fn compute_call_fee_(call: &<T as Config>::Call) -> Result<u64, &'static str> {
let fee = match *call {
Call::PalletA(palletA::Call::name_of_palletA_call(x,y)) => 50u64, // here this is not real syntax, this is what I need to figure out
_ => 100u64
};
Ok(fee)
}
}
for the case above the Config trait would implement the Config traits from the different pallets matched on:
pub trait Config: system::Config + palletA::Config + palletB::Config {
type Call: Parameter + Dispatchable<Origin = Self::Origin> + GetDispatchInfo;
}
How can I match on call
by origin pallet, function name, and function arguments ?
I've tried:
using similar syntax as above, without success
making the
Config::Call
implementGetCallMetadata
: this only get me the origin pallet and function name, not the parametersmaking the call implement
IsSubType
, and following this answer: How to decode and match a call when passed as a parameter in Substrate. This is not related to Calls from other pallets if I get it right.For using
IsSubType
, I've added it as a trait bound to the impl block rather than in theConfig
trait:impl<T: Config> Module<T> where <T as Config>::Call: IsSubType<Call<T>>, { fn compute_call_fee_(call: &<T as Config>::Call) -> Result<u64, &'static str> { if let Some(local_call) = call.is_sub_type() { return match local_call { palletA::Call::name_of_palletA_call(x,y) => Ok(42u64), _ => Ok(0u64), } } Ok(21u64) } }