Skip to content

Commit

Permalink
fix event parsing when reading from pending block
Browse files Browse the repository at this point in the history
  • Loading branch information
augustbleeds committed Jun 13, 2024
1 parent 3b2290d commit 7bf092e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion relayer/pkg/chainlink/ocr2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,18 @@ func (c *Client) LinkAvailableForPayment(ctx context.Context, address *felt.Felt
}

func (c *Client) fetchEventsFromBlock(ctx context.Context, address *felt.Felt, eventType string, blockNum uint64) (events []starknetrpc.EmittedEvent, err error) {
block := starknetrpc.WithBlockNumber(blockNum)
latestBlockHeight, err := c.r.LatestBlockHeight(ctx)
if err != nil {
return nil, fmt.Errorf("couldn't fetch latest block height: %w", err)
}

var block starknetrpc.BlockID
// "blockNum" may be available on-chain, but unqueryable via the RPC because the block is pending
if blockNum > latestBlockHeight {
block = starknetrpc.WithBlockTag("pending")
} else {
block = starknetrpc.WithBlockNumber(blockNum)
}

eventKey := starknetutils.GetSelectorFromNameFelt(eventType)

Expand Down

0 comments on commit 7bf092e

Please sign in to comment.