aboutsummaryrefslogtreecommitdiff
path: root/core/types/derive_sha.go
diff options
context:
space:
mode:
authorDeterminant <tederminant@gmail.com>2020-09-15 23:55:34 -0400
committerDeterminant <tederminant@gmail.com>2020-09-15 23:55:34 -0400
commit78745551c077bf54151202138c2629f288769561 (patch)
tree2b628e99fd110617089778fa91235ecd2888f4ef /core/types/derive_sha.go
parent7d1388c743b4ec8f4a86bea95bfada785dee83f7 (diff)
WIP: geth-tavum
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()
}