github.com/iotexproject/iotex-core@v1.14.1-rc1/db/trie/mptrie/layertwoleafiterator.go (about)

     1  // Copyright (c) 2018 IoTeX
     2  // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
     3  // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
     4  // This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
     5  
     6  package mptrie
     7  
     8  import (
     9  	"github.com/pkg/errors"
    10  
    11  	"github.com/iotexproject/iotex-core/db/trie"
    12  )
    13  
    14  // NewLayerTwoLeafIterator returns a new leaf iterator
    15  func NewLayerTwoLeafIterator(tr trie.TwoLayerTrie, layerOneKey []byte, l int) (trie.Iterator, error) {
    16  	tlt, ok := tr.(*twoLayerTrie)
    17  	if !ok {
    18  		return nil, errors.New("trie is not supported type")
    19  	}
    20  	lt, err := tlt.layerTwoTrie(layerOneKey, l)
    21  	if err != nil {
    22  		return nil, err
    23  	}
    24  	return NewLeafIterator(lt.tr)
    25  }