diff --git a/api/handler/blockHandler.go b/api/handler/blockHandler.go index 3dcd72be7..ced11a48a 100644 --- a/api/handler/blockHandler.go +++ b/api/handler/blockHandler.go @@ -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 @@ -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 { diff --git a/common/constant/api.go b/common/constant/api.go index 3810f37e3..8ededaa5a 100644 --- a/common/constant/api.go +++ b/common/constant/api.go @@ -2,4 +2,5 @@ package constant var ( MaxAPIRequestPerSecond uint32 = 10 + MaxAPIGetBlocks uint32 = 500 )