construct_runtime in frame_support - Rust (original) (raw)

logo

construct_runtime!() { /* proc-macro */ }

Expand description

Construct a runtime, with the given name and the given pallets.

The parameters here are specific types for Block, NodeBlock, and UncheckedExtrinsicand the pallets that are used by the runtime.Block is the block type that is used in the runtime and NodeBlock is the block type that is used in the node. For instance they can differ in the extrinsics type.

Example:

construct_runtime!(
    pub enum Runtime where
        Block = Block,
        NodeBlock = node::Block,
        UncheckedExtrinsic = UncheckedExtrinsic
    {
        System: frame_system::{Pallet, Call, Event<T>, Config<T>} = 0,
        Test: path::to::test::{Pallet, Call} = 1,

        // Pallets with instances.
        Test2_Instance1: test2::<Instance1>::{Pallet, Call, Storage, Event<T, I>, Config<T, I>, Origin<T, I>},
        Test2_DefaultInstance: test2::{Pallet, Call, Storage, Event<T>, Config<T>, Origin<T>} = 4,

        // Pallets declared with `pallet` attribute macro: no need to define the parts
        Test3_Instance1: test3::<Instance1>,
        Test3_DefaultInstance: test3,

        // with `exclude_parts` keyword some part can be excluded.
        Test4_Instance1: test4::<Instance1> exclude_parts { Call, Origin },
        Test4_DefaultInstance: test4 exclude_parts { Storage },

        // with `use_parts` keyword, a subset of the pallet parts can be specified.
        Test4_Instance1: test4::<Instance1> use_parts { Pallet, Call},
        Test4_DefaultInstance: test4 use_parts { Pallet },
    }
)

Each pallet is declared as such:

pallet1 .. = 2,  
pallet2 .., // Here pallet2 is given index 3  
pallet3 .. = 0,  
pallet4 .., // Here pallet4 is given index 1  

Note

The population of the genesis storage depends on the order of pallets. So, if one of your pallets depends on another pallet, the pallet that is depended upon needs to come before the pallet depending on it.

Type definitions