gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:34:00 24 4
gpt4 key购买 nike

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

关于substrate - 我们如何使用余额托盘而不是系统托盘来存储余额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66511734/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com