https://github.com/scorum/event-provider-go
https://github.com/scorum/event-provider-go
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/scorum/event-provider-go
- Owner: scorum
- License: mit
- Created: 2018-06-26T10:49:36.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-03-14T08:24:15.000Z (about 2 years ago)
- Last Synced: 2024-06-19T19:42:18.119Z (almost 2 years ago)
- Language: Go
- Size: 4.55 MB
- Stars: 2
- Watchers: 5
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# scorum/event-provider-go
[](https://goreportcard.com/report/github.com/scorum/event-provider-go)
[](https://godoc.org/github.com/scorum/event-provider-go)
[](https://travis-ci.org/scorum/event-provider-go.svg?branch=master)
Golang wrapper under [scorum-go](https://github.com/scorum/scorum-go).
## Usage
```go
import (
"context"
"time"
"os"
"os/signal"
"syscall"
"github.com/scorum/event-provider-go/event"
"github.com/scorum/event-provider-go/provider"
log "github.com/sirupsen/logrus"
)
func main() {
provider := provider.NewProvider("https://testnet.scorum.com", provider.SyncInterval(time.Second))
ctx, cancel := context.WithCancel(context.Background())
blocksCh, irreversibleBlocksCh, errorCh := provider.Provide(ctx, 2220447, 2220447,
[]event.Type{event.CommentEventType, event.PostEventType, event.VoteEventType, event.FlagEventType})
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
<-sigCh
cancel()
}()
for {
select {
case e := <-errorCh:
panic(e)
case <-ctx.Done():
return
case b := <-blocksCh:
log.Infof("reversible block %d with %d operations", b.BlockNum, len(b.Events))
case b := <-irreversibleBlocksCh:
log.Infof("irreversible block %d with %d operations", b.BlockNum, len(b.Events))
}
}
}
```