Skip to content

Commit

Permalink
chore: Add FetchEvents function to connection package (#23)
Browse files Browse the repository at this point in the history
Co-authored-by: mj52951 <[email protected]>
  • Loading branch information
mj52951 and mj52951 authored Apr 8, 2024
1 parent eb3fbea commit 240c91d
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 240c91d

Please sign in to comment.