有什么方法可以重新初始化映射
我正在尝试编码智能合约,并且正在使用映射(地址=> bool);当特定条件满足时,我将其成立。现在,对于另一个条件,我希望我的映射重置并释放其所有数据,我希望它是一开始是空映射的位置。
问题语句:我为使用dapp在我的dapp中投票的任何人都设置了全部设置(地址=> bool)现在投票结束后,我希望我所有的映射值都是错误的,是否有任何有效的方法可以
提前解决此谢谢。
I am trying to code a smart contract and I am using a mapping (address => bool) ; i make it true when a certain conditions meet. Now for another condition I want my mapping to reset and loose all of its data , i want it to be where it was in the beginning a empty mapping.
Problem statement : I am setting all true for whoever voted using in my Dapp using a mapping ( address => bool ) now after voting is ended i want all my mapping values to be false , is there any efficient way to solve this
Thank you in advance..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
重置映射的唯一方法是迭代所有键并将值设置为零。这在牢固性上是不切实际的。
取而代之的是,您可能需要将映射与第三层使用,并具有
的数据元组(版本,键,值)
。然后,当您要进行完整重置时,请增加版本。另外,您可以执行
(键,版本,值)
并每次读取键时都会比较版本。这种方法可能会更有效,因为您在重写值时使用相同的存储批。The only way to reset mapping is to iterate through all the keys and set values to zero. This is not practical in Solidity.
Instead, you probably want to use mapping with the third layer and having data tuple of
(version, key, value)
. Then just increment version when you want to do a full reset.Alternatively you can do
(key, version, value)
and compare the version every time the key is read. This approach could be more gas efficient, as you are using the same storage lot when rewriting values.到目前为止,我发现这是最可行的。
I have found this as most feasible so far;