go-ethereum/chain/derive_sha.go

21 lines
402 B
Go
Raw Normal View History

2014-10-31 11:59:17 +02:00
package chain
2014-10-29 11:29:22 +02:00
import (
"github.com/ethereum/go-ethereum/ethutil"
2014-10-31 15:45:03 +02:00
"github.com/ethereum/go-ethereum/trie"
2014-10-29 11:29:22 +02:00
)
type DerivableList interface {
Len() int
GetRlp(i int) []byte
}
func DeriveSha(list DerivableList) []byte {
2014-10-31 15:45:03 +02:00
trie := trie.New(ethutil.Config.Db, "")
2014-10-29 11:29:22 +02:00
for i := 0; i < list.Len(); i++ {
trie.Update(string(ethutil.NewValue(i).Encode()), string(list.GetRlp(i)))
}
return trie.GetRoot()
}