1717
1818//! Custom transaction extension for the transaction storage pallet.
1919
20- use crate :: { Call , CidCodecForStore , Config , LOG_TARGET } ;
20+ use crate :: { cids :: CidConfig , Call , CidConfigForStore , Config , LOG_TARGET } ;
2121use codec:: { Decode , DecodeWithMemTracking , Encode } ;
2222use core:: { fmt, marker:: PhantomData } ;
2323use polkadot_sdk_frame:: {
@@ -26,32 +26,23 @@ use polkadot_sdk_frame::{
2626 traits:: Implication ,
2727} ;
2828
29- /// Type alias representing a CID codec.
30- pub type CidCodec = u64 ;
31-
32- /// Temporarily tracks provided optional CID codec.
33- #[ derive( Default ) ]
34- pub struct CidCodecContext {
35- pub codec : Option < CidCodec > ,
36- }
37-
3829/// `TransactionExtension` implementation that provides optional `CidCodec` for the `store`
3930/// extrinsic.
4031#[ derive( Clone , PartialEq , Eq , Encode , Decode , DecodeWithMemTracking , scale_info:: TypeInfo ) ]
4132#[ scale_info( skip_type_params( T ) ) ]
42- pub struct ProvideCidCodec < T > ( pub Option < CidCodec > , PhantomData < T > ) ;
33+ pub struct ProvideCidConfig < T > ( pub Option < CidConfig > , PhantomData < T > ) ;
4334
44- impl < T > ProvideCidCodec < T > {
45- /// Create a new `ProvideCidCodec ` instance.
46- pub fn new ( cid_codec : Option < CidCodec > ) -> Self {
47- Self ( cid_codec , Default :: default ( ) )
35+ impl < T > ProvideCidConfig < T > {
36+ /// Create a new `ProvideCidConfig ` instance.
37+ pub fn new ( config : Option < CidConfig > ) -> Self {
38+ Self ( config , Default :: default ( ) )
4839 }
4940}
5041
51- impl < T : Config + Send + Sync > fmt:: Debug for ProvideCidCodec < T > {
42+ impl < T : Config + Send + Sync > fmt:: Debug for ProvideCidConfig < T > {
5243 #[ cfg( feature = "std" ) ]
5344 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
54- write ! ( f, "ProvideCidCodec ({:?})" , self . 0 )
45+ write ! ( f, "ProvideCidConfig ({:?})" , self . 0 )
5546 }
5647
5748 #[ cfg( not( feature = "std" ) ) ]
@@ -60,18 +51,18 @@ impl<T: Config + Send + Sync> fmt::Debug for ProvideCidCodec<T> {
6051 }
6152}
6253
63- impl < T : Config + Send + Sync > TransactionExtension < T :: RuntimeCall > for ProvideCidCodec < T >
54+ impl < T : Config + Send + Sync > TransactionExtension < T :: RuntimeCall > for ProvideCidConfig < T >
6455where
6556 <T as frame_system:: Config >:: RuntimeCall : IsSubType < Call < T > > ,
6657{
67- const IDENTIFIER : & ' static str = "ProvideCidCodec " ;
58+ const IDENTIFIER : & ' static str = "ProvideCidConfig " ;
6859
6960 type Implicit = ( ) ;
7061 fn implicit ( & self ) -> Result < Self :: Implicit , TransactionValidityError > {
7162 Ok ( ( ) )
7263 }
7364
74- type Val = Option < CidCodec > ;
65+ type Val = Option < CidConfig > ;
7566 type Pre = ( ) ;
7667
7768 fn weight ( & self , _call : & T :: RuntimeCall ) -> Weight {
8879 _inherited_implication : & impl Implication ,
8980 _source : TransactionSource ,
9081 ) -> ValidateResult < Self :: Val , T :: RuntimeCall > {
91- match ( self . 0 , call. is_sub_type ( ) ) {
92- ( Some ( cid_codec ) , Some ( Call :: store { .. } ) ) =>
93- Ok ( ( Default :: default ( ) , Some ( cid_codec ) , origin) ) ,
82+ match ( self . 0 . as_ref ( ) , call. is_sub_type ( ) ) {
83+ ( Some ( cid_config ) , Some ( Call :: store { .. } ) ) =>
84+ Ok ( ( Default :: default ( ) , Some ( cid_config . clone ( ) ) , origin) ) ,
9485 ( Some ( _) , _) => {
9586 // All other calls are invalid with cid_codec.
9687 Err ( InvalidTransaction :: Call . into ( ) )
@@ -108,10 +99,17 @@ where
10899 _len : usize ,
109100 ) -> Result < Self :: Pre , TransactionValidityError > {
110101 log:: error!( target: LOG_TARGET , "prepare: {val:?}" ) ;
111- if let Some ( cid_codec) = val {
112- CidCodecForStore :: < T > :: set ( Some ( cid_codec) ) ;
113-
114- // TODO: just attempt, not working, will remove.
102+ if let Some ( cid_config) = val {
103+ // Let's store the codec in the intermediary storage, which will be cleared by the store
104+ // extrinsic.
105+ CidConfigForStore :: < T > :: set ( Some ( cid_config) ) ;
106+
107+ // TODO: just attempt with dispatch `with_context`, not working, will remove.
108+ // /// Temporarily tracks provided optional CID codec.
109+ // #[derive(Default)]
110+ // pub struct CidCodecContext {
111+ // pub codec: Option<CidCodec>,
112+ // }
115113 // Put cid codec to the dispatch context
116114 // with_context::<CidCodecContext, _>(|v| {
117115 // let context = v.or_default();
0 commit comments