1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-06-18 05:00:03 +02:00

src/api/eosio-contract.go: Add SetTime() and GetTime()

This commit is contained in:
Henrik Hautakoski 2022-08-17 17:27:42 +02:00
parent 816a38acae
commit fa6c0bf8a1
No known key found for this signature in database
GPG key ID: 608414D93E862CCD

View file

@ -11,6 +11,7 @@ import (
type EosioContract struct {
client contract_api.Client
block_time float64
ts time.Time
}
func NewEosioContract(url string, block_time float64) EosioContract {
@ -30,6 +31,18 @@ func (e EosioContract) LogInfo() LogParams {
}
}
func (e *EosioContract) SetTime(t time.Time) {
e.ts = t
}
func (e EosioContract) GetTime() time.Time {
if e.ts.IsZero() {
return time.Now().In(time.UTC)
}
return e.ts
}
func (e EosioContract) Call() (agentcheck.Response, string) {
h, err := e.client.GetHealth()
@ -65,7 +78,7 @@ func (e EosioContract) Call() (agentcheck.Response, string) {
}
// Validate head block.
now := time.Now().In(time.UTC)
now := e.GetTime()
diff := now.Sub(h.Data.Chain.HeadTime).Seconds()
if diff > e.block_time {