plugeth/chain/derive_sha.go
2014-10-31 10:59:17 +01:00

21 lines
408 B
Go

package chain
import (
"github.com/ethereum/go-ethereum/ethtrie"
"github.com/ethereum/go-ethereum/ethutil"
)
type DerivableList interface {
Len() int
GetRlp(i int) []byte
}
func DeriveSha(list DerivableList) []byte {
trie := ethtrie.New(ethutil.Config.Db, "")
for i := 0; i < list.Len(); i++ {
trie.Update(string(ethutil.NewValue(i).Encode()), string(list.GetRlp(i)))
}
return trie.GetRoot()
}