如何使用平衡托盘而不是系统托盘来存储余额。

9
如果我们查看Polkadot JS文档,可以看到以下说明: 这仅在使用此面板存储余额的情况下使用。 那么我们如何使用balances面板来存储余额呢?因为我们还有api.query.system.account函数,而不是api.query.balances.account

嗨Noah,你能否支持我们的Substrate StackExchange提案:https://area51.stackexchange.com/proposals/126136? - Shawn Tabrizi
1个回答

10

您可以在框架系统和托盘平衡器的 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 Frame System 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>,
>;

非常感谢您的调整,但是我遇到了以下错误:the trait bound `pallet_balances::Pallet: StoredMap>` is not satisfied --> /home/noone/cious3/substrate-node-template/runtime/src/lib.rs:280:2 | 280 | type AccountStore = Balances; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `StoredMap>` is not implemented for `pallet_balances::Pallet` | 我正在使用 Substrate 节点模板 3.0.0。 - Noah Bergh
1
抱歉 @NoahBergh!我已经更新了示例,确保它正确,并测试了本地编译和运行。 - Shawn Tabrizi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接