-
Notifications
You must be signed in to change notification settings - Fork 2.7k
transactional: Wrap pallet::calls directly in storage layers
#11927
Changes from all commits
0fd5b85
028cf63
d80af32
ab7fa66
f24d062
fe15f9d
9a82ad5
b6095fd
ad18fa6
cec575f
7f400d1
1807e1d
22e5fab
e3bd7c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,6 +140,24 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { | |
|
|
||
| let capture_docs = if cfg!(feature = "no-metadata-docs") { "never" } else { "always" }; | ||
|
|
||
| // Wrap all calls inside of storage layers | ||
| if let Some(syn::Item::Impl(item_impl)) = def | ||
| .call | ||
| .as_ref() | ||
| .map(|c| &mut def.item.content.as_mut().expect("Checked by def parser").1[c.index]) | ||
| { | ||
| item_impl.items.iter_mut().for_each(|i| { | ||
| if let syn::ImplItem::Method(method) = i { | ||
| let block = &method.block; | ||
| method.block = syn::parse_quote! {{ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You change the logic of an extrinsic to be wrapped inside a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the idea, if you are thinking of making it configurable, there is this PR that attempts to solve it.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we should make it configurable eventually |
||
| // We execute all dispatchable in a new storage layer, allowing them | ||
| // to return an error at any point, and undoing any storage changes. | ||
| #frame_support::storage::with_storage_layer(|| #block) | ||
| }}; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| quote::quote_spanned!(span => | ||
| #[doc(hidden)] | ||
| pub mod __substrate_call_check { | ||
|
|
@@ -267,12 +285,8 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { | |
| #frame_support::sp_tracing::enter_span!( | ||
| #frame_support::sp_tracing::trace_span!(stringify!(#fn_name)) | ||
| ); | ||
| // We execute all dispatchable in a new storage layer, allowing them | ||
| // to return an error at any point, and undoing any storage changes. | ||
| #frame_support::storage::with_storage_layer(|| { | ||
| <#pallet_ident<#type_use_gen>>::#fn_name(origin, #( #args_name, )* ) | ||
| .map(Into::into).map_err(Into::into) | ||
| }) | ||
| <#pallet_ident<#type_use_gen>>::#fn_name(origin, #( #args_name, )* ) | ||
| .map(Into::into).map_err(Into::into) | ||
| }, | ||
| )* | ||
| Self::__Ignore(_, _) => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.