diff --git a/primitives/api/proc-macro/src/impl_runtime_apis.rs b/primitives/api/proc-macro/src/impl_runtime_apis.rs index f594a743fcf94..f1903191e712f 100644 --- a/primitives/api/proc-macro/src/impl_runtime_apis.rs +++ b/primitives/api/proc-macro/src/impl_runtime_apis.rs @@ -301,6 +301,10 @@ fn generate_runtime_api_base_structures() -> Result { state_version, ) } + + fn overlay(&self) -> #crate_::OverlayedChanges { + ::std::clone::Clone::clone(&::std::cell::RefCell::borrow(&self.changes)) + } } #[cfg(any(feature = "std", test))] diff --git a/primitives/api/proc-macro/src/mock_impl_runtime_apis.rs b/primitives/api/proc-macro/src/mock_impl_runtime_apis.rs index ffc158ac94d29..ce955405873f2 100644 --- a/primitives/api/proc-macro/src/mock_impl_runtime_apis.rs +++ b/primitives/api/proc-macro/src/mock_impl_runtime_apis.rs @@ -123,6 +123,10 @@ fn implement_common_api_traits(block_type: TypePath, self_ty: Type) -> Result where Self: Sized { unimplemented!("`into_storage_changes` not implemented for runtime api mocks") } + + fn overlay(&self) -> #crate_::OverlayedChanges { + unimplemented!("`overlay` not implemented for runtime api mocks") + } } impl #crate_::Core<#block_type> for #self_ty { diff --git a/primitives/api/src/lib.rs b/primitives/api/src/lib.rs index 964ef15ce5f5a..5c109d6fb46ac 100644 --- a/primitives/api/src/lib.rs +++ b/primitives/api/src/lib.rs @@ -519,6 +519,11 @@ pub trait ApiExt { ) -> Result, String> where Self: Sized; + + /// Returns the overlayed changes. + /// + /// Useful when you want to construct an intermediate state during the entire block execution. + fn overlay(&self) -> OverlayedChanges; } /// Parameters for [`CallApiAt::call_api_at`].