mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-26 09:49:28 +00:00
29 lines
449 B
Go
29 lines
449 B
Go
package health
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
var (
|
|
errTimestampTooOld = errors.New("timestamp too old")
|
|
)
|
|
|
|
func checkTime(
|
|
ec ethClient,
|
|
r *http.Request,
|
|
seconds int,
|
|
) error {
|
|
i, err := ec.BlockByNumber(context.TODO(), nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
timestamp := i.Time()
|
|
if timestamp < uint64(seconds) {
|
|
return fmt.Errorf("%w: got ts: %d, need: %d", errTimestampTooOld, timestamp, seconds)
|
|
}
|
|
|
|
return nil
|
|
}
|