add error code for blocks length check

This commit is contained in:
Sina Mahmoodi 2023-10-24 18:14:04 +02:00
parent c02d29d8e4
commit e4eb56a4a9
2 changed files with 7 additions and 4 deletions

View file

@ -1230,11 +1230,9 @@ func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrO
// useful to execute and retrieve values. // useful to execute and retrieve values.
func (s *BlockChainAPI) MulticallV1(ctx context.Context, opts multicallOpts, blockNrOrHash *rpc.BlockNumberOrHash) ([]blockResult, error) { func (s *BlockChainAPI) MulticallV1(ctx context.Context, opts multicallOpts, blockNrOrHash *rpc.BlockNumberOrHash) ([]blockResult, error) {
if len(opts.BlockStateCalls) == 0 { if len(opts.BlockStateCalls) == 0 {
// TODO return error code. return nil, &invalidParamsError{message: "empty input"}
return nil, errors.New("invalid params")
} else if len(opts.BlockStateCalls) > maxMulticallBlocks { } else if len(opts.BlockStateCalls) > maxMulticallBlocks {
// TODO return error code. return nil, &invalidParamsError{message: "too many blocks"}
return nil, errors.New("invalid params")
} }
if blockNrOrHash == nil { if blockNrOrHash == nil {
n := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber) n := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)

View file

@ -68,3 +68,8 @@ func callErrorFromError(err error) *callError {
Code: errCodeInternalError, Code: errCodeInternalError,
} }
} }
type invalidParamsError struct{ message string }
func (e *invalidParamsError) Error() string { return e.message }
func (e *invalidParamsError) ErrorCode() int { return errCodeInvalidParams }