go-ethereum/chain/derive_sha.go

21 lines
402 B
Go
Raw Normal View History

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