Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add view functions to Proxy pallet for runtime-specific type configuration #7297 #7320

Merged
merged 24 commits into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ substrate.code-workspace
target/
*.scale
justfile
rustc-ice-*
14 changes: 14 additions & 0 deletions prdoc/pr_7320.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
title: Add view functions to Proxy pallet for runtime-specific type configuration.

doc:
- audience: Runtime User
description: |-
Adds two view functions to `pallet-proxy`:
`check_permissions`: Checks if a given RuntimeCall is allowed for a specific ProxyType
using the InstanceFilter trait.
`is_superset`: Checks if one ProxyType is a superset of another ProxyType by comparing
them using the PartialOrd trait.

crates:
- name: pallet-proxy
bump: minor
18 changes: 17 additions & 1 deletion substrate/frame/proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern crate alloc;
use alloc::{boxed::Box, vec};
use frame::{
prelude::*,
traits::{Currency, ReservableCurrency},
traits::{Currency, InstanceFilter, ReservableCurrency},
};
pub use pallet::*;
pub use weights::WeightInfo;
Expand Down Expand Up @@ -590,6 +590,22 @@ pub mod pallet {
),
ValueQuery,
>;

#[pallet::view_functions_experimental]
impl<T: Config> Pallet<T> {
/// Check if a `RuntimeCall` is allowed for a given `ProxyType`.
pub fn check_permissions(
call: <T as Config>::RuntimeCall,
proxy_type: T::ProxyType,
) -> bool {
proxy_type.filter(&call)
}

/// Check if one `ProxyType` is a subset of another `ProxyType`.
pub fn is_superset(to_check: T::ProxyType, against: T::ProxyType) -> bool {
to_check.is_superset(&against)
}
}
}

impl<T: Config> Pallet<T> {
Expand Down
Loading