graphql: return error if block from>to

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2023-10-20 22:59:52 +08:00
parent cd29535672
commit 3856c823cb

View file

@ -41,7 +41,8 @@ import (
)
var (
errBlockInvariant = errors.New("block objects must be instantiated with at least one of num or hash")
errBlockInvariant = errors.New("block objects must be instantiated with at least one of num or hash")
errInvalidBlockRange = errors.New("invalid from and to block combination: from > to")
)
type Long int64
@ -1333,7 +1334,7 @@ func (r *Resolver) Blocks(ctx context.Context, args struct {
to = rpc.BlockNumber(r.backend.CurrentBlock().Number.Int64())
}
if to < from {
return []*Block{}, nil
return nil, errInvalidBlockRange
}
var ret []*Block
for i := from; i <= to; i++ {