aboutsummaryrefslogtreecommitdiff
path: root/core/types/derive_sha.go
diff options
context:
space:
mode:
authorTed Yin <tederminant@gmail.com>2020-09-18 13:14:29 -0400
committerGitHub <noreply@github.com>2020-09-18 13:14:29 -0400
commitd048937c48753d9eaef771bf71820cf95d79df26 (patch)
tree1a7f65fcd72e77092525ab01625b8b9d365e3e40 /core/types/derive_sha.go
parent7d1388c743b4ec8f4a86bea95bfada785dee83f7 (diff)
parent7d8c85cf8895b0f998d8eafb02f99d5b689fcd59 (diff)
Merge pull request #34 from ava-labs/devv0.3.0-rc.5
Dev
Diffstat (limited to 'core/types/derive_sha.go')
-rw-r--r--core/types/derive_sha.go21
1 files changed, 14 insertions, 7 deletions
diff --git a/core/types/derive_sha.go b/core/types/derive_sha.go
index 8234191..7d40c7f 100644
--- a/core/types/derive_sha.go
+++ b/core/types/derive_sha.go
@@ -19,23 +19,30 @@ package types
import (
"bytes"
- "github.com/ava-labs/go-ethereum/common"
- "github.com/ava-labs/go-ethereum/rlp"
- "github.com/ava-labs/go-ethereum/trie"
+ "github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/rlp"
)
+// DerivableList is the interface which can derive the hash.
type DerivableList interface {
Len() int
GetRlp(i int) []byte
}
-func DeriveSha(list DerivableList) common.Hash {
+// Hasher is the tool used to calculate the hash of derivable list.
+type Hasher interface {
+ Reset()
+ Update([]byte, []byte)
+ Hash() common.Hash
+}
+
+func DeriveSha(list DerivableList, hasher Hasher) common.Hash {
+ hasher.Reset()
keybuf := new(bytes.Buffer)
- trie := new(trie.Trie)
for i := 0; i < list.Len(); i++ {
keybuf.Reset()
rlp.Encode(keybuf, uint(i))
- trie.Update(keybuf.Bytes(), list.GetRlp(i))
+ hasher.Update(keybuf.Bytes(), list.GetRlp(i))
}
- return trie.Hash()
+ return hasher.Hash()
}