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

Pallet view functions: improve metadata, API docs and testing #7412

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

re-gius
Copy link
Contributor

@re-gius re-gius commented Jan 31, 2025

@re-gius re-gius self-assigned this Jan 31, 2025
@re-gius re-gius added T1-FRAME This PR/Issue is related to core FRAME, the framework. T4-runtime_API This PR/Issue is related to runtime APIs. labels Jan 31, 2025
@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/13138990543
Failed job name: test-linux-stable-no-try-runtime

@re-gius
Copy link
Contributor Author

re-gius commented Feb 4, 2025

/cmd prdoc --audience runtime_dev --bump patch

@re-gius re-gius marked this pull request as ready for review February 4, 2025 17:24
@re-gius re-gius requested a review from a team as a code owner February 4, 2025 17:24
@re-gius re-gius requested a review from jsdw February 4, 2025 17:24

#[pallet::view_functions_experimental]
impl<T: Config> Pallet<T> {
fn get_value() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn get_value() {
pub fn get_value() {

@@ -212,6 +179,8 @@ pub struct PalletMetadataIR<T: Form = MetaForm> {
pub storage: Option<PalletStorageMetadataIR<T>>,
/// Pallet calls metadata.
pub calls: Option<PalletCallMetadataIR<T>>,
/// Pallet view functions metadata.
pub view_functions: Vec<PalletViewFunctionMethodMetadataIR<T>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a note, moving the view functions to pallet means we can't keep the same view function when pallets are reorganizing, merging or splitting.

@@ -63,6 +63,12 @@ impl From<codec::Error> for ViewFunctionDispatchError {
/// Implemented by both pallets and the runtime. The runtime is dispatching by prefix using the
/// pallet implementation of `ViewFunctionIdPrefix` then the pallet is dispatching by suffix using
/// the methods implementation of `ViewFunctionIdSuffix`.
///
/// More in details, `ViewFunctionId` = `ViewFunctionIdPrefix` ++ `ViewFunctionIdSuffix`, where
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// More in details, `ViewFunctionId` = `ViewFunctionIdPrefix` ++ `ViewFunctionIdSuffix`, where
/// In more details, `ViewFunctionId` = `ViewFunctionIdPrefix` ++ `ViewFunctionIdSuffix`, where

Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no opinion on whether view functions should be defined in the pallets or in the runtime.

Having it in the runtime could allow some more stable view functions for the runtime when pallets are reorganizing/merging/splitting. But at the same time I don't expect people writing runtime to implement the view functions themself in order to maintain the view functions.

Apart from this the code is good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T1-FRAME This PR/Issue is related to core FRAME, the framework. T4-runtime_API This PR/Issue is related to runtime APIs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants