首页 > 解决方案 > 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'

标签: substratepolkadot

解决方案


此方法是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以满足特征实现。


推荐阅读