简体   繁体   English

如何获得roothash或来自孩子的证据?

[英]How to get the roothash or a proof from a child trie in substrate?

According to the example here , I see one could use the srml_support::storage::child API to create a merkle sub trie out of arbitrary data. 根据这里的例子,我看到可以使用srml_support::storage::child API从任意数据中创建一个merkle子trie。 But how can we get the merkle root or a proof for a particular leaf using this? 但是我们怎样才能获得merkle root或使用它的特定叶子的证明? I see the API doesn't provide any functions named as such. 我看到API没有提供任何这样命名的函数。

The srml_support::storage::child API make use of sr_io API. srml_support::storage::child API使用sr_io API。

sr_io provides more functionality, for example sr_io::child_storage_root which is the function you are looking for. sr_io提供了更多功能,例如sr_io :: child_storage_root ,这是您正在寻找的功能。

An alternative is to directly query the parent trie node containing the root. 另一种方法是直接查询包含根的父trie节点。 For the linked exemple it will be something like this (child_storage_root is doing calculation of ongoing change whereas querying directly the root get the state at the start of the block processing or the latest stored state calculation): 对于链接的例子,它将是这样的(child_storage_root正在计算正在进行的更改,而直接查询根获取块处理开始时的状态或最新存储状态计算):

let id = Self::id_from_index(index);
let child_root = storage::unhashed::get_raw(id.as_ref());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM