New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pallet Syntax: Analysis of T
consistency
#176
Comments
For storage items we need the generic T in the first type parameter of StorageValue, macro should generate something along the line:
bounding It is needed to access the name of the pallet which is used to derive the key to store the value in the trie For Error: I forbid the For GenesisConfig I think we don't generate the phantom data because it looks a bit ugly when using the type. EDIT: I agree allowing |
This issue has been mentioned on Polkadot Forum. There might be relevant details there: |
This issue has been mentioned on Polkadot Forum. There might be relevant details there: |
In this issue, I will describe how
T
is used within a pallet, and we can discuss if/how it can be improved. Would be good to double check all of this. The best way is try and start writing a pallet from scratch and letting yourself be confused.Storage Items
Storage items are valid in either of
but this is not valid:
type Foo = StorageValue<Value = u32>
.which implies that
<T>
is always needed, and is always expanded to<T: Config>
even if you drop it.But this is not the case and
type Foo<T> = StorageValue<Value = T::AccountId>
is also not valid.Pallet
structSimilarly, this is also always generic over
T
, and can be defined as either of:But, confusingly, neither of the below are valid, which makes this not abide by the same mental model as storage items, where
<T>
is auto-expanded for you to<T: Config>
.enum Event
This one acts like a very normal enum. Unlike storage, if you need
T
, you define it, if not, you don't. The only quirk here is that the if you define any genric, the pallet macro will auto-generate a hiddenPhamtomData
field for you.I think putting the
PhantomData
in there by default has been confusing and has probably led us to putting it there in many pallets without needing it.enum Error
This one works similar to
struct Pallet
, where onlyT
is accepted.The
Error
enum is among more involved ones, and you always needT
to getpallet_index
, which is needed to convert this upwards toDispatchError
.GenesisConfig
The usage of
T
inGenesisConfig
seems to be exactly like one would expect from Rust. The only inconsistency I see is that unlikeEvent
, if you use<T>
or<T: Config>
, aPhantomData
is not auto-injected for you. Both of the following is valid:All in all, Just looking at this from a syntactic point of view, I see two main points of inconsistency+improvement:
PhantomData
and in some cases we don't<T>
being<T: Config>
, but in some cases likeError
andPallet
we are arguably too strict for no reason, and don't allow the latter.The text was updated successfully, but these errors were encountered: