Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. But how can we get the merkle root or a proof for a particular leaf using this? I see the API doesn't provide any functions named as such.

like image 484
vim Avatar asked Jul 26 '19 11:07

vim


2 Answers

The srml_support::storage::child API make use of sr_io API.

sr_io provides more functionality, for example sr_io::child_storage_root which is the function you are looking for.

like image 118
thiolliere Avatar answered Oct 13 '22 06:10

thiolliere


An alternative is to directly query the parent trie node containing the root. 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):

let id = Self::id_from_index(index);
let child_root = storage::unhashed::get_raw(id.as_ref());
like image 2
cheme Avatar answered Oct 13 '22 06:10

cheme