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 the ability to declare multiple impl blocks #6795

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
21 changes: 21 additions & 0 deletions prdoc/pr_6795.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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: ...

doc:
- audience: Runtime Dev
description: |
Makes possible to split internals of `sp_api::impl_runtime_apis!` into multiple blocks.
to do this user is required to use `sp_api::impl_runtime_apis_ext` proc-macro attribute on a
module that defines additional `impl` items that will be included in `impl_runtime_apis!` through `use <path>::*` declarations.


crates:
- name: sp-api
bump: major
- name: sp-api-proc-macro
bump: major
- name: frame-support
bump: major

30 changes: 19 additions & 11 deletions substrate/frame/support/test/tests/runtime_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ sp_api::decl_runtime_apis! {

// Module to emulate having the implementation in a different file.
mod apis {
use super::{Block, BlockT, Runtime};
use super::{ext, Block, Runtime};

sp_api::impl_runtime_apis! {
impl crate::Api<Block> for Runtime {
Expand All @@ -103,16 +103,24 @@ mod apis {
fn wild_card(_: u32) {}
}

impl sp_api::Core<Block> for Runtime {
fn version() -> sp_version::RuntimeVersion {
unimplemented!()
}
fn execute_block(_: Block) {
unimplemented!()
}
fn initialize_block(_: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
unimplemented!()
}
external_impls!{ext}
}
}

#[sp_api::impl_runtime_apis_ext]
mod ext {

external_impls! {super, crate::apis}

impl sp_api::Core<Block> for Runtime {
fn version() -> sp_version::RuntimeVersion {
unimplemented!()
}
fn execute_block(_: Block) {
unimplemented!()
}
fn initialize_block(_: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
unimplemented!()
}
}
}
Expand Down
Loading
Loading