mirror of
https://github.com/hanzoai/bootnode.git
synced 2026-10-25 02:31:30 +00:00
Adds a Go subsystem alongside the existing Python FastAPI service so
bootnode can fold into `superbase` per HIP-0106. The Python service in
`api/bootnode/` stays untouched.
What landed:
- `schema/bootnode.zap` — public typed surface (chains, RPC, tokens,
NFTs, transfers, smart wallets, ERC-4337, gas, webhooks, fleets,
nodes, usage). No `.capnp` anywhere — ZAP only, per brand policy.
- `zap/gen/` — hand-rolled Go bindings that match what `zapc generate`
emits, so `go build` works without zapc installed locally.
- `api/mount.go` — the HIP-0106 contract:
func Mount(r chi.Router, deps Deps) error
mounts every FastAPI-parity route group through `api/handlers/`.
- `api/deps.go` — cross-subsystem ZAP client interfaces (IAM, KMS,
Base, O11y, Commerce). No business logic, no hard imports — keeps
the Bootnode module independent of sibling subsystems until they
ship their typed clients.
- `api/handlers/` — 149 chi routes mounted (Python has 150). Each
handler body is a 501 stub with a `TODO(bootnode-port)` pointing at
the Python file + symbol to port.
- `api/middleware/` — IAM-backed auth, OTEL-friendly telemetry,
per-org rate limit (stub).
- `api/store/` — per-tenant SQLite access via `deps.Base.Open(orgID,
"bootnode")` per HIP-0302.
- `api/web3/` — chain registry + RPC pool surface (production version
prefers luxfi/* over upstream go-ethereum).
- `cmd/bootnode/main.go` — standalone shim; same `api.Mount` superbase
calls in production.
- `docs/PYTHON_TO_GO_PORT.md` — endpoint-by-endpoint port map.
Build: `go build ./...` and `go vet ./...` clean. Standalone shim
smokes 200 on /health, /ready, /v1/chains; 401 on auth-required
endpoints with no JWT; 501 on every TODO route.
Out of scope (not in this commit):
- Handler bodies (Phase 2 — porting in RPC → tokens → NFTs → ...
priority order).
- superbase wiring (lands when the superbase repo opens its main).
- Python service removal (stays until handlers reach prod parity).
179 lines
8.6 KiB
Go
179 lines
8.6 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
// MountFleets registers /v1/fleets/* — multi-replica node deployments.
|
|
func MountFleets(r chi.Router, _ Deps) {
|
|
r.Route("/fleets", func(r chi.Router) {
|
|
r.Post("/", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:create
|
|
stub(w, "fleets POST")
|
|
})
|
|
r.Get("/", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:list
|
|
stub(w, "fleets GET")
|
|
})
|
|
r.Get("/stats", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:stats
|
|
stub(w, "fleets/stats")
|
|
})
|
|
r.Get("/chains", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:chains
|
|
stub(w, "fleets/chains")
|
|
})
|
|
r.Get("/networks", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:networks
|
|
stub(w, "fleets/networks")
|
|
})
|
|
r.Get("/clusters", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:list_clusters
|
|
stub(w, "fleets/clusters GET")
|
|
})
|
|
r.Post("/clusters", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:create_cluster
|
|
stub(w, "fleets/clusters POST")
|
|
})
|
|
r.Delete("/clusters/{cluster_id}", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:delete_cluster
|
|
stub(w, "fleets/clusters/{id} DELETE")
|
|
})
|
|
r.Get("/{chain}/{cluster_id}/{network}", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:get_fleet
|
|
stub(w, "fleets/{chain}/{cluster}/{network}")
|
|
})
|
|
r.Patch("/{chain}/{cluster_id}/{network}", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:update_fleet
|
|
stub(w, "fleets/{chain}/{cluster}/{network} PATCH")
|
|
})
|
|
r.Delete("/{chain}/{cluster_id}/{network}", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:delete_fleet
|
|
stub(w, "fleets/{chain}/{cluster}/{network} DELETE")
|
|
})
|
|
r.Post("/{chain}/{cluster_id}/{network}/scale", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:scale_fleet
|
|
stub(w, "fleets scale")
|
|
})
|
|
r.Post("/{chain}/{cluster_id}/{network}/restart", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:restart_fleet
|
|
stub(w, "fleets restart")
|
|
})
|
|
r.Get("/{chain}/{cluster_id}/{network}/pods/{pod_name}/logs", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:pod_logs
|
|
stub(w, "fleets pod logs")
|
|
})
|
|
r.Get("/{chain}/{cluster_id}/{network}/pods/{pod_name}/health", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:pod_health
|
|
stub(w, "fleets pod health")
|
|
})
|
|
_ = chi.URLParam
|
|
})
|
|
}
|
|
|
|
// MountNodes registers /v1/nodes/* — single-instance node lifecycle.
|
|
func MountNodes(r chi.Router, _ Deps) {
|
|
r.Route("/nodes", func(r chi.Router) {
|
|
r.Get("/", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:list
|
|
stub(w, "nodes GET")
|
|
})
|
|
r.Get("/presets", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:presets
|
|
stub(w, "nodes/presets")
|
|
})
|
|
r.Get("/supported-chains", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:supported_chains
|
|
stub(w, "nodes/supported-chains")
|
|
})
|
|
r.Post("/", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:create —
|
|
// docker-managed nodes via deps.Compute (was direct docker SDK).
|
|
stub(w, "nodes POST")
|
|
})
|
|
r.Get("/stats", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:stats
|
|
stub(w, "nodes/stats")
|
|
})
|
|
r.Get("/metrics/all", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:metrics_all
|
|
stub(w, "nodes/metrics/all")
|
|
})
|
|
r.Get("/docker/status", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:docker_status
|
|
stub(w, "nodes/docker/status")
|
|
})
|
|
r.Get("/{node_id}", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:get
|
|
stub(w, "nodes/{id}")
|
|
})
|
|
r.Delete("/{node_id}", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:delete
|
|
stub(w, "nodes/{id} DELETE")
|
|
})
|
|
r.Post("/{node_id}/start", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:start
|
|
stub(w, "nodes/{id}/start")
|
|
})
|
|
r.Post("/{node_id}/stop", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:stop
|
|
stub(w, "nodes/{id}/stop")
|
|
})
|
|
r.Post("/{node_id}/rpc", func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:rpc_proxy
|
|
stub(w, "nodes/{id}/rpc")
|
|
})
|
|
})
|
|
}
|
|
|
|
// MountInfra registers /v1/infra/* — K8s clusters / volumes / snapshots / clones.
|
|
func MountInfra(r chi.Router, _ Deps) {
|
|
r.Route("/infra", func(r chi.Router) {
|
|
// Clusters
|
|
r.Get("/clusters", stubHandler("infra/clusters GET", "list_clusters"))
|
|
r.Get("/clusters/{cluster_id}", stubHandler("infra/clusters/{id}", "get_cluster"))
|
|
r.Post("/clusters", stubHandler("infra/clusters POST", "create_cluster"))
|
|
r.Delete("/clusters/{cluster_id}", stubHandler("infra/clusters/{id} DELETE", "delete_cluster"))
|
|
r.Post("/clusters/{cluster_id}/scale", stubHandler("infra/clusters/{id}/scale", "scale_cluster"))
|
|
r.Get("/clusters/{cluster_id}/kubeconfig", stubHandler("infra/clusters/{id}/kubeconfig", "kubeconfig"))
|
|
// Volumes
|
|
r.Get("/volumes", stubHandler("infra/volumes GET", "list_volumes"))
|
|
r.Get("/volumes/{volume_id}", stubHandler("infra/volumes/{id}", "get_volume"))
|
|
r.Post("/volumes", stubHandler("infra/volumes POST", "create_volume"))
|
|
r.Delete("/volumes/{volume_id}", stubHandler("infra/volumes/{id} DELETE", "delete_volume"))
|
|
r.Post("/volumes/{volume_id}/attach", stubHandler("infra/volumes/{id}/attach", "attach_volume"))
|
|
r.Post("/volumes/{volume_id}/detach", stubHandler("infra/volumes/{id}/detach", "detach_volume"))
|
|
r.Post("/volumes/{volume_id}/resize", stubHandler("infra/volumes/{id}/resize", "resize_volume"))
|
|
// Snapshots
|
|
r.Get("/snapshots", stubHandler("infra/snapshots GET", "list_snapshots"))
|
|
r.Post("/snapshots", stubHandler("infra/snapshots POST", "create_snapshot"))
|
|
r.Delete("/snapshots/{snapshot_id}", stubHandler("infra/snapshots/{id} DELETE", "delete_snapshot"))
|
|
// Clone
|
|
r.Post("/clone", stubHandler("infra/clone POST", "create_clone"))
|
|
r.Get("/clone", stubHandler("infra/clone GET", "list_clones"))
|
|
r.Get("/clone/{clone_id}", stubHandler("infra/clone/{id}", "get_clone"))
|
|
r.Delete("/clone/{clone_id}", stubHandler("infra/clone/{id} DELETE", "cancel_clone"))
|
|
// Services
|
|
r.Get("/services", stubHandler("infra/services GET", "list_services"))
|
|
r.Get("/services/{service}/status", stubHandler("infra/services/{s}/status", "service_status"))
|
|
r.Post("/services/{service}/deploy", stubHandler("infra/services/{s}/deploy", "service_deploy"))
|
|
r.Post("/services/{service}/scale", stubHandler("infra/services/{s}/scale", "service_scale"))
|
|
r.Post("/services/{service}/restart", stubHandler("infra/services/{s}/restart", "service_restart"))
|
|
r.Delete("/services/{service}", stubHandler("infra/services/{s} DELETE", "service_delete"))
|
|
r.Get("/services/{service}/logs", stubHandler("infra/services/{s}/logs", "service_logs"))
|
|
r.Get("/services/{service}/health", stubHandler("infra/services/{s}/health", "service_health"))
|
|
// Stats
|
|
r.Get("/stats", stubHandler("infra/stats", "infra_stats"))
|
|
})
|
|
}
|
|
|
|
// stubHandler is shorthand for the giant infra routing table.
|
|
func stubHandler(route, pyFunc string) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/infra/__init__.py:<pyFunc>
|
|
stub(w, route+" — port: bootnode/api/infra/__init__.py:"+pyFunc)
|
|
}
|
|
}
|