Skip to content

Commit

Permalink
chg: fix negative blockNums
Browse files Browse the repository at this point in the history
  • Loading branch information
marcello33 committed Nov 13, 2024
1 parent 8b52903 commit cab287e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions bor/client/grpc/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func (h *BorGRPCClient) GetVoteOnHash(ctx context.Context, startBlock uint64, en
return res.Response, nil
}

func (h *BorGRPCClient) HeaderByNumber(ctx context.Context, blockID uint64) (*ethTypes.Header, error) {
func (h *BorGRPCClient) HeaderByNumber(ctx context.Context, blockID int64) (*ethTypes.Header, error) {

if blockID > math.MaxInt64 {
return nil, fmt.Errorf("blockID too large: %d", blockID)
}

blockNumberAsString := ToBlockNumArg(big.NewInt(int64(blockID)))
blockNumberAsString := ToBlockNumArg(big.NewInt(blockID))

req := &proto.GetHeaderByNumberRequest{
Number: blockNumberAsString,
Expand All @@ -85,13 +85,13 @@ func (h *BorGRPCClient) HeaderByNumber(ctx context.Context, blockID uint64) (*et
return resp, nil
}

func (h *BorGRPCClient) BlockByNumber(ctx context.Context, blockID uint64) (*ethTypes.Block, error) {
func (h *BorGRPCClient) BlockByNumber(ctx context.Context, blockID int64) (*ethTypes.Block, error) {

if blockID > math.MaxInt64 {
return nil, fmt.Errorf("blockID too large: %d", blockID)
}

blockNumberAsString := ToBlockNumArg(big.NewInt(int64(blockID)))
blockNumberAsString := ToBlockNumArg(big.NewInt(blockID))

req := &proto.GetBlockByNumberRequest{
Number: blockNumberAsString,
Expand Down
4 changes: 2 additions & 2 deletions helper/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func (c *ContractCaller) GetMaticChainBlock(blockNum *big.Int) (header *ethTypes
// LatestBlockNumber is BlockNumber(-2) in go-ethereum rpc
latestBlock, err = c.MaticGrpcClient.HeaderByNumber(ctx, -2)
} else {
latestBlock, err = c.MaticGrpcClient.HeaderByNumber(ctx, blockNum.Uint64())
latestBlock, err = c.MaticGrpcClient.HeaderByNumber(ctx, blockNum.Int64())
}
} else {
latestBlock, err = c.MaticChainClient.HeaderByNumber(ctx, blockNum)
Expand Down Expand Up @@ -888,7 +888,7 @@ func (c *ContractCaller) GetBlockByNumber(ctx context.Context, blockNumber uint6
var err error

if c.MaticGrpcFlag {
block, err = c.MaticGrpcClient.BlockByNumber(ctx, blockNumber)
block, err = c.MaticGrpcClient.BlockByNumber(ctx, int64(blockNumber))
} else {
block, err = c.MaticChainClient.BlockByNumber(ctx, big.NewInt(int64(blockNumber)))
}
Expand Down

0 comments on commit cab287e

Please sign in to comment.