1

How to use following data structure of solidity in substrate?

 struct SortitionSumTree {
        uint K; 
        uint[] stack;
        uint[] nodes;
        mapping(bytes32 => uint) IDsToTreeIndexes;
        mapping(uint => bytes32) nodeIndexesToIDs;
    }

    /* Storage */

    struct SortitionSumTrees {
        mapping(bytes32 => SortitionSumTree) sortitionSumTrees;
    }
 

Should I use BTreeMap instead of mapping of solidity in the struct? https://paritytech.github.io/substrate/master/sp_std/collections/btree_map/struct.BTreeMap.html

#[derive(PartialEq, Eq, PartialOrd, Ord, Default, Clone, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct SortitionSumTree {
    pub k: u128,
    pub stack: u128,
    pub nodes: u128,
    pub ids_to_tree_indexes: BTreeMap<Vec<u8>, u128>,
    pub node_indexes_to_ids: BTreeMap<u128, Vec<u8>>,
}


#[pallet::storage]
#[pallet::getter(fn sortition_sum_trees)]
pub type SortitionSumTrees<T> = StorageMap<_,Blake2_128Concat, Vec<u8>, SortitionSumTree>;

Is it right way of doing it in substrate?

Amiya Behera
  • 2,210
  • 19
  • 32

0 Answers0