forked from cerc-io/ipld-eth-server
lowercase address on map to get transformers
This commit is contained in:
parent
518bfbaf54
commit
24cf0661b0
@ -17,6 +17,7 @@ package shared
|
|||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Chunker interface {
|
type Chunker interface {
|
||||||
@ -42,7 +43,8 @@ func NewLogChunker() *LogChunker {
|
|||||||
func (chunker *LogChunker) AddConfigs(transformerConfigs []TransformerConfig) {
|
func (chunker *LogChunker) AddConfigs(transformerConfigs []TransformerConfig) {
|
||||||
for _, config := range transformerConfigs {
|
for _, config := range transformerConfigs {
|
||||||
for _, address := range config.ContractAddresses {
|
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)
|
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{}
|
chunks := map[string][]types.Log{}
|
||||||
for _, log := range logs {
|
for _, log := range logs {
|
||||||
// Topic0 is not unique to each transformer, also need to consider the contract address
|
// 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 {
|
for _, transformer := range relevantTransformers {
|
||||||
if chunker.NameToTopic0[transformer] == log.Topics[0] {
|
if chunker.NameToTopic0[transformer] == log.Topics[0] {
|
||||||
|
@ -54,9 +54,9 @@ var _ = Describe("Log chunker", func() {
|
|||||||
Describe("initialisation", func() {
|
Describe("initialisation", func() {
|
||||||
It("creates lookup maps correctly", func() {
|
It("creates lookup maps correctly", func() {
|
||||||
Expect(chunker.AddressToNames).To(Equal(map[string][]string{
|
Expect(chunker.AddressToNames).To(Equal(map[string][]string{
|
||||||
"0x00000000000000000000000000000000000000A1": []string{"TransformerA"},
|
"0x00000000000000000000000000000000000000a1": []string{"TransformerA"},
|
||||||
"0x00000000000000000000000000000000000000A2": []string{"TransformerA", "TransformerC"},
|
"0x00000000000000000000000000000000000000a2": []string{"TransformerA", "TransformerC"},
|
||||||
"0x00000000000000000000000000000000000000B1": []string{"TransformerB"},
|
"0x00000000000000000000000000000000000000b1": []string{"TransformerB"},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
Expect(chunker.NameToTopic0).To(Equal(map[string]common.Hash{
|
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.AddressToNames).To(ContainElement([]string{"TransformerD"}))
|
||||||
Expect(chunker.NameToTopic0).To(ContainElement(common.HexToHash("0xD")))
|
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() {
|
Describe("ChunkLogs", func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user