Merge branch 'staging' into batch-historical-headers

This commit is contained in:
Takayuki Goto 2019-01-16 15:56:36 -06:00 committed by GitHub
commit 54d771cb06
2 changed files with 18 additions and 5 deletions

View File

@ -17,6 +17,7 @@ package shared
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"strings"
)
type Chunker interface {
@ -42,7 +43,8 @@ func NewLogChunker() *LogChunker {
func (chunker *LogChunker) AddConfigs(transformerConfigs []TransformerConfig) {
for _, config := range transformerConfigs {
for _, address := range config.ContractAddresses {
chunker.AddressToNames[address] = append(chunker.AddressToNames[address], config.TransformerName)
var lowerCaseAddress = strings.ToLower(address)
chunker.AddressToNames[lowerCaseAddress] = append(chunker.AddressToNames[lowerCaseAddress], config.TransformerName)
chunker.NameToTopic0[config.TransformerName] = common.HexToHash(config.Topic)
}
}
@ -53,7 +55,7 @@ func (chunker *LogChunker) ChunkLogs(logs []types.Log) map[string][]types.Log {
chunks := map[string][]types.Log{}
for _, log := range logs {
// Topic0 is not unique to each transformer, also need to consider the contract address
relevantTransformers := chunker.AddressToNames[log.Address.String()]
relevantTransformers := chunker.AddressToNames[strings.ToLower(log.Address.String())]
for _, transformer := range relevantTransformers {
if chunker.NameToTopic0[transformer] == log.Topics[0] {

View File

@ -54,9 +54,9 @@ var _ = Describe("Log chunker", func() {
Describe("initialisation", func() {
It("creates lookup maps correctly", func() {
Expect(chunker.AddressToNames).To(Equal(map[string][]string{
"0x00000000000000000000000000000000000000A1": []string{"TransformerA"},
"0x00000000000000000000000000000000000000A2": []string{"TransformerA", "TransformerC"},
"0x00000000000000000000000000000000000000B1": []string{"TransformerB"},
"0x00000000000000000000000000000000000000a1": []string{"TransformerA"},
"0x00000000000000000000000000000000000000a2": []string{"TransformerA", "TransformerC"},
"0x00000000000000000000000000000000000000b1": []string{"TransformerB"},
}))
Expect(chunker.NameToTopic0).To(Equal(map[string]common.Hash{
@ -79,6 +79,17 @@ var _ = Describe("Log chunker", func() {
Expect(chunker.AddressToNames).To(ContainElement([]string{"TransformerD"}))
Expect(chunker.NameToTopic0).To(ContainElement(common.HexToHash("0xD")))
})
It("lower cases address", func() {
configD := shared.TransformerConfig{
TransformerName: "TransformerD",
ContractAddresses: []string{"0x000000000000000000000000000000000000000D"},
Topic: "0xD",
}
chunker.AddConfigs([]shared.TransformerConfig{configD})
Expect(chunker.AddressToNames["0x000000000000000000000000000000000000000d"]).To(Equal([]string{"TransformerD"}))
})
})
Describe("ChunkLogs", func() {