0

I’m developing a Substrate-based blockchain and I want to create a pallet that intercepts all runtime calls. I have created a pallet that accepts a runtime call as a parameter, but it doesn’t intercept all calls as expected. How can I ensure that every call is funneled through my pallet? I can manually call my extrinsic and pass another runtime call into it, but I want all calls automatically be funneled into that extrinsic.

I followed an approach similar to the feeless pallet by Shawn, as demonstrated in this video. However, while his implementation works, mine does not. Below is the relevant part of my code.

pallet:

pub use pallet::*;
use frame_support::dispatch::GetDispatchInfo;
use frame_support::traits::UnfilteredDispatchable;
use scale_info::prelude::boxed::Box;
use frame_support::dispatch::PostDispatchInfo;
use sp_runtime::traits::Dispatchable;

#[pallet::config(with_default)]
pub trait Config: frame_system::Config {
    #[pallet::no_default_bounds]
    type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

    #[pallet::no_default_bounds]
    type RuntimeCall: Parameter
    + Dispatchable<RuntimeOrigin = Self::RuntimeOrigin>
    + From<Call<Self>>;

    type WeightInfo: WeightInfo;

}

#[pallet::call]
impl<T: Config> Pallet<T> {
    #[pallet::call_index(0)]
    #[pallet::weight(T::WeightInfo::intercept())]
    pub fn intercept(
        origin: OriginFor<T>,
        call: Box<<T as Config>::RuntimeCall>,
    ) -> DispatchResultWithPostInfo {
        let _res = call.dispatch(origin);
        Self::deposit_event(Event::Intercepted);
...
    }
}

runtime:

impl pallet_interceptor::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type WeightInfo = pallet_interceptor::weights::SubstrateWeight<Runtime>;
}


construct_runtime!(
pub enum Runtime {
    System: frame_system,
    Timestamp: pallet_timestamp,
    Aura: pallet_aura,
    Grandpa: pallet_grandpa,
    Balances: pallet_balances,
    TransactionPayment: pallet_transaction_payment,
    Sudo: pallet_sudo,
    Identity: pallet_identity,
    Collective: pallet_collective::<Instance1>,
    Membership: pallet_membership,
    Preimage: pallet_preimage,
    Scheduler: pallet_scheduler,
    Bounties: pallet_bounties,
    Treasury: pallet_treasury,
    Nfts: pallet_nfts,
    Democracy: pallet_democracy,
    Interceptor: pallet_interceptor,
}
);

1 Answer 1

1

I don't think that video will work either. It only sets up a call for the user to make and cannot intercept any runtime calls if the user interacts with other pallets.

safe-mode pallet might be a good template for you.

In this way, it captures the runtime calls by being set up as a system hook.


If you just want the first method shown in the video, the utility pallet is the best template for you.

2
  • Thank you very much! Commented Jun 14 at 18:51
  • If this solved your problem please mark it as the answer, thanks.
    – AurevoirXavier
    Commented Jun 14 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.