mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
The module already called itself github.com/luxfi/node while containing no node in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and the Go column of the matrix measured a VM plugin. A repo that fetches the thing it claims to be has not replaced it, so the Go sources move in — 1515 files, the daemon and everything under it — and the build reaches outside this module for nothing. Rust and C++ sit beside it unchanged and are still measured against it by the differential. That is the point of one repo: the reference implementation and the two ports are the same checkout, so parity is a thing you can run rather than a thing you assert. Verified: builds, and the closure carries no lux-private — checked at build time rather than believed. The daemon starts twelve chains on a local network (P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package json
|
|
|
|
import (
|
|
stdjson "encoding/json"
|
|
"time"
|
|
)
|
|
|
|
// Time is an instant, on a wire whose fields are offsets.
|
|
//
|
|
// time.Time cannot be one. Its fields are all unexported, so a reply that holds
|
|
// one lays out with nothing in it — eight bytes pointing at an empty message —
|
|
// and a caller reads a zero it cannot tell from a zero that was sent. That is
|
|
// worse than a refusal: nothing fails and the value is simply absent.
|
|
//
|
|
// The same instant as three numbers does have a layout. The JSON is byte for
|
|
// byte what time.Time's own marshaler writes, because the offset is all the
|
|
// rendering depends on: RFC 3339 spells a zero offset "Z" and any other one
|
|
// "+HH:MM", so carrying it is enough to put the instant back in the zone it was
|
|
// read in.
|
|
type Time struct {
|
|
// Seconds is seconds since the epoch.
|
|
Seconds int64 `json:"seconds"`
|
|
// Nanos is the nanosecond within that second.
|
|
Nanos int32 `json:"nanos"`
|
|
// Offset is seconds east of UTC.
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
// NewTime is the instant t, as a value that can cross.
|
|
func NewTime(t time.Time) Time {
|
|
_, offset := t.Zone()
|
|
return Time{Seconds: t.Unix(), Nanos: int32(t.Nanosecond()), Offset: int32(offset)}
|
|
}
|
|
|
|
// Time is the instant, in the zone it was read in.
|
|
func (t Time) Time() time.Time {
|
|
return time.Unix(t.Seconds, int64(t.Nanos)).In(time.FixedZone("", int(t.Offset)))
|
|
}
|
|
|
|
func (t Time) MarshalJSON() ([]byte, error) {
|
|
return stdjson.Marshal(t.Time())
|
|
}
|
|
|
|
func (t *Time) UnmarshalJSON(b []byte) error {
|
|
if string(b) == Null {
|
|
return nil
|
|
}
|
|
var parsed time.Time
|
|
if err := stdjson.Unmarshal(b, &parsed); err != nil {
|
|
return err
|
|
}
|
|
*t = NewTime(parsed)
|
|
return nil
|
|
}
|