-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnew_blocks.go
36 lines (28 loc) · 1.04 KB
/
new_blocks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package bloxroute_sdk_go
import (
"context"
"github.com/bloXroute-Labs/gateway/v2/types"
)
// NewBlockParams is the params object for the OnNewBlock subscription
type NewBlockParams struct {
// Include is the list of fields to include in the response.
// The values of these fields depend on the feed type.
// Optional (defaults to ["hash", "header"])
Include []string `json:"include"`
}
// OnNewBlock subscribes to a stream of all new blocks as they are propagated in the BDN.
func (c *Client) OnNewBlock(ctx context.Context, params *NewBlockParams, callbackFunc CallbackFunc[*OnBdnBlockNotification]) error {
if params == nil {
params = &NewBlockParams{}
}
if len(params.Include) == 0 {
params.Include = []string{"hash", "header"}
}
wrap := func(ctx context.Context, err error, result any) {
callbackFunc(ctx, err, result.(*OnBdnBlockNotification))
}
return c.handler.Subscribe(ctx, types.NewBlocksFeed, params, wrap)
}
func (c *Client) UnsubscribeFromOnNewBlock() error {
return c.handler.UnsubscribeRetry(types.NewBlocksFeed)
}