Reputation: 538
So every pallet type has more or less the same declaration : pub struct Pallet<T>(_)
or pub struct Pallet<T>(PhantomData<T>)
where T: Config
. My question is what does T
stand for? Someone mentioned that T
represents the substrate runtime which led me to question, if a node has multiple running pallets, do they all share the same definition of T
?
Upvotes: 4
Views: 366
Reputation: 12434
T
is a generic type which represents the entire Runtime configuration for your chain.
Substrate is designed to be modular and configurable, and thus we allow every pallet to be completely configured for your needs.
A simple example of this is that we make no assumptions about what type you use for the block number for your chain. Throughout the code, the block number type is generic, and can be referenced by the T::Number
type.
At some point, that generic type needs to be concretely defined, which happens in the runtime configuration. This T
generic type is passed to all pallets in order to share what those concrete types actually are, and make everything work in the end.
Check out this repository for a helpful example of how you can transition to concrete types into generic types, and then it will be obvious how the T
syntax came to be:
https://www.youtube.com/watch?v=6cp10jVWNl4
https://github.com/shawntabrizi/substrate-trait-tutorial
Upvotes: 6