Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions api/handler/blockHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package handler

import (
"context"
"fmt"

"github.com/zoobc/zoobc-core/api/service"
"github.com/zoobc/zoobc-core/common/constant"
"github.com/zoobc/zoobc-core/common/chaintype"
"github.com/zoobc/zoobc-core/common/model"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

// BlockHandler to handle request related to Blocks from client
Expand Down Expand Up @@ -35,6 +39,10 @@ func (bs *BlockHandler) GetBlock(ctx context.Context, req *model.GetBlockRequest

// GetBlocks handles request to get data of multiple blocks
func (bs *BlockHandler) GetBlocks(ctx context.Context, req *model.GetBlocksRequest) (*model.GetBlocksResponse, error) {
if req.Limit > constant.MaxAPIGetBlocks {
return nil, status.Error(codes.OutOfRange, fmt.Sprintf("limit exceeded, max. %d", constant.MaxAPIGetBlocks))
}

chainType := chaintype.GetChainType(req.ChainType)
blocksResponse, err := bs.Service.GetBlocks(chainType, req.Limit, req.Height)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions common/constant/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package constant

var (
MaxAPIRequestPerSecond uint32 = 10
MaxAPIGetBlocks uint32 = 500
)