2

I see this code used in the Substrate runtime:

pub enum ProxyType {
    Any,
    NonTransfer,
    Governance,
    Staking,
}

impl InstanceFilter<Call> for ProxyType {
    fn filter(&self, c: &Call) -> bool {
        match self {
            ProxyType::Any => true,
            ProxyType::NonTransfer => !matches!(
                c,
                Call::Balances(..) |
                    Call::Assets(..) | Call::Uniques(..) |
                    Call::Vesting(pallet_vesting::Call::vested_transfer { .. }) |
                    Call::Indices(pallet_indices::Call::transfer { .. })
            ),
            ProxyType::Governance => matches!(
                c,
                Call::Democracy(..) |
                    Call::Council(..) | Call::Society(..) |
                    Call::TechnicalCommittee(..) |
                    Call::Elections(..) | Call::Treasury(..)
            ),
            ProxyType::Staking => matches!(c, Call::Staking(..)),
        }
    }
    fn is_superset(&self, o: &Self) -> bool {
        match (self, o) {
            (x, y) if x == y => true,
            (ProxyType::Any, _) => true,
            (_, ProxyType::Any) => false,
            (ProxyType::NonTransfer, _) => true,
            _ => false,
        }
    }
}

How does this work and when should I create one?

1 Answer 1

5

Call filters are used to determine which types of calls are allowed to be made by a particular Origin. In the example you've given, they're being used in the definition of different kinds of proxy accounts to determine which types of calls they're allowed to make on behalf of another account. Proxies and governance are main use-cases of this, but there are others.

A pallet author can use InstanceFilter (which is stateful) or the Contains trait (which is not) to limit the types of calls which can be made.

Oftentimes, chains early in their launch cycle will limit the type of transactions that accounts can make. For instance, when Polkadot was initially launched, a call filter was used prior to the transition to permissionless PoS to prevent balances from being transferred. After the transition to PoS, the call filter was removed by a governance proposal.

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.