Reputation: 2270
In substrate pallets, build
is often used in decl_storage.
e.g.
pub ReferendumCount get(fn referendum_count) build(|_| 0 as ReferendumIndex): ReferendumIndex;
What does the build method do, how and when it is used?
Upvotes: 0
Views: 90
Reputation: 1405
From substrate.dev:
Whereas the config extension to the decl_storage macro allows you to configure a module's genesis storage state within a chain specification, the build extension allows you to perform this same task within the module itself (this gives you access to the module's private functions). Like config, the build extension accepts a single parameter, but in this case the parameter is always required and must be a closure, which is essentially a function. The build closure will be invoked with a single parameter whose type will be the pallet's GenesisConfig type (this gives you easy access to all the attributes of the GenesisConfig type). You may use the build extension along with the config extension for a single storage item; in this case, the pallet's GenesisConfig type will have an attribute that corresponds to what was set using config whose value will be set in the chain specification, but it will be the value returned by the build closure that will be used to set the storage item's genesis value.
Upvotes: 2
Reputation: 461
What build($expr)
does there is adding the build logic to the genesis config build.
You can learn more about this reading the macro documentation, I would recomend these points related to your question
You can find examples in that very same documentation
Upvotes: 1