substrate - into_sub_account 方法未找到
问题描述
我正在尝试使用 PALLET_ID
const PALLET_ID: PalletId = PalletId(*b"ex/cfund");
fn fund_account_id(index: FundIndex) -> T::AccountId {
PALLET_ID.into_sub_account(index)
}
但它给出的错误:
method not found in `frame_support::PalletId`
Docs: Link
所有方法都无法访问并给出错误。
版本:
git = 'https://github.com/paritytech/substrate.git'
标签 = 'monthly-2021-10'
版本 = '4.0.0-dev'
解决方案
此方法是AccountIdConversion
为 type 实现的特征的一部分PalletId
。因此,您需要在范围内拥有特征或显式地从特征调用方法。
就像:
use sp_runtime::traits::AccountIdConversion;
const PALLET_ID: frame_support::PalletId = frame_support::PalletId(*b"ex/cfund");
fn fund_account_id(index: u32) -> u128 {
PALLET_ID.into_sub_account(index)
}
或者
const PALLET_ID: frame_support::PalletId = frame_support::PalletId(*b"ex/cfund");
fn fund_account_id(index: u32) -> u128 {
sp_runtime::traits::AccountIdConversion::into_sub_account(&PALLET_ID, index)
}
同样在您的示例中,类型FundIndex
需要实现Encode
以满足特征实现。
推荐阅读
- php - 如何正确地从数组中获取信息以便可以插入数据库?
- flutter - 按下按钮时如何在 Flutter 上更改文本样式
- spring-batch - Spring Batch CompositeItemWriter 如何为委托编写者管理事务?
- apache-spark - Spark 抛出 FileNotFoundException 并说“刷新表表名”
- python-3.x - Pathos 排队任务然后得到结果
- javascript - 对数组的 mongoose.model 索引返回未定义
- javascript - 为什么需要 Angular Universal?
- html - 根据 lang 属性为所有元素设置 css 样式
- java - 尝试平均数字的程序。答案以 Integer 出现,而它应该是 Double
- python - cv2 findChessboardCorner 使用树莓派相机模块时精度低