mirror of
https://github.com/hanzoai/bootnode.git
synced 2026-09-30 20:46:32 +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).
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
)
|
|
|
|
// writeJSON renders v as a JSON response with status code.
|
|
func writeJSON(w http.ResponseWriter, status int, v any) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(status)
|
|
_ = json.NewEncoder(w).Encode(v)
|
|
}
|
|
|
|
// readJSON decodes the request body into v. Returns 400 on failure.
|
|
func readJSON(w http.ResponseWriter, r *http.Request, v any) bool {
|
|
if err := json.NewDecoder(r.Body).Decode(v); err != nil {
|
|
writeJSON(w, http.StatusBadRequest, errBody{"invalid json: " + err.Error()})
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
type errBody struct {
|
|
Error string `json:"error"`
|
|
}
|
|
|
|
// stub returns a 501 with the canonical port-in-progress message. It
|
|
// is the one place HTTP handlers translate ErrNotImplemented from the
|
|
// service into a wire-level response.
|
|
func stub(w http.ResponseWriter, note string) {
|
|
writeJSON(w, http.StatusNotImplemented, errBody{"not implemented: " + note})
|
|
}
|
|
|
|
// serviceErr converts a typed service error into an HTTP response.
|
|
// Today the only typed error is ErrNotImplemented; the function is
|
|
// here as the seam where future error categories land.
|
|
func serviceErr(w http.ResponseWriter, err error, note string) {
|
|
if errors.Is(err, ErrNotImplemented) {
|
|
stub(w, note)
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusInternalServerError, errBody{err.Error()})
|
|
}
|