Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a template function to retrieve past events #58

Merged
merged 2 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tools/generators/ethereum/contract_events.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@ type {{$contract.FullVar}}{{$event.CapsName}}Func func(
{{$event.ParamDeclarations -}}
)

func ({{$contract.ShortVar}} *{{$contract.Class}}) Past{{$event.CapsName}}Events(
startBlock uint64,
endBlock *uint64,
{{$event.IndexedFilterDeclarations -}}
) ([]*abi.{{$contract.AbiClass}}{{$event.CapsName}}, error){
iterator, err := {{$contract.ShortVar}}.contract.Filter{{$event.CapsName}}(
&bind.FilterOpts{
Start: startBlock,
End: endBlock,
},
{{$event.IndexedFilters}}
)
if err != nil {
return nil, fmt.Errorf(
"error retrieving past {{$event.CapsName}} events: [%v]",
err,
)
}

events := make([]*abi.{{$contract.AbiClass}}{{$event.CapsName}}, 0)

for iterator.Next() {
event := iterator.Event
events = append(events, event)
}

return events, nil
}

func ({{$contract.ShortVar}} *{{$contract.Class}}) Watch{{$event.CapsName}}(
success {{$contract.FullVar}}{{$event.CapsName}}Func,
fail func(err error) error,
Expand Down
29 changes: 29 additions & 0 deletions tools/generators/ethereum/contract_events_template_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,35 @@ type {{$contract.FullVar}}{{$event.CapsName}}Func func(
{{$event.ParamDeclarations -}}
)

func ({{$contract.ShortVar}} *{{$contract.Class}}) Past{{$event.CapsName}}Events(
startBlock uint64,
endBlock *uint64,
{{$event.IndexedFilterDeclarations -}}
) ([]*abi.{{$contract.AbiClass}}{{$event.CapsName}}, error){
iterator, err := {{$contract.ShortVar}}.contract.Filter{{$event.CapsName}}(
&bind.FilterOpts{
Start: startBlock,
End: endBlock,
},
{{$event.IndexedFilters}}
)
if err != nil {
return nil, fmt.Errorf(
"error retrieving past {{$event.CapsName}} events: [%v]",
err,
)
}

events := make([]*abi.{{$contract.AbiClass}}{{$event.CapsName}}, 0)

for iterator.Next() {
event := iterator.Event
events = append(events, event)
}

return events, nil
}

func ({{$contract.ShortVar}} *{{$contract.Class}}) Watch{{$event.CapsName}}(
success {{$contract.FullVar}}{{$event.CapsName}}Func,
fail func(err error) error,
Expand Down