Skip to content

Commit

Permalink
Added fetchEvents function to connection package
Browse files Browse the repository at this point in the history
  • Loading branch information
mj52951 committed Apr 4, 2024
1 parent eb3fbea commit d56ed6c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions chains/substrate/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package connection

import (
"math/big"
"sync"

"github.com/centrifuge/go-substrate-rpc-client/v4/client"
Expand Down Expand Up @@ -86,3 +87,20 @@ func (c *Connection) GetBlockEvents(hash types.Hash) ([]*parser.Event, error) {
}
return evts, nil
}

func (c *Connection) FetchEvents(startBlock, endBlock *big.Int) ([]*parser.Event, error) {
evts := make([]*parser.Event, 0)
for i := new(big.Int).Set(startBlock); i.Cmp(endBlock) == -1; i.Add(i, big.NewInt(1)) {
hash, err := c.GetBlockHash(i.Uint64())
if err != nil {
return nil, err
}

evt, err := c.GetBlockEvents(hash)
if err != nil {
return nil, err
}
evts = append(evts, evt...)
}
return evts, nil
}

0 comments on commit d56ed6c

Please sign in to comment.