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 c10cdf4
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 @@ -77,6 +77,12 @@ func (c *Client) StartEventsListening() (func(), <-chan error, error) {
case <-done:
return
case set := <-sub.Chan():
header, err := c.RPC.Chain.GetHeader(set.Block)
if err != nil {
c.errsListening <- fmt.Errorf("get header: %w", err)
continue
}

for _, change := range set.Changes {
if !codec.Eq(change.StorageKey, key) || !change.HasStorageData {
continue
Expand All @@ -89,7 +95,7 @@ func (c *Client) StartEventsListening() (func(), <-chan error, error) {
}

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

0 comments on commit c10cdf4

Please sign in to comment.