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.
func (s *BlockChainAPI) MulticallV1(ctx context.Context, opts multicallOpts, blockNrOrHash *rpc.BlockNumberOrHash) ([]blockResult, error) {
if len(opts.BlockStateCalls) == 0 {
// TODO return error code.
return nil, errors.New("invalid params")
return nil, &invalidParamsError{message: "empty input"}
} else if len(opts.BlockStateCalls) > maxMulticallBlocks {
// TODO return error code.
return nil, errors.New("invalid params")
return nil, &invalidParamsError{message: "too many blocks"}
}
if blockNrOrHash == nil {
n := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)

View file

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