Skip to content

Commit

Permalink
Add http handler to sync atxs received after given timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
kacpersaw committed Apr 2, 2024
1 parent 40e00b6 commit 141d51a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions collector/http.go
Expand Up @@ -12,13 +12,37 @@ import (

func (c *Collector) StartHttpServer(apiHost string, apiPort int) {
e := echo.New()

e.GET("/sync/atx/ts/:ts", func(ctx echo.Context) error {
ts := ctx.Param("ts")
timestamp, err := strconv.ParseInt(ts, 10, 64)
if err != nil {
return ctx.String(http.StatusBadRequest, "Invalid parameter")
}

log.Info("http syncing atxs from %d", timestamp)
go func() {
err = c.dbClient.GetAtxsReceivedAfter(c.db, timestamp, func(atx *types.VerifiedActivationTx) bool {
c.listener.OnActivation(atx)
return true
})
if err != nil {
log.Warning("syncing atxs from %s failed with error %d", ts, err)
return
}
}()

return ctx.NoContent(http.StatusOK)
})

e.GET("/sync/atx/:epoch", func(ctx echo.Context) error {
epoch := ctx.Param("epoch")
epochId, err := strconv.ParseInt(epoch, 10, 64)
if err != nil {
return ctx.String(http.StatusBadRequest, "Invalid parameter")
}

log.Info("http syncing atxs for epoch %s", epoch)
go func() {
err = c.dbClient.GetAtxsByEpoch(c.db, epochId, func(atx *types.VerifiedActivationTx) bool {
c.listener.OnActivation(atx)
Expand Down

0 comments on commit 141d51a

Please sign in to comment.