问题描述
如果我们查看 polkadot js 文档,我们可以看到以下注释:
这仅在此托盘用于存储余额的情况下使用。
现在我们如何使用余额托盘来存储余额?因为我们还有 api.query.system.account
函数而不是 api.query.balances.account
解决方法
您可以在您的框架系统和托盘平衡 Config
特性中进行配置。
在我们的示例中,我们使用以下内容将余额放置在系统托盘中:
impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = ();
/// Block & extrinsics weights: base values and limits.
type BlockWeights = BlockWeights;
/* -- snip -- */
/// The data to be stored in an account.
--> type AccountData = pallet_balances::AccountData<Balance>;
/// Weight information for the extrinsics of this pallet.
type SystemWeightInfo = ();
/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
type SS58Prefix = SS58Prefix;
}
impl pallet_balances::Config for Runtime {
type MaxLocks = MaxLocks;
/// The type for recording an account's balance.
type Balance = Balance;
/// The ubiquitous event type.
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
--> type AccountStore = System;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
}
我在相关字段上放了一个箭头。
如果您想将余额存储在余额托盘本身,您只需将这两行更改为以下内容:
/// Store no extra data in the Balances pallet.
type AccountData = ();
和
use frame_support::traits::StorageMapShim;
...
/// Store the balance information in the Balances pallet.
type AccountStore = StorageMapShim<
pallet_balances::Account<Runtime>,frame_system::Provider<Runtime>,AccountId,pallet_balances::AccountData<Balance>,>;