4

Is there a way to whitelist a call subset of a pallet? And hide the rest from the end user.

// something like
Pallet { fn call_a(){} fn call_b(){} }; // Some Pallet
...
construct_runtime!(
    pub enum Runtime {
        .....
        Some: pallet_some::{Pallet, Call{call_a}, Storage, Event<T>} = 3
        .....
    }
);
// as a result for an end user only call_a is available
2
  • What are you trying to do more specifically? why do you need it?
    – Nuke
    Dec 16, 2022 at 6:36
  • For example: perhaps you want to have only specific origins to successfully pass an ensure origin check otherwise the call fails, and although not "hidden" (or not actually included in the runtime) it could be non-functional for anyone but specific (or no) origins.
    – Nuke
    Dec 16, 2022 at 6:40

1 Answer 1

4

There is no way to do this.

You can remove the entire Call from the runtime:

construct_runtime! {
   ..
   MyPallet: my_pallet exclude_parts { Call },
   ..
}

This will remove Call and will leave all other parts like Origin, Event etc as part of your runtime.

The only solution to prevent users from calling certain calls of a pallet is to use the BaseCallFilter:

pub struct TestBaseCallFilter;
impl Contains<RuntimeCall> for TestBaseCallFilter {
    fn contains(c: &RuntimeCall) -> bool {
        match *c {
            // Only allow `whatever` and `yes` calls from `MyPallet`.
            RuntimeCall::MyPallet(call) => match call {
                my_pallet::Call::whatever { .. } => true,
                my_pallet::Call::yes { .. } => true,
                _ => false,
            },
            _ => true,
        }
    }
}

These calls will not be "hidden" from the user, but in a "perfect world" a normal user would also use some dedicated app for your runtime. This dedicated app wouldn't provide a way to construct these "forbidden" calls.

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.