From 9a01ac4f4566a18471ae750fa5a86aa3feb45a8b Mon Sep 17 00:00:00 2001 From: Leopold Schabel Date: Wed, 15 Jun 2022 14:47:56 +0200 Subject: [PATCH] rpc/ws: fix SlotsUpdatesResult timestamp resolution --- rpc/ws/slotsUpdatesSubscribe.go | 2 +- types.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/rpc/ws/slotsUpdatesSubscribe.go b/rpc/ws/slotsUpdatesSubscribe.go index 11931b4f..0dd8621d 100644 --- a/rpc/ws/slotsUpdatesSubscribe.go +++ b/rpc/ws/slotsUpdatesSubscribe.go @@ -22,7 +22,7 @@ type SlotsUpdatesResult struct { // The newly updated slot. Slot uint64 `json:"slot"` // The Unix timestamp of the update. - Timestamp *solana.UnixTimeSeconds `json:"timestamp"` + Timestamp *solana.UnixTimeMilliseconds `json:"timestamp"` // The update type. Type SlotsUpdatesType `json:"type"` } diff --git a/types.go b/types.go index 308d0c49..a22a8184 100644 --- a/types.go +++ b/types.go @@ -32,6 +32,17 @@ func (res UnixTimeSeconds) String() string { return res.Time().String() } +// UnixTimeMilliseconds represents a UNIX millisecond-resolution timestamp. +type UnixTimeMilliseconds int64 + +func (res UnixTimeMilliseconds) Time() time.Time { + return time.Unix(0, int64(res)*int64(time.Millisecond)) +} + +func (res UnixTimeMilliseconds) String() string { + return res.Time().String() +} + type DurationSeconds int64 func (res DurationSeconds) Duration() time.Duration {