plugeth/chain/derive_sha.go

21 lines
402 B
Go
Raw Normal View History

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