Files
zeekayandHanzo Dev 938b06d485 Stop requiring the node this module is imported by
proto required luxfi/node and luxfi/node required proto, with no replace
directive on either side. The cycle was not load-bearing: most of it was proto
reaching into the node for packages proto already owns — p/warp, p/txs,
p/signer, p/stakeable, p/security, x/txs — which now name themselves.

Two were real. The UTXO components moved here, where the chains that use them
already live, and the node is the only other caller, so that dependency now
runs one way. And p/config held the node's chain manager to queue a chain the
P-Chain had accepted a CreateChainTx for; it calls one method, so it declares
one method. A P-Chain that imports the node to describe QueueChainCreation is
what made two modules require each other.

Dropping the requirement dropped a registration with it: lux.ParseUTXO is a
registry filled by an init, which the node used to link in on proto's behalf.
The packages that call it now say so themselves.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-06 12:49:55 -07:00

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/util/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
}