Skip to content

Commit

Permalink
Pass block number and hash to events listener
Browse files Browse the repository at this point in the history
  • Loading branch information
khssnv committed Mar 14, 2024
1 parent 41380fa commit 3dca6df
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions blockchain/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/cerebellum-network/cere-ddc-sdk-go/blockchain/pallets"
)

type EventsListener func(*pallets.Events)
type EventsListener func(events *pallets.Events, blockNumber types.BlockNumber, blockHash types.Hash)

type Client struct {
*gsrpc.SubstrateAPI
Expand Down Expand Up @@ -88,8 +88,14 @@ func (c *Client) StartEventsListening() (func(), <-chan error, error) {
c.errsListening <- fmt.Errorf("events decoder: %w", err)
}

header, err := c.RPC.Chain.GetHeader(set.Block)
if err != nil {
c.errsListening <- fmt.Errorf("get header: %w", err)
continue
}

for _, callback := range c.eventsListeners {
go callback(events)
go callback(events, header.Number, set.Block)
}
}
}
Expand Down

0 comments on commit 3dca6df

Please sign in to comment.