substrate新增pallet流程

1. 在pallets目录下创建新pallet的目录

添加Cargo.toml,可以复制template下的文件来修改,
substrate新增pallet流程_第1张图片
修改toml文件中的描述,一般改name和description其它不用动
substrate新增pallet流程_第2张图片
创建子目录src并创建文件lib.rs做为pallet的源码文件

2. 修改runtime下的Cargo.toml

首先添加本地依赖
substrate新增pallet流程_第3张图片
然后修改std列表,添加新的pallet

[features]
default = ['std']
runtime-benchmarks = [
     ......
]
std = [
    'codec/std',
    'scale-info/std',
    'frame-executive/std',
     ......
    'pallet-storage-provider/std',
]

3. 修改runtime下的src\lib.rs

添加runtime对pallet的实现
substrate新增pallet流程_第4张图片
修改construct_runtime列表

construct_runtime!(
	pub enum Runtime where
		Block = Block,
		NodeBlock = opaque::Block,
		UncheckedExtrinsic = UncheckedExtrinsic
	{
		System: frame_system,
        ......
		// Include the custom logic from the pallet-template in the runtime.
		TemplateModule: pallet_template,
		StorageModule : pallet_storage_provider,
	}
);

你可能感兴趣的:(Substrate,rust,学习,开发语言)