Files
zeekayandGitHub 97321f67b0 feat: Go rewrite scaffold — ZAP-first, Mount() per HIP-0106 (#1)
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).
2026-05-18 23:36:46 -07:00

72 lines
3.0 KiB
Go

package handlers
import (
"net/http"
"github.com/go-chi/chi/v5"
)
// MountTokens registers /v1/tokens/{chain}/* — ERC-20 balances + metadata.
func MountTokens(r chi.Router, _ Deps) {
r.Route("/tokens", func(r chi.Router) {
r.Get("/{chain}/balances/{address}", func(w http.ResponseWriter, _ *http.Request) {
// TODO(bootnode-port): port from bootnode/api/tokens/__init__.py:balances
stub(w, "tokens/{chain}/balances/{address}")
})
r.Get("/{chain}/metadata/{contract}", func(w http.ResponseWriter, _ *http.Request) {
// TODO(bootnode-port): port from bootnode/api/tokens/__init__.py:metadata
stub(w, "tokens/{chain}/metadata/{contract}")
})
r.Post("/{chain}", func(w http.ResponseWriter, _ *http.Request) {
// TODO(bootnode-port): port from bootnode/api/tokens/__init__.py:batch
stub(w, "tokens/{chain} (batch)")
})
r.Post("/{chain}/{network}", func(w http.ResponseWriter, _ *http.Request) {
// TODO(bootnode-port): port from bootnode/api/tokens/__init__.py:batch_network
stub(w, "tokens/{chain}/{network} (batch)")
})
})
}
// MountNFTs registers /v1/nfts/{chain}/* — collection + ownership + metadata.
func MountNFTs(r chi.Router, _ Deps) {
r.Route("/nfts", func(r chi.Router) {
r.Get("/{chain}/owned/{address}", func(w http.ResponseWriter, _ *http.Request) {
// TODO(bootnode-port): port from bootnode/api/nfts/__init__.py:owned
stub(w, "nfts/{chain}/owned/{address}")
})
r.Get("/{chain}/collection/{contract}", func(w http.ResponseWriter, _ *http.Request) {
// TODO(bootnode-port): port from bootnode/api/nfts/__init__.py:collection
stub(w, "nfts/{chain}/collection/{contract}")
})
r.Get("/{chain}/metadata/{contract}/{token_id}", func(w http.ResponseWriter, _ *http.Request) {
// TODO(bootnode-port): port from bootnode/api/nfts/__init__.py:metadata
stub(w, "nfts/{chain}/metadata/{contract}/{token_id}")
})
r.Post("/{chain}/refresh/{contract}/{token_id}", func(w http.ResponseWriter, _ *http.Request) {
// TODO(bootnode-port): port from bootnode/api/nfts/__init__.py:refresh_metadata —
// enqueues an MQ job (was arq, target is deps.MQ subsystem).
stub(w, "nfts/{chain}/refresh/{contract}/{token_id}")
})
_ = chi.URLParam // keep import live for symmetry with downstream handlers
})
}
// MountTransfers registers /v1/transfers/{chain}/* — historical transfers.
func MountTransfers(r chi.Router, _ Deps) {
r.Route("/transfers", func(r chi.Router) {
r.Get("/{chain}/address/{address}", func(w http.ResponseWriter, _ *http.Request) {
// TODO(bootnode-port): port from bootnode/api/transfers/__init__.py:address
stub(w, "transfers/{chain}/address/{address}")
})
r.Get("/{chain}/tx/{tx_hash}", func(w http.ResponseWriter, _ *http.Request) {
// TODO(bootnode-port): port from bootnode/api/transfers/__init__.py:tx
stub(w, "transfers/{chain}/tx/{tx_hash}")
})
r.Post("/{chain}/send", func(w http.ResponseWriter, _ *http.Request) {
// TODO(bootnode-port): port from bootnode/api/transfers/__init__.py:send
stub(w, "transfers/{chain}/send")
})
})
}