【问题标题】:How do we use the balances pallet instead of the system pallet to store the balances我们如何使用天平托盘而不是系统托盘来存储天平
【发布时间】:2021-03-06 23:28:13
【问题描述】:

如果我们查看 polkadot js 文档,我们可以看到以下注释: 这仅在此托盘用于存储天平的情况下使用。 现在我们如何使用天平托盘来存放天平?因为我们也有 api.query.system.account 函数而不是 api.query.balances.account

【问题讨论】:

标签: substrate


【解决方案1】:

您可以在框架系统和托盘天平Config trait 中进行配置。

在我们的示例中,我们使用以下方法将天平放置在系统托盘中:

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>,
>;

【讨论】:

  • 非常感谢,但是通过您的调整,我有以下错误``` trait bound pallet_balances::Pallet&lt;Runtime&gt;: StoredMap&lt;AccountId32, AccountData&lt;u128&gt;&gt; 不满足 --> /home/noone/cious3/substrate-node-template/runtime/src /lib.rs:280:2 | 280 |类型 AccountStore = 余额; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 特征 StoredMap&lt;AccountId32, AccountData&lt;u128&gt;&gt; 没有为 pallet_balances::Pallet&lt;Runtime&gt; 实现 | ```我使用的是基板节点模板3.0.0
  • 对不起@NoahBergh!我已将示例更新为正确,并已对其在本地编译和工作进行了测试。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-29
相关资源
最近更新 更多