@@ -103,7 +103,7 @@ pub mod weights;
103
103
#[ cfg( test) ]
104
104
mod tests;
105
105
use crate :: {
106
- exec:: { AccountIdOf , ErrorOrigin , ExecError , Executable , Key , Stack as ExecStack } ,
106
+ exec:: { AccountIdOf , ErrorOrigin , ExecError , Executable , Key , MomentOf , Stack as ExecStack } ,
107
107
gas:: GasMeter ,
108
108
storage:: { meter:: Meter as StorageMeter , ContractInfo , DeletionQueueManager } ,
109
109
wasm:: { CodeInfo , WasmBlob } ,
@@ -122,9 +122,13 @@ use frame_support::{
122
122
ConstU32 , Contains , Get , Randomness , Time ,
123
123
} ,
124
124
weights:: Weight ,
125
- BoundedVec , RuntimeDebug , RuntimeDebugNoBound ,
125
+ BoundedVec , DefaultNoBound , RuntimeDebug , RuntimeDebugNoBound ,
126
+ } ;
127
+ use frame_system:: {
128
+ ensure_signed,
129
+ pallet_prelude:: { BlockNumberFor , OriginFor } ,
130
+ EventRecord , Pallet as System ,
126
131
} ;
127
- use frame_system:: { ensure_signed, pallet_prelude:: OriginFor , EventRecord , Pallet as System } ;
128
132
use pallet_contracts_primitives:: {
129
133
Code , CodeUploadResult , CodeUploadReturnValue , ContractAccessError , ContractExecResult ,
130
134
ContractInstantiateResult , ContractResult , ExecReturnValue , GetStorageResult ,
@@ -179,6 +183,36 @@ const SENTINEL: u32 = u32::MAX;
179
183
/// Example: `RUST_LOG=runtime::contracts=debug my_code --dev`
180
184
const LOG_TARGET : & str = "runtime::contracts" ;
181
185
186
+ /// Wrapper around `PhantomData` to prevent it being filtered by `scale-info`.
187
+ ///
188
+ /// `scale-info` filters out `PhantomData` fields because usually we are only interested
189
+ /// in sized types. However, when trying to communicate **types** as opposed to **values**
190
+ /// we want to have those zero sized types be included.
191
+ #[ derive( Encode , Decode , DefaultNoBound , TypeInfo ) ]
192
+ #[ cfg_attr( feature = "std" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
193
+ pub struct EnvironmentType < T > ( PhantomData < T > ) ;
194
+
195
+ /// List of all runtime configurable types that are used in the communication between
196
+ /// `pallet-contracts` and any given contract.
197
+ ///
198
+ /// Since those types are configurable they can vary between
199
+ /// chains all using `pallet-contracts`. Hence we need a mechanism to communicate those types
200
+ /// in a way that can be consumed by offchain tooling.
201
+ ///
202
+ /// This type only exists in order to appear in the metadata where it can be read by
203
+ /// offchain tooling.
204
+ #[ derive( Encode , Decode , DefaultNoBound , TypeInfo ) ]
205
+ #[ cfg_attr( feature = "std" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
206
+ #[ scale_info( skip_type_params( T ) ) ]
207
+ pub struct Environment < T : Config > {
208
+ account_id : EnvironmentType < AccountIdOf < T > > ,
209
+ balance : EnvironmentType < BalanceOf < T > > ,
210
+ hash : EnvironmentType < <T as frame_system:: Config >:: Hash > ,
211
+ hasher : EnvironmentType < <T as frame_system:: Config >:: Hashing > ,
212
+ timestamp : EnvironmentType < MomentOf < T > > ,
213
+ block_number : EnvironmentType < BlockNumberFor < T > > ,
214
+ }
215
+
182
216
#[ frame_support:: pallet]
183
217
pub mod pallet {
184
218
use super :: * ;
@@ -360,6 +394,13 @@ pub mod pallet {
360
394
/// Do **not** use it in a production environment or for benchmarking purposes.
361
395
#[ cfg( feature = "unsafe-debug" ) ]
362
396
type Debug : unsafe_debug:: UnsafeDebug < Self > ;
397
+
398
+ /// Type that bundles together all the runtime configurable interface types.
399
+ ///
400
+ /// This is not a real config. We just mention the type here as constant so that
401
+ /// its type appears in the metadata. Only valid value is `()`.
402
+ #[ pallet:: constant]
403
+ type Environment : Get < Environment < Self > > ;
363
404
}
364
405
365
406
#[ pallet:: hooks]
0 commit comments