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

Implement pallet view function queries #4722

Open
wants to merge 139 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
264b902
Add view functions parsing and definition
ascjones May 20, 2024
987802c
Add to view functions mod definition
ascjones May 20, 2024
4f7a513
Adding traits and types and wiring up expansion
ascjones May 21, 2024
e8af3c2
Use ToTokens for expansion
ascjones May 22, 2024
7038710
fmtl
ascjones May 22, 2024
9267519
Adding generics etc to query struct
ascjones May 22, 2024
c6a4e42
fmt
ascjones May 22, 2024
140f7d9
example with args
ascjones May 23, 2024
23b9ebf
add example for testing
ascjones May 23, 2024
86c5f2f
wire up codegen for view functions
ascjones May 24, 2024
f42c5c4
Generate DispatchQuery impl
ascjones May 24, 2024
ac6643e
Wire up runtime PalletQuery
ascjones May 24, 2024
2ea6158
Wire up query args
ascjones May 28, 2024
8b56a84
Add get value with args query
ascjones May 28, 2024
06f9ffc
decode_all
ascjones May 29, 2024
9ed181b
Merge branch 'master' into aj/view-functions
ascjones May 29, 2024
cd52010
Docs
ascjones May 30, 2024
44707b3
Generate suffix from view_fn signature
ascjones May 30, 2024
afa1490
separate suffix id
ascjones May 30, 2024
f97a40c
WIP expand runtime level query
ascjones May 30, 2024
ddff4d0
Implement `DispatchQuery` for pallets even without queries
ascjones May 31, 2024
538ea8a
WIP
ascjones May 31, 2024
db616f5
Use pallet name hash as query id prefix
ascjones Jun 3, 2024
fd3318b
Commented out code
ascjones Jun 3, 2024
a49e5f3
Inject runtime type
ascjones Jun 3, 2024
dd651ac
tidy
ascjones Jun 3, 2024
c7ff6c9
Add pallet with instances
ascjones Jun 3, 2024
5a8e559
Pallet instances tests
ascjones Jun 3, 2024
e71b9de
Refactor tests
ascjones Jun 3, 2024
22dd94b
Move execute from codegen to trait
ascjones Jun 4, 2024
117ac87
WIP query runtime api
ascjones Jun 4, 2024
def7807
WIP query metadata
ascjones Jun 5, 2024
fbd4d3a
Fix up metadata generation
ascjones Jun 5, 2024
04d763e
Add queries section to custom metadata
ascjones Jun 6, 2024
86f35eb
Comment
ascjones Jun 6, 2024
885fd3a
fix metadata gen
ascjones Jun 6, 2024
3b563fb
move runtime api and core types to primitives
ascjones Jun 6, 2024
43de841
Add some RuntimeQuery types
ascjones Jun 7, 2024
ebcf283
Fix up westend runtime
ascjones Jun 7, 2024
f0b1f36
Add RuntimeQuery derives
ascjones Jun 7, 2024
c6dd8a5
Wire up runtime API query methods
ascjones Jun 7, 2024
81150ba
Use Runtime::execute_query generated method
ascjones Jun 7, 2024
11cb3db
Fmt
ascjones Jun 7, 2024
18b7deb
Merge branch 'master' into aj/view-functions
ascjones Jun 7, 2024
21eeba7
Merge branch 'master' into aj/view-functions
ascjones Jun 7, 2024
7b82da6
Master.into()
kianenigma Oct 8, 2024
fd0896c
Merge branch 'master' into aj/view-functions
ascjones Oct 9, 2024
0bf818a
Merge branch 'master' into aj/view-functions
jsdw Nov 7, 2024
7c71b8a
Rename `view_functions` to `view_functions_experimental`
ascjones Nov 8, 2024
60d78fc
Remove Vec import
ascjones Nov 8, 2024
19d6f65
Resore Vec import
ascjones Nov 8, 2024
f8e9d2b
Merge branch 'master' into aj/view-functions
ascjones Nov 21, 2024
b93cbf4
QueryDispatchError -> ViewFunctionDispatchError
ascjones Nov 21, 2024
b58b9ae
query -> view function naming WIP
ascjones Nov 21, 2024
c2c3883
query -> view function naming WIP
ascjones Nov 21, 2024
0e92e5b
query -> view function naming
ascjones Nov 21, 2024
62674bd
fmt
ascjones Nov 21, 2024
bb35aa4
query -> view function renaming WIP
ascjones Nov 22, 2024
f5c498e
query -> view function renaming WIP
ascjones Nov 22, 2024
6acc73f
more query -> view function renaming
ascjones Nov 22, 2024
282ce5e
more query -> view function renaming
ascjones Nov 22, 2024
39d6e35
fmt
ascjones Nov 22, 2024
d35e6df
invoke
ascjones Nov 22, 2024
9e3bc13
even more query -> view function renaming
ascjones Nov 22, 2024
82e9fbc
final query -> view function renaming?
ascjones Nov 22, 2024
09d3e75
Warnings/docs
ascjones Nov 25, 2024
b120001
Manual formatting
ascjones Nov 25, 2024
49a5d73
More warnings, format
ascjones Nov 25, 2024
cf9c01e
Rename view function interface to groups
ascjones Nov 25, 2024
9628070
Merge branch 'master' into aj/view-functions
ascjones Nov 25, 2024
cb97676
Add PR doc
ascjones Nov 25, 2024
d355f30
Merge branch 'master' into aj/view-functions
ascjones Nov 25, 2024
f88b646
Merge branch 'master' into aj/view-functions
ascjones Nov 26, 2024
b87bc0e
Renaming and implement view fn args
ascjones Nov 26, 2024
5b4e2f1
Docs
ascjones Nov 26, 2024
18b7d6d
Metadata tests and remove spaces from types.
ascjones Nov 26, 2024
25479e2
Fmt
ascjones Nov 26, 2024
402c29d
Merge branch 'master' into aj/view-functions
ascjones Nov 26, 2024
24d00d9
Merge branch 'master' into aj/view-functions
jsdw Nov 29, 2024
3fd9b5d
Merge branch 'master' into aj/view-functions
re-gius Jan 7, 2025
15d74ea
fix `Cargo.toml` duplicate dependency
re-gius Jan 7, 2025
6a042fb
format and fix toml files + Cargo.lock
re-gius Jan 7, 2025
c6a87fc
fix `Cargo.toml` of `pallet-example-view-functions`
re-gius Jan 7, 2025
9e92079
TOML lint + `cargo clippy`
re-gius Jan 7, 2025
c2e175a
add pallets to prdoc
re-gius Jan 7, 2025
cdca6f5
Add `RuntimeViewFunction` to `DefaultConfig`
re-gius Jan 7, 2025
2512093
Merge branch 'master' into aj/view-functions
re-gius Jan 7, 2025
e71d7d7
Add `RuntimeViewFunction`s to runtime config
re-gius Jan 7, 2025
05f7caa
Spelling
ascjones Jan 8, 2025
fc1d7aa
Merge branch 'master' into aj/view-functions
ascjones Jan 8, 2025
7a82560
fix `RuntimeViewFunction`
re-gius Jan 8, 2025
87807aa
fix
re-gius Jan 8, 2025
d3bf83c
undo changes
re-gius Jan 8, 2025
ccbac76
Revert "undo changes"
re-gius Jan 8, 2025
03c1c45
revert last 3 commits
re-gius Jan 8, 2025
d513cd1
revert last commits
re-gius Jan 8, 2025
627c275
Revert "fix"
re-gius Jan 8, 2025
227deb6
Revert "fix `RuntimeViewFunction`"
re-gius Jan 8, 2025
d234fdd
Revert "Add `RuntimeViewFunction`s to runtime config"
re-gius Jan 8, 2025
68061a9
Revert "Add `RuntimeViewFunction` to `DefaultConfig`"
re-gius Jan 8, 2025
bab4cb0
fix toml formatting
re-gius Jan 8, 2025
7b85388
Add `RuntimeViewFunction` type to all runtime configs
re-gius Jan 9, 2025
f176933
add missing `RuntimeViewFunction`
re-gius Jan 10, 2025
90d45f6
Merge branch 'master' into aj/view-functions
re-gius Jan 10, 2025
502c5be
small fix
re-gius Jan 10, 2025
a4d8b0c
Merge branch 'master' into aj/view-functions
re-gius Jan 13, 2025
c44d40e
Propagate runtime attributes to view function macros
re-gius Jan 13, 2025
0819dac
nit
re-gius Jan 13, 2025
9793b26
update errors msg in tests with view function errors
re-gius Jan 13, 2025
9a50968
Merge branch 'master' into aj/view-functions
re-gius Jan 13, 2025
cf06441
fix prdoc
re-gius Jan 13, 2025
a372eec
prdoc nit
re-gius Jan 13, 2025
e0758a2
fix prdoc bumps
re-gius Jan 13, 2025
73b41aa
fix semver bumps
re-gius Jan 14, 2025
9b62146
Add `wasm32-unknown-unknown` target in `check-semver` CI
re-gius Jan 14, 2025
320d7f4
Merge branch 'master' into aj/view-functions
re-gius Jan 14, 2025
e2ac06c
upgrade `parity-publish` version in `check-semver.yml`
re-gius Jan 15, 2025
258373c
undo last change
re-gius Jan 15, 2025
b63e77a
update `rust-cache` version too
re-gius Jan 16, 2025
578fa91
Revert "update `rust-cache` version too"
re-gius Jan 16, 2025
f3f321c
remove `RuntimeViewFunction` runtime type from `system` pallet
re-gius Jan 17, 2025
c642149
Merge branch 'master' into aj/view-functions
re-gius Jan 17, 2025
abe6f5c
remove unused import
re-gius Jan 17, 2025
013e789
Update substrate/frame/support/procedural/src/pallet/parse/view_funct…
re-gius Jan 17, 2025
d7d614d
remove deprecated use of `sp-std`
re-gius Jan 17, 2025
f9be388
Update substrate/frame/support/src/traits/view_function.rs
re-gius Jan 17, 2025
051dcdd
Update substrate/frame/support/src/traits/view_function.rs
re-gius Jan 17, 2025
dec2467
update `Cargo.lock`
re-gius Jan 17, 2025
e8ff55d
`cargo +nightly fmt --all`
re-gius Jan 17, 2025
82f08ea
update prdoc semver bump
re-gius Jan 17, 2025
98d3063
add `get_attributes()` method for pallet macros
re-gius Jan 17, 2025
502afaf
Update substrate/frame/support/src/traits/view_function.rs
re-gius Jan 17, 2025
e0b76ed
Update substrate/frame/support/src/traits/view_function.rs
re-gius Jan 17, 2025
73f62e4
fmt
re-gius Jan 17, 2025
8e34251
remove `sp-std` from view functions macro
re-gius Jan 17, 2025
de5834c
Change `panic`s into compile errors
re-gius Jan 20, 2025
f4e8aa2
Add view functions to Runtime APIs in `westend` runtime + `solochain`…
re-gius Jan 20, 2025
85ab0b7
remove unused pallet-level `Query` type
re-gius Jan 20, 2025
b04abd3
Merge branch 'master' into aj/view-functions
re-gius Jan 20, 2025
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 .github/workflows/check-semver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
if: ${{ !contains(github.event.pull_request.labels.*.name, 'R0-silent') }}
run: |
rustup default $TOOLCHAIN
rustup target add wasm32-unknown-unknown --toolchain $TOOLCHAIN
rustup component add rust-src --toolchain $TOOLCHAIN

- name: install parity-publish
Expand Down
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ members = [
"substrate/frame/examples/single-block-migrations",
"substrate/frame/examples/split",
"substrate/frame/examples/tasks",
"substrate/frame/examples/view-functions",
"substrate/frame/executive",
"substrate/frame/fast-unstake",
"substrate/frame/glutton",
Expand Down Expand Up @@ -941,6 +942,7 @@ pallet-example-offchain-worker = { path = "substrate/frame/examples/offchain-wor
pallet-example-single-block-migrations = { path = "substrate/frame/examples/single-block-migrations", default-features = false }
pallet-example-split = { path = "substrate/frame/examples/split", default-features = false }
pallet-example-tasks = { path = "substrate/frame/examples/tasks", default-features = false }
pallet-example-view-functions = { path = "substrate/frame/examples/view-functions", default-features = false }
pallet-examples = { path = "substrate/frame/examples" }
pallet-fast-unstake = { path = "substrate/frame/fast-unstake", default-features = false }
pallet-glutton = { path = "substrate/frame/glutton", default-features = false }
Expand Down
3 changes: 2 additions & 1 deletion cumulus/pallets/weight-reclaim/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ mod runtime {
RuntimeHoldReason,
RuntimeSlashReason,
RuntimeLockId,
RuntimeTask
RuntimeTask,
RuntimeViewFunction
gui1117 marked this conversation as resolved.
Show resolved Hide resolved
)]
pub struct Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ type SignedExtra = ();
mod runtime {
/// The main runtime type.
#[runtime::runtime]
#[runtime::derive(RuntimeCall, RuntimeEvent, RuntimeError, RuntimeOrigin, RuntimeTask)]
#[runtime::derive(
RuntimeCall,
RuntimeEvent,
RuntimeError,
RuntimeOrigin,
RuntimeTask,
RuntimeViewFunction
)]
pub struct Runtime;

/// Mandatory system pallet that should always be included in a FRAME runtime.
Expand Down
13 changes: 11 additions & 2 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ use sp_consensus_beefy::{
ecdsa_crypto::{AuthorityId as BeefyId, Signature as BeefySignature},
mmr::{BeefyDataProvider, MmrLeafVersion},
};
use sp_core::{ConstU8, OpaqueMetadata, RuntimeDebug, H256};
use sp_core::{
ConstU8, OpaqueMetadata, RuntimeDebug, ViewFunctionDispatchError, ViewFunctionId, H256,
};
use sp_runtime::{
generic, impl_opaque_keys,
traits::{
Expand Down Expand Up @@ -1611,7 +1613,8 @@ mod runtime {
RuntimeHoldReason,
RuntimeSlashReason,
RuntimeLockId,
RuntimeTask
RuntimeTask,
RuntimeViewFunction
)]
pub struct Runtime;

Expand Down Expand Up @@ -1973,6 +1976,12 @@ sp_api::impl_runtime_apis! {
}
}

impl sp_api::RuntimeViewFunction<Block> for Runtime {
fn execute_view_function(id: ViewFunctionId, input: Vec<u8>) -> Result<Vec<u8>, ViewFunctionDispatchError> {
Runtime::execute_view_function(id, input)
}
}

impl sp_block_builder::BlockBuilder<Block> for Runtime {
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
Executive::apply_extrinsic(extrinsic)
Expand Down
37 changes: 37 additions & 0 deletions prdoc/pr_4722.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Implement pallet view functions

doc:
- audience: Runtime Dev
description: |
Read-only view functions can now be defined on pallets. These functions provide an interface for querying state,
from both outside and inside the runtime. Common queries can be defined on pallets, without users having to
access the storage directly.

- audience: Runtime User
description: |
Querying the runtime state is now easier with the introduction of pallet view functions. Clients can call commonly
defined view functions rather than accessing the storage directly. These are similar to the Runtime APIs, but
are defined within the runtime itself.

crates:
- name: frame-support
bump: minor
- name: sp-core
bump: minor
- name: sp-api
bump: minor
- name: sp-metadata-ir
bump: major
- name: frame-support-procedural
bump: patch
- name: pallet-example-view-functions
bump: patch
- name: cumulus-pov-validator
bump: none
- name: cumulus-pallet-weight-reclaim
bump: patch
- name: westend-runtime
bump: minor
11 changes: 9 additions & 2 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ use sp_consensus_beefy::{
mmr::MmrLeafVersion,
};
use sp_consensus_grandpa::AuthorityId as GrandpaId;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160};
use sp_core::{crypto::KeyTypeId, OpaqueMetadata, ViewFunctionDispatchError, ViewFunctionId, H160};
use sp_inherents::{CheckInherentsResult, InherentData};
use sp_runtime::{
curve::PiecewiseLinear,
Expand Down Expand Up @@ -2459,7 +2459,8 @@ mod runtime {
RuntimeHoldReason,
RuntimeSlashReason,
RuntimeLockId,
RuntimeTask
RuntimeTask,
RuntimeViewFunction
)]
pub struct Runtime;

Expand Down Expand Up @@ -3013,6 +3014,12 @@ impl_runtime_apis! {
}
}

impl sp_api::RuntimeViewFunction<Block> for Runtime {
fn execute_view_function(id: ViewFunctionId, input: Vec<u8>) -> Result<Vec<u8>, ViewFunctionDispatchError> {
Copy link
Contributor

@jsdw jsdw Nov 29, 2024

Choose a reason for hiding this comment

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

Nit: I'm wondering whether it's worth scoping this call a bit more eg execute_pallet_view_function, in case we want to have an execute_runtime_view_function in the future or something? Or would you see runtime-wide view functions also being callable through this same interface?

Runtime::execute_view_function(id, input)
}
}

impl sp_block_builder::BlockBuilder<Block> for Runtime {
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
Executive::apply_extrinsic(extrinsic)
Expand Down
3 changes: 3 additions & 0 deletions substrate/frame/examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pallet-example-offchain-worker = { workspace = true }
pallet-example-single-block-migrations = { workspace = true }
pallet-example-split = { workspace = true }
pallet-example-tasks = { workspace = true }
pallet-example-view-functions = { workspace = true }

[features]
default = ["std"]
Expand All @@ -40,6 +41,7 @@ std = [
"pallet-example-single-block-migrations/std",
"pallet-example-split/std",
"pallet-example-tasks/std",
"pallet-example-view-functions/std",
]
try-runtime = [
"pallet-default-config-example/try-runtime",
Expand All @@ -51,4 +53,5 @@ try-runtime = [
"pallet-example-single-block-migrations/try-runtime",
"pallet-example-split/try-runtime",
"pallet-example-tasks/try-runtime",
"pallet-example-view-functions/try-runtime",
]
3 changes: 3 additions & 0 deletions substrate/frame/examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
//!
//! - [`pallet_example_tasks`]: This pallet demonstrates the use of `Tasks` to execute service work.
//!
//! - [`pallet_example_view_functions`]: This pallet demonstrates the use of view functions to query
//! pallet state.
//!
//! - [`pallet_example_authorization_tx_extension`]: An example `TransactionExtension` that
//! authorizes a custom origin through signature validation, along with two support pallets to
//! showcase the usage.
Expand Down
61 changes: 61 additions & 0 deletions substrate/frame/examples/view-functions/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[package]
name = "pallet-example-view-functions"
version = "1.0.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
description = "Pallet to demonstrate the usage of view functions to query pallet state"

[lints]
workspace = true

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.12", default-features = false, workspace = true }
frame-metadata = { features = ["current"], workspace = true }
log = { workspace = true }
scale-info = { version = "2.11.1", default-features = false, features = ["derive"], workspace = true }

frame-support = { path = "../../support", default-features = false, workspace = true }
frame-system = { path = "../../system", default-features = false, workspace = true }

sp-core = { default-features = false, path = "../../../primitives/core", workspace = true }
sp-io = { path = "../../../primitives/io", default-features = false, workspace = true }
sp-metadata-ir = { path = "../../../primitives/metadata-ir", default-features = false, workspace = true }
sp-runtime = { path = "../../../primitives/runtime", default-features = false, workspace = true }

frame-benchmarking = { path = "../../benchmarking", default-features = false, optional = true, workspace = true }

[dev-dependencies]
pretty_assertions = { version = "1.3.0" }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-metadata/std",
"frame-support/std",
"frame-system/std",
"log/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-metadata-ir/std",
"sp-runtime/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
]
114 changes: 114 additions & 0 deletions substrate/frame/examples/view-functions/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! This pallet demonstrates the use of the `pallet::view_functions_experimental` api for service
//! work.
#![cfg_attr(not(feature = "std"), no_std)]

pub mod tests;

use frame_support::Parameter;
use scale_info::TypeInfo;

pub struct SomeType1;
impl From<SomeType1> for u64 {
fn from(_t: SomeType1) -> Self {
0u64
}
}

pub trait SomeAssociation1 {
type _1: Parameter + codec::MaxEncodedLen + TypeInfo;
}
impl SomeAssociation1 for u64 {
type _1 = u64;
}

#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;

#[pallet::error]
pub enum Error<T> {}

#[pallet::config]
pub trait Config: frame_system::Config {}

#[pallet::pallet]
pub struct Pallet<T>(_);

#[pallet::storage]
pub type SomeValue<T: Config> = StorageValue<_, u32>;

#[pallet::storage]
pub type SomeMap<T: Config> = StorageMap<_, Twox64Concat, u32, u32, OptionQuery>;

#[pallet::view_functions_experimental]
impl<T: Config> Pallet<T>
where
T::AccountId: From<SomeType1> + SomeAssociation1,
{
/// Query value no args.
pub fn get_value() -> Option<u32> {
SomeValue::<T>::get()
}

/// Query value with args.
pub fn get_value_with_arg(key: u32) -> Option<u32> {
SomeMap::<T>::get(key)
}
}
}

#[frame_support::pallet]
pub mod pallet2 {
use super::*;
use frame_support::pallet_prelude::*;

#[pallet::error]
pub enum Error<T, I = ()> {}

#[pallet::config]
pub trait Config<I: 'static = ()>: frame_system::Config {}

#[pallet::pallet]
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);

#[pallet::storage]
pub type SomeValue<T: Config<I>, I: 'static = ()> = StorageValue<_, u32>;

#[pallet::storage]
pub type SomeMap<T: Config<I>, I: 'static = ()> =
StorageMap<_, Twox64Concat, u32, u32, OptionQuery>;

#[pallet::view_functions_experimental]
impl<T: Config<I>, I: 'static> Pallet<T, I>
where
T::AccountId: From<SomeType1> + SomeAssociation1,
{
/// Query value no args.
pub fn get_value() -> Option<u32> {
SomeValue::<T, I>::get()
}

/// Query value with args.
pub fn get_value_with_arg(key: u32) -> Option<u32> {
SomeMap::<T, I>::get(key)
}
}
}
Loading
Loading