refactor(proxy): normalise worker timestamps

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-04 20:35:03 +00:00
parent d47d89af7a
commit 35d8c524e4
2 changed files with 17 additions and 2 deletions

View file

@ -12,6 +12,7 @@ package api
import (
"encoding/json"
"net/http"
"time"
"dappco.re/go/proxy"
)
@ -139,7 +140,7 @@ func workersResponse(p *proxy.Proxy) any {
record.Rejected,
record.Invalid,
record.Hashes,
record.LastHashAt.Unix(),
unixOrZero(record.LastHashAt),
record.Hashrate(60),
record.Hashrate(600),
record.Hashrate(3600),
@ -187,3 +188,10 @@ func upstreamRatio(now, total uint64) float64 {
}
return float64(now) / float64(total)
}
func unixOrZero(value time.Time) int64 {
if value.IsZero() {
return 0
}
return value.Unix()
}

View file

@ -585,7 +585,7 @@ func (p *Proxy) workersDocument() any {
record.Rejected,
record.Invalid,
record.Hashes,
record.LastHashAt.Unix(),
unixOrZero(record.LastHashAt),
record.Hashrate(60),
record.Hashrate(600),
record.Hashrate(3600),
@ -629,6 +629,13 @@ func upstreamRatio(now uint64, upstreams UpstreamStats) float64 {
return float64(now) / float64(upstreams.Total)
}
func unixOrZero(value time.Time) int64 {
if value.IsZero() {
return 0
}
return value.Unix()
}
func NewMiner(conn net.Conn, localPort uint16, tlsCfg *tls.Config) *Miner {
if tlsCfg != nil {
if _, ok := conn.(*tls.Conn); !ok {