Extract helper for converting hex to keccak256 hash

- Also prefer crypto.Keccak256Hash(x) to common.BytesToHash(crypto.Keccak256(x))
This commit is contained in:
Rob Mulholand
2019-09-25 16:36:08 -05:00
committed by Elizabeth Engelman
parent d06dddbfaa
commit 2ff88de859
8 changed files with 20 additions and 25 deletions
+5 -2
View File
@@ -42,9 +42,8 @@ func FromParityCsvRow(csvRow []string) (StorageDiff, error) {
if err != nil {
return StorageDiff{}, err
}
hashedAddr := crypto.Keccak256(common.FromHex(csvRow[0]))
return StorageDiff{
KeccakOfContractAddress: common.BytesToHash(hashedAddr),
KeccakOfContractAddress: HexToKeccak256Hash(csvRow[0]),
BlockHash: common.HexToHash(csvRow[1]),
BlockHeight: height,
StorageKey: common.HexToHash(csvRow[3]),
@@ -61,3 +60,7 @@ func FromGethStateDiff(account statediff.AccountDiff, stateDiff *statediff.State
StorageValue: common.BytesToHash(storage.Value),
}
}
func HexToKeccak256Hash(addr string) common.Hash {
return crypto.Keccak256Hash(common.FromHex(addr))
}
+1 -2
View File
@@ -18,7 +18,6 @@ package utils_test
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/statediff"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -41,7 +40,7 @@ var _ = Describe("Storage row parsing", func() {
result, err := utils.FromParityCsvRow(data)
Expect(err).NotTo(HaveOccurred())
expectedKeccakOfContractAddress := common.BytesToHash(crypto.Keccak256(common.FromHex(contract)))
expectedKeccakOfContractAddress := utils.HexToKeccak256Hash(contract)
Expect(result.KeccakOfContractAddress).To(Equal(expectedKeccakOfContractAddress))
Expect(result.BlockHash).To(Equal(common.HexToHash(blockHash)))
Expect(result.BlockHeight).To(Equal(789))