From 87ac3f2edc372104f29e42a889af9e39a29f36d3 Mon Sep 17 00:00:00 2001 From: Nathaniel Bajo <73991674+Nathy-bajo@users.noreply.github.com> Date: Sat, 15 Feb 2025 01:18:28 +0100 Subject: [PATCH] Add view functions to Proxy pallet for runtime-specific type configuration #7297 (#7320) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Solves https://github.com/paritytech/polkadot-sdk/issues/7297 I added a ProxyApi runtime API to the Proxy pallet with two methods: check_permissions: Checks if a RuntimeCall passes a ProxyType's InstanceFilter. is_superset: Verifies if one ProxyType includes another. Polkadot address: 121HJWZtD13GJQPD82oEj3gSeHqsRYm1mFgRALu4L96kfPD1 --------- Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: Bastian Köcher <info@kchr.de> --- .gitignore | 1 + prdoc/pr_7320.prdoc | 14 ++++++++++++++ substrate/frame/proxy/src/lib.rs | 18 +++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 prdoc/pr_7320.prdoc diff --git a/.gitignore b/.gitignore index d4828765708..4fe0701fde6 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ substrate.code-workspace target/ *.scale justfile +rustc-ice-* diff --git a/prdoc/pr_7320.prdoc b/prdoc/pr_7320.prdoc new file mode 100644 index 00000000000..fe918a33211 --- /dev/null +++ b/prdoc/pr_7320.prdoc @@ -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 diff --git a/substrate/frame/proxy/src/lib.rs b/substrate/frame/proxy/src/lib.rs index cc21db7469b..1fe97726172 100644 --- a/substrate/frame/proxy/src/lib.rs +++ b/substrate/frame/proxy/src/lib.rs @@ -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; @@ -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> { -- GitLab