微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我们如何使用余额托盘而不是系统托盘来存储余额

如何解决我们如何使用余额托盘而不是系统托盘来存储余额

如果我们查看 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>,>;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。