substrate - 将存储宏从帧 v1 转换为帧 v2
问题描述
标题非常具有描述性。
我想转换这个:
decl_storage! {
trait Store for Module<T: Config> as SimpleTreasury {
// No storage items of our own, but we still need decl_storage to initialize the pot
}
add_extra_genesis {
build(|_config| {
// Create the charity's pot of funds, and ensure it has the minimum required deposit
let _ = T::Currency::make_free_balance_be(
&<Module<T>>::account_id(),
T::Currency::minimum_balance(),
);
});
}
}
进入帧 V2。下面我有我的转换版本,但它似乎不起作用,最低余额似乎没有正确设置。
#[pallet::genesis_config]
#[derive(Default)]
pub struct GenesisConfig {
}
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
fn build(&self) {
let _ = T::Currency::make_free_balance_be(
&<Module<T>>::account_id(),
T::Currency::minimum_balance(),
);
}
}
有人可以看看并告诉我出了什么问题。我真的很感激。Pallet Github 链接:https ://github.com/herou/recipes/tree/recipes_pallet_v2/pallets/charity 注意:一些测试失败
解决方案
该宏有一个关于从宏pallet
升级的部分: https ://substrate.dev/rustdocs/latest/frame_support/attr.pallet.html#upgrade-guidelinesdecl_*
我建议仔细阅读该部分。
要说这个文档的几点,我可以说:
- 里面有一个助手
decl_storage
可以为新的托盘宏生成一些代码。通过使用环境变量运行宏扩展PRINT_PALLET_UPGRADE
:例如PRINT_PALLET_UPGRADE=1 cargo check -p $my_pallet$
。 - 存储使用的托盘前缀配置不同:在 decl_storage 中给出了托盘前缀(例如
SimpleTreasury
在您的示例中)。现在,pallet 前缀是构建运行时时配置的名称。(例如在construct_runtime 调用中,当它被写入时:MyPalletName: path_to_pallet::{Call, ...},
,名称MyPalletName
)。如果名称不同,您可以使用一些实用程序函数来创建迁移:https ://substrate.dev/rustdocs/latest/frame_support/storage/migration/index.html - 现在应该将属性
config()
和build()
将特定值放入存储中的属性放入GenesisConfig::build
实现中。 - 通常在声明存储时使用的哈希器和类型应该非常简单。但人们必须小心
QueryKind
泛型。如果存储是用值写入的,Option<$Something>
则 querykind 是OptionQuery,否则它是ValueQuery。(但助手PRINT_PALLET_UPGRADE
必须给你正确的翻译。)
推荐阅读
- javascript - Accessing property's array with a specific id
- javascript - 是否可以在 gulp4 gulp.watch 任务中获取文件名?
- r - 为什么 r(r 代码)在我的图表中给我锯齿线?
- ruby - 从字符串加载常量,在当前范围内解析
- node.js - 浏览器接受“经典”js 脚本标签,但不接受 ES6 模块 — 带有节点 http 服务器的 MIME 错误
- python - 将xml转换为pandas数据框python
- r - Googleway 不考虑交通时间(路线搜索)
- java - 如何将arraylist的每一行分配给它自己的数组
- extract-value - 多个元素的 ExtractValue
- android - 无法预览捕获的高质量图像