ipld-eth-server/libraries/shared/watcher.go
Matt Krump 06f78e0083 Handle events
- Adds interfaces for developers to build handlers that update data in
response to log events
- Resolves #29
2018-03-05 10:01:50 -06:00

28 lines
614 B
Go

package shared
import (
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
)
type Watcher struct {
Handlers []Handler
DB postgres.DB
Blockchain core.ContractDataFetcher
}
func (watcher *Watcher) AddHandlers(us []HandlerInitializer) {
for _, handlerInitializer := range us {
handler := handlerInitializer(&watcher.DB, watcher.Blockchain)
watcher.Handlers = append(watcher.Handlers, handler)
}
}
func (watcher *Watcher) Execute() error {
var err error
for _, handler := range watcher.Handlers {
err = handler.Execute()
}
return err
}