mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
The node moved every chain route from /v1/bc/<alias> to /v1/chain/<alias> and deleted the old prefix, so every chain call answered 404. The address was spelled out at 112 sites across 34 files and constants.ChainAliasPrefix was used at none of them, which is why nothing failed to compile when the segment moved. route.Chain(uri, alias) composes it now, and route.Alias reads one back, replacing three hand-rolled parsers — one of which took the alias by position in the split path and only worked because the new segment happens to leave the component count unchanged. TestChainAddressBuiltOnlyHere walks every .go file in the module and fails on a chain address in a string literal, so the segment cannot drift back; prose is free to name a route. TestGuardCatchesEachShape plants each forbidden shape and requires the guard to find it. The endpoint box and the eleven-chain table were the same list written twice; there is one list, rendered once, measured rather than hand-padded. The generated CLI reference and the faucet manifest compose through the same function. Co-authored-by: Hanzo Dev <[email protected]>
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
// Package route addresses a node's HTTP API.
|
|
package route
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/luxfi/constants"
|
|
)
|
|
|
|
// base is the prefix every luxd route hangs from: the node's own endpoints
|
|
// (/v1/info, /v1/health) and, below [Chain], every chain's.
|
|
const base = "/v1"
|
|
|
|
// Chain is where a chain answers, and the one place this module builds that
|
|
// address.
|
|
//
|
|
// uri is a node's base URL, or empty for the path alone: Chain("", "P") is the
|
|
// P-Chain path, and Chain("http://localhost:9630", "C")+"/rpc" is that node's
|
|
// C-Chain RPC. The segment is [constants.ChainAliasPrefix], named once, so
|
|
// every caller moves when it moves.
|
|
//
|
|
// That is the point of routing them all through here. This module used to
|
|
// spell the address out at 112 sites; when the node renamed the segment, all
|
|
// 112 went on addressing a name the router had already left behind. Nothing
|
|
// failed to compile. They simply answered 404.
|
|
func Chain(uri, alias string) string {
|
|
return uri + base + "/" + constants.ChainAliasPrefix + "/" + alias
|
|
}
|
|
|
|
// Alias reads back what [Chain] writes: the alias in a chain address, and
|
|
// whether the address named a chain at all. Inverse of Chain, and the one
|
|
// place this module recognises the segment.
|
|
func Alias(address string) (string, bool) {
|
|
parts := strings.Split(address, "/")
|
|
for i, part := range parts {
|
|
if part == constants.ChainAliasPrefix && i+1 < len(parts) && parts[i+1] != "" {
|
|
return parts[i+1], true
|
|
}
|
|
}
|
|
return "", false
|
|
}
|