diff --git a/src/api/eosio-contract.go b/src/api/eosio-contract.go index ee3981e..0d99450 100644 --- a/src/api/eosio-contract.go +++ b/src/api/eosio-contract.go @@ -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 {