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:
parent
816a38acae
commit
fa6c0bf8a1
1 changed files with 14 additions and 1 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue