mirror of
https://github.com/luxfi/platformvm.git
synced 2026-10-30 15:22:12 +00:00
- Drop atomic_block.go + legacy *_block_test.go (consolidated) - Add block/v0/ subdir + lift_v0.go for old version handling - Copyright header: 'Lux Industries, Inc.' → 'Lux Industries Inc' (no comma) - block_adapter.go: new adapter layer
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package api
|
|
|
|
import (
|
|
"errors"
|
|
"math"
|
|
|
|
"github.com/luxfi/node/utils/json"
|
|
)
|
|
|
|
type Height json.Uint64
|
|
|
|
const (
|
|
ProposedHeightJSON = `"proposed"`
|
|
ProposedHeight = math.MaxUint64
|
|
)
|
|
|
|
var errInvalidHeight = errors.New("invalid height")
|
|
|
|
func (h Height) MarshalJSON() ([]byte, error) {
|
|
if h == ProposedHeight {
|
|
return []byte(ProposedHeightJSON), nil
|
|
}
|
|
return json.Uint64(h).MarshalJSON()
|
|
}
|
|
|
|
func (h *Height) UnmarshalJSON(b []byte) error {
|
|
// First check for known string values
|
|
switch string(b) {
|
|
case json.Null:
|
|
return nil
|
|
case ProposedHeightJSON:
|
|
*h = ProposedHeight
|
|
return nil
|
|
}
|
|
|
|
// Otherwise, unmarshal as a uint64
|
|
if err := (*json.Uint64)(h).UnmarshalJSON(b); err != nil {
|
|
return errInvalidHeight
|
|
}
|
|
|
|
// MaxUint64 is reserved for proposed height, so return an error if supplied
|
|
// numerically.
|
|
if uint64(*h) == ProposedHeight {
|
|
*h = 0
|
|
return errInvalidHeight
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (h Height) IsProposed() bool {
|
|
return h == ProposedHeight
|
|
}
|