aboutsummaryrefslogtreecommitdiffstats
path: root/core/types/derive_sha.go
blob: 10e3d74468e9a82b4ebebf3804ec70c5b6c15315 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package types

import (
    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/ethdb"
    "github.com/ethereum/go-ethereum/rlp"
    "github.com/ethereum/go-ethereum/trie"
)

type DerivableList interface {
    Len() int
    GetRlp(i int) []byte
}

func DeriveSha(list DerivableList) common.Hash {
    db, _ := ethdb.NewMemDatabase()
    trie := trie.New(nil, db)
    for i := 0; i < list.Len(); i++ {
        key, _ := rlp.EncodeToBytes(i)
        trie.Update(key, list.GetRlp(i))
    }

    return common.BytesToHash(trie.Root())
}