diff options
Diffstat (limited to 'chain/types/derive_sha.go')
-rw-r--r-- | chain/types/derive_sha.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/chain/types/derive_sha.go b/chain/types/derive_sha.go new file mode 100644 index 000000000..1897ff198 --- /dev/null +++ b/chain/types/derive_sha.go @@ -0,0 +1,20 @@ +package types + +import ( + "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/trie" +) + +type DerivableList interface { + Len() int + GetRlp(i int) []byte +} + +func DeriveSha(list DerivableList) []byte { + trie := trie.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() +} |