什么是BigMap容器,为什么重要?
1 个回答
- 投票数
-
- 2019-02-22
- BigMap容器是一种特殊的地图(词典),仅按需按键读取或写入存储.
拥有这样一个容器的动机如下.假设您有一个包含或多或少的独立数据的合同,并且您不想一次读取/写入所有数据,而只读取其中的一小部分.考虑一下加密猫,集合,STO(安全令牌)等. 通常,仅访问所需的部分而不是加载所有内容,这是更有效的资源管理方式(耗油和执行时间).
-
在迈克尔逊实现中,每个合同的限制实际上只是为了简化目的.
-
在今天的实现中,只有一个BigMap意味着如果您需要两个这样的东西map1和map2,则需要通过执行以下操作来编码map1和map2的混合:
键=左键1|右键2
您希望拥有两张这样的地图的示例可以是代表房地产和所有者或收藏品和所有者的合同.您可能希望访问某些商品的所有者或某些所有者的商品.
我个人认为在迈克尔逊市解除这一限制会很好.
- The BigMap container is a special map (dictionary) whose storage is only read or written per key on demand.
The motivation to have such a container is the following. Suppose that you have a contract containing lots of more or less independent data and you don't want to read / write all of the data at once but only a small part of it. Think of crypto-kitties, collections, STOs (security tokens), etc. It is in general much more efficient resource wise (gas and execution time) to only access the part you need instead of loading everything.
The limitation of only one per contract is really for simplicity purposes in the Michelson implementation.
With today's implementation, having only one BigMap means that if you need two such things map1 and map2, you need to encode the mixing of map1 and map2 by doing something like:
key = Left key1 | Right key2
An example where you would wish to have two such maps can be a contract that represents real estate and owners or collectibles and owners. You may wish to access owners of some goods or goods of some owners.
I personally think that lifting this restriction in Michelson would be nice.
-
不幸的是,您不能将总和类型用作大地图的键,因为总和类型不可比(没有充分的理由).您将必须使用sun类型的哈希或其打包字节表示形式.Unfortunately, you can't use sum types as keys to bigmaps because sum types aren't comparable (for no good reason). You would have to use the hash of the sun type, or its packed byte representation.
- 1
- 2019-03-19
- Arthur B
-
@ArthurB我写这个答案时错过了这个限制.感谢您的精确度.最终取消此限制可能是合理的(我想也要做单位和期权).@ArthurB I missed this limitation when I wrote this answer. Thanks for the precision. It might be reasonable to lift this restriction eventually (and do unit and option as well I guess).
- 0
- 2019-03-19
- FFF
-
...和配对. 是的,这是使这些类型具有可比性的非常简单的补丁... and Pair. And yes, it's a pretty straightforward patch to make these types comparable
- 1
- 2019-03-20
- Arthur B
我在很多地方都听说过Tezos正在使用一种称为BigMap的特定类型的容器,以便将数据存储在智能合约中.
该对象必须相对复杂,因为到目前为止,单个智能合约中仅允许一个BigMap实例.
我的问题如下: