github.com/okex/exchain@v1.8.0/libs/tendermint/crypto/merkle/ibc_adapter_tree.go (about) 1 package merkle 2 3 import "github.com/okex/exchain/libs/tendermint/crypto/tmhash" 4 5 func HashFromByteSlices(items [][]byte) []byte { 6 switch len(items) { 7 case 0: 8 return emptyHash() 9 case 1: 10 return leafHash(items[0]) 11 default: 12 k := getSplitPoint(len(items)) 13 left := HashFromByteSlices(items[:k]) 14 right := HashFromByteSlices(items[k:]) 15 return innerHash(left, right) 16 } 17 } 18 19 // returns tmhash(<empty>) 20 func emptyHash() []byte { 21 return tmhash.Sum([]byte{}) 22 } 23 24 // ProofsFromByteSlices computes inclusion proof for given items. 25 // proofs[0] is the proof for items[0]. 26 func ProofsFromByteSlices(items [][]byte) (rootHash []byte, proofs []*SimpleProof) { 27 trails, rootSPN := trailsFromByteSlices(items) 28 rootHash = rootSPN.Hash 29 proofs = make([]*SimpleProof, len(items)) 30 for i, trail := range trails { 31 proofs[i] = &SimpleProof{ 32 Total: len(items), 33 Index: i, 34 LeafHash: trail.Hash, 35 Aunts: trail.FlattenAunts(), 36 } 37 } 38 return 39 }