Skip to content

Commit

Permalink
fix event_calls block filters
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBger committed Oct 30, 2024
1 parent 16f01f3 commit 5a72468
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 20 deletions.
63 changes: 43 additions & 20 deletions evm-events-calls/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,48 +75,71 @@ func isValidChainName(input string) bool {
return ChainConfigByID[input] != nil
}

func (p *Project) ApplyEventsBlockFilter() bool {
for _, dcontract := range p.DynamicContracts {
if dcontract.TrackEvents {
return false
}
}

for _, contract := range p.Contracts {
if contract.TrackEvents {
return true
}
}

return false
}

func (p *Project) ApplyCallsBlockFilter() bool {
for _, dcontract := range p.DynamicContracts {
if dcontract.TrackCalls {
return false
}
}

for _, contract := range p.Contracts {
if contract.TrackCalls {
return true
}
}

return false
}

func (p *Project) GenerateEventsBlockFilterQuery() string {
var query string
for i, contract := range p.Contracts {
if i == 0 {
query = fmt.Sprintf("evt_addr:%s", contract.Address)
for _, contract := range p.Contracts {
if !contract.TrackEvents {
continue
}

query += fmt.Sprintf(" || evt_addr:%s", contract.Address)
}

for i, dynamicContract := range p.DynamicContracts {
if i == 0 {
query += fmt.Sprintf(" || evt_addr:%s", dynamicContract.ReferenceContractAddress)
if query == "" {
query = fmt.Sprintf("evt_addr:%s", contract.Address)
continue
}

query += fmt.Sprintf(" || evt_addr:%s", dynamicContract.ReferenceContractAddress)
query += fmt.Sprintf(" || evt_addr:%s", contract.Address)
}

return query
}

func (p *Project) GenerateCallsBlockFilterQuery() string {
var query string
for i, contract := range p.Contracts {
if i == 0 {
query = fmt.Sprintf("call_to:%s", contract.Address)
for _, contract := range p.Contracts {
if !contract.TrackCalls {
continue
}

query += fmt.Sprintf(" || call_to:%s", contract.Address)
}

for i, dynamicContract := range p.DynamicContracts {
if i == 0 {
query += fmt.Sprintf(" || call_to:%s", dynamicContract.ReferenceContractAddress)
if query == "" {
query = fmt.Sprintf("call_to:%s", contract.Address)
continue
}

query += fmt.Sprintf(" || call_to:%s", dynamicContract.ReferenceContractAddress)
query += fmt.Sprintf(" || call_to:%s", contract.Address)
}

return query
}

Expand Down
8 changes: 8 additions & 0 deletions evm-events-calls/templates/substreams.yaml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ modules:
initialBlock: {{ with $ddsContract.ParentContract.InitialBlock }}{{ . }}{{ else }}0{{ end }}
updatePolicy: set
valueType: proto:dynamic_datasource
blockFilter:
module: ethcommon:index_events
query:
string: evt_addr:{{ $ddsContract.ParentContract.Address }}
inputs:
- source: sf.ethereum.type.v2.Block
{{- end}}
Expand All @@ -35,11 +39,13 @@ modules:
- name: map_events
kind: map
initialBlock: {{ .MustLowestStartBlock }}
{{- if .ApplyEventsBlockFilter }}
blockFilter:
module: ethcommon:index_events
{{- $eventQuery := .GenerateEventsBlockFilterQuery }}
query:
string: {{ $eventQuery }}
{{- end }}
inputs:
- source: sf.ethereum.type.v2.Block
{{- range $index, $ddsContract := .DynamicContracts }}
Expand All @@ -54,11 +60,13 @@ modules:
- name: map_calls
kind: map
initialBlock: {{ .MustLowestStartBlock }}
{{- if .ApplyCallsBlockFilter }}
blockFilter:
module: ethcommon:index_calls
{{- $callQuery := .GenerateCallsBlockFilterQuery }}
query:
string: {{ $callQuery }}
{{- end }}
inputs:
- source: sf.ethereum.type.v2.Block
{{- range $index, $ddsContract := .DynamicContracts }}
Expand Down

0 comments on commit 5a72468

Please sign in to comment.