Skip to content

Commit 87ac3f2

Browse files
Nathy-bajobkchr
andauthored
Add view functions to Proxy pallet for runtime-specific type configuration #7297 (#7320)
Solves #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 <[email protected]> Co-authored-by: Bastian Köcher <[email protected]>
1 parent a025562 commit 87ac3f2

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ substrate.code-workspace
4141
target/
4242
*.scale
4343
justfile
44+
rustc-ice-*

prdoc/pr_7320.prdoc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
title: Add view functions to Proxy pallet for runtime-specific type configuration.
2+
3+
doc:
4+
- audience: Runtime User
5+
description: |-
6+
Adds two view functions to `pallet-proxy`:
7+
`check_permissions`: Checks if a given RuntimeCall is allowed for a specific ProxyType
8+
using the InstanceFilter trait.
9+
`is_superset`: Checks if one ProxyType is a superset of another ProxyType by comparing
10+
them using the PartialOrd trait.
11+
12+
crates:
13+
- name: pallet-proxy
14+
bump: minor

substrate/frame/proxy/src/lib.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extern crate alloc;
3737
use alloc::{boxed::Box, vec};
3838
use frame::{
3939
prelude::*,
40-
traits::{Currency, ReservableCurrency},
40+
traits::{Currency, InstanceFilter, ReservableCurrency},
4141
};
4242
pub use pallet::*;
4343
pub use weights::WeightInfo;
@@ -590,6 +590,22 @@ pub mod pallet {
590590
),
591591
ValueQuery,
592592
>;
593+
594+
#[pallet::view_functions_experimental]
595+
impl<T: Config> Pallet<T> {
596+
/// Check if a `RuntimeCall` is allowed for a given `ProxyType`.
597+
pub fn check_permissions(
598+
call: <T as Config>::RuntimeCall,
599+
proxy_type: T::ProxyType,
600+
) -> bool {
601+
proxy_type.filter(&call)
602+
}
603+
604+
/// Check if one `ProxyType` is a subset of another `ProxyType`.
605+
pub fn is_superset(to_check: T::ProxyType, against: T::ProxyType) -> bool {
606+
to_check.is_superset(&against)
607+
}
608+
}
593609
}
594610

595611
impl<T: Config> Pallet<T> {

0 commit comments

Comments
 (0)