如何在同一运行时内多次重复使用 Substrate 子板块?

huangapple go评论71阅读模式
英文:

How to re-use a Substrate pallet multiple times within the same runtime?

问题

我想在同一个运行时内使用多种货币。默认节点模板中已经插入了“Balances”模块,但如果我理解正确,它只能处理一种货币。

我如何多次重复使用这个模块?

英文:

I want to have multiple currencies within the same runtime. There is Balances pallet plugged into the default node template, but if I've got it right it can handle only one currency.

How can I re-use the pallet multiple times?

答案1

得分: 10

Pallets can be made instantiable which allows you to include multiple instances in the same runtime. The Substrate Recipes contain a writeup on creating instantiable pallets as well as these examples:

  • Instantiable pallet without default instance example
  • Instantiable pallet with deafult instance example
  • How to include instantiable pallets in your runtime example

Conveniently, the Balances pallet that you're interested in is already instantiable as you can see from (among other places) its configuration trait.

For completeness, it's also worth mentioning that Substrate ships with the Assets pallet which is another approach to multiple tokens in a single runtime.

If you want exactly two tokens it's best to use two instances of the Balances pallet. If you want multiple tokens and the ability to add more later, Assets is best.

英文:

Pallets can be made instantiable which allows you to include multiple instances in the same runtime. The Substrate Recipes contain a writeup on creating instantiable pallets as well as these examples:

  • Instantiable pallet without default instance example
  • Instantiable pallet with deafult instance example
  • How to include instantiable pallets in your runtime example

Conveniently, the Balances pallet that you're interested in is already instantiable as you can see from (among other places) its configuration trait.

For completeness, it's also worth mentioning that Substrate ships with the Assets pallet which is another approach to multiple tokens in a single runtime.

If you want exactly two tokens it's best to use two instances of the Balances pallet. If you want multiple tokens and the ability to add more later, Assets is best.

答案2

得分: 6

所有的托盘可以被实例化。这是专为适用于多实例模型的模块设计的,包括 Balances。多货币链是此功能的经典示例。substrate-node 中的集体托盘已经可以像这样工作。请注意,在 GenesisConfig 中它被命名两次(一次为 council,一次为 technical committee),甚至在 construct_runtime! {} 中也是如此。

这里有一个教程,介绍如何完成所有这些操作,尽管如果您在 substrate 主分支上尝试,可能会有一些变化,这是针对 1.0 版本的。但概念应该是相同的。

英文:

All pallets can be instantiated. This is specifically designed for modules that serve a purpose that suites the multi-instance model, including Balances. A multi-currency chain is the textbook example of this feature. The collective pallet in substrate-node is already working like this. See how it is named twice (once for council and once for technical committee) in GenesisConfig and even construct_runtime! {}.

Here's a tutorial on how to do all of this, though expect some changes if you try in on substrate master, this is for 1.0. But the concepts should be the same.

huangapple
  • 本文由 发表于 2020年1月3日 21:26:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/59579424.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定