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

220 lines
8.9 KiB
Go

package handlers
import (
"context"
"errors"
"log/slog"
bootnodezap "github.com/hanzoai/bootnode/zap/gen"
)
// ServiceDeps is the (smaller) dependency bundle the in-process ZAP
// service implementation consumes. Distinct from the HTTP handler
// Deps because the ZAP path doesn't need a Service handle to itself.
type ServiceDeps struct {
Logger *slog.Logger
IAM IAMClient
KMS KMSClient
Base BaseClient
O11y O11yClient
Commerce CommerceClient
}
// service is the canonical bootnodezap.Service implementation. The
// HTTP handlers wrap it where they need typed access; superbase
// hands the same instance to peer subsystems via the in-process ZAP
// dispatcher (HIP-0106).
//
// Every method below is a stub that returns ErrNotImplemented with a
// TODO(bootnode-port) tag pointing at the Python file we need to
// port. We keep them on one struct so the interface contract stays
// honest: when zapc regenerates bindings, the method set must match
// or compile fails.
type service struct {
deps ServiceDeps
}
// NewService builds the in-process Service implementation.
func NewService(d ServiceDeps) bootnodezap.Service { return &service{deps: d} }
// ErrNotImplemented is the canonical "stub" error. Handlers convert
// it to HTTP 501.
var ErrNotImplemented = errors.New("bootnode: not implemented (port in progress)")
// ---- RPC ------------------------------------------------------------------
func (s *service) RPC(_ context.Context, _ bootnodezap.RPCRequest) (bootnodezap.RPCResponse, error) {
// TODO(bootnode-port): port from bootnode/api/rpc/__init__.py — JSON-RPC
// proxy fanned out across upstream nodes via web3.HTTPProvider equivalent
// in api/web3/client.go.
return bootnodezap.RPCResponse{}, ErrNotImplemented
}
// ---- Tokens ---------------------------------------------------------------
func (s *service) TokenBalances(_ context.Context, _ bootnodezap.Chain, _ string) ([]bootnodezap.TokenBalance, error) {
// TODO(bootnode-port): port from bootnode/api/tokens/__init__.py:balances
return nil, ErrNotImplemented
}
func (s *service) TokenMetadata(_ context.Context, _ bootnodezap.Chain, _ string) (bootnodezap.TokenMetadata, error) {
// TODO(bootnode-port): port from bootnode/api/tokens/__init__.py:metadata
return bootnodezap.TokenMetadata{}, ErrNotImplemented
}
// ---- NFTs -----------------------------------------------------------------
func (s *service) NFTMetadata(_ context.Context, _ bootnodezap.Chain, _, _ string) (bootnodezap.NFTMetadata, error) {
// TODO(bootnode-port): port from bootnode/api/nfts/__init__.py:metadata
return bootnodezap.NFTMetadata{}, ErrNotImplemented
}
func (s *service) NFTCollection(_ context.Context, _ bootnodezap.Chain, _ string) (bootnodezap.NFTCollection, error) {
// TODO(bootnode-port): port from bootnode/api/nfts/__init__.py:collection
return bootnodezap.NFTCollection{}, ErrNotImplemented
}
func (s *service) NFTsOwned(_ context.Context, _ bootnodezap.Chain, _ string) ([]bootnodezap.NFTMetadata, error) {
// TODO(bootnode-port): port from bootnode/api/nfts/__init__.py:owned
return nil, ErrNotImplemented
}
// ---- Transfers ------------------------------------------------------------
func (s *service) ListTransfers(_ context.Context, _ bootnodezap.Chain, _ string) ([]bootnodezap.Transfer, error) {
// TODO(bootnode-port): port from bootnode/api/transfers/__init__.py:address
return nil, ErrNotImplemented
}
// ---- Smart wallets --------------------------------------------------------
func (s *service) CreateSmartWallet(_ context.Context, _ bootnodezap.Chain, _ string) (bootnodezap.SmartWallet, error) {
// TODO(bootnode-port): port from bootnode/api/wallets/__init__.py:create
return bootnodezap.SmartWallet{}, ErrNotImplemented
}
func (s *service) GetSmartWallet(_ context.Context, _ string) (bootnodezap.SmartWallet, error) {
// TODO(bootnode-port): port from bootnode/api/wallets/__init__.py:get
return bootnodezap.SmartWallet{}, ErrNotImplemented
}
// ---- Bundler --------------------------------------------------------------
func (s *service) SendUserOp(_ context.Context, _ bootnodezap.Chain, _ bootnodezap.UserOp) (string, error) {
// TODO(bootnode-port): port from bootnode/api/bundler/__init__.py:sendUserOperation
return "", ErrNotImplemented
}
func (s *service) GetUserOpReceipt(_ context.Context, _ bootnodezap.Chain, _ string) (bootnodezap.UserOpReceipt, error) {
// TODO(bootnode-port): port from bootnode/api/bundler/__init__.py:getUserOperationReceipt
return bootnodezap.UserOpReceipt{}, ErrNotImplemented
}
// ---- Gas ------------------------------------------------------------------
func (s *service) GasPrices(_ context.Context, _ bootnodezap.Chain) (bootnodezap.GasPrices, error) {
// TODO(bootnode-port): port from bootnode/api/gas/__init__.py:prices
return bootnodezap.GasPrices{}, ErrNotImplemented
}
func (s *service) SponsorUserOp(_ context.Context, _ bootnodezap.Chain, _ bootnodezap.UserOp, _ string) (string, error) {
// TODO(bootnode-port): port from bootnode/api/gas/__init__.py:sponsor
return "", ErrNotImplemented
}
// ---- Webhooks -------------------------------------------------------------
func (s *service) CreateWebhook(_ context.Context, _ bootnodezap.Webhook) (bootnodezap.Webhook, error) {
// TODO(bootnode-port): port from bootnode/api/webhooks/__init__.py:create
return bootnodezap.Webhook{}, ErrNotImplemented
}
func (s *service) ListWebhooks(_ context.Context, _ string) ([]bootnodezap.Webhook, error) {
// TODO(bootnode-port): port from bootnode/api/webhooks/__init__.py:list
return nil, ErrNotImplemented
}
func (s *service) DeleteWebhook(_ context.Context, _ string) (bool, error) {
// TODO(bootnode-port): port from bootnode/api/webhooks/__init__.py:delete
return false, ErrNotImplemented
}
// ---- API keys / projects --------------------------------------------------
func (s *service) CreateAPIKey(_ context.Context, _, _, _ string, _ []string) (bootnodezap.CreateAPIKeyResult, error) {
// TODO(bootnode-port): port from bootnode/api/auth_keys.py:create_api_key — MUST bcrypt the plaintext before persistence.
return bootnodezap.CreateAPIKeyResult{}, ErrNotImplemented
}
func (s *service) ListAPIKeys(_ context.Context, _ string) ([]bootnodezap.APIKey, error) {
// TODO(bootnode-port): port from bootnode/api/auth_keys.py:list_api_keys
return nil, ErrNotImplemented
}
func (s *service) RevokeAPIKey(_ context.Context, _, _ string) (bool, error) {
// TODO(bootnode-port): port from bootnode/api/auth_keys.py:delete_api_key
return false, ErrNotImplemented
}
// ---- Fleets ---------------------------------------------------------------
func (s *service) CreateFleet(_ context.Context, _ bootnodezap.Fleet) (bootnodezap.Fleet, error) {
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:create
return bootnodezap.Fleet{}, ErrNotImplemented
}
func (s *service) ListFleets(_ context.Context, _ string) ([]bootnodezap.Fleet, error) {
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:list
return nil, ErrNotImplemented
}
func (s *service) ScaleFleet(_ context.Context, _ string, _ int32) (bootnodezap.Fleet, error) {
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:scale
return bootnodezap.Fleet{}, ErrNotImplemented
}
func (s *service) DeleteFleet(_ context.Context, _ string) (bool, error) {
// TODO(bootnode-port): port from bootnode/api/fleets/__init__.py:delete
return false, ErrNotImplemented
}
// ---- Nodes ----------------------------------------------------------------
func (s *service) DeployNode(_ context.Context, _ bootnodezap.Node) (bootnodezap.Node, error) {
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:create
return bootnodezap.Node{}, ErrNotImplemented
}
func (s *service) ListNodes(_ context.Context, _ string) ([]bootnodezap.Node, error) {
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:list
return nil, ErrNotImplemented
}
func (s *service) StartNode(_ context.Context, _ string) (bool, error) {
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:start
return false, ErrNotImplemented
}
func (s *service) StopNode(_ context.Context, _ string) (bool, error) {
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:stop
return false, ErrNotImplemented
}
func (s *service) DeleteNode(_ context.Context, _ string) (bool, error) {
// TODO(bootnode-port): port from bootnode/api/nodes/__init__.py:delete
return false, ErrNotImplemented
}
// ---- Usage ---------------------------------------------------------------
func (s *service) RecordUsage(_ context.Context, _ bootnodezap.UsageRecord) (bool, error) {
// TODO(bootnode-port): port from bootnode/core/billing/sync.py:report_usage —
// must call deps.Commerce.RecordUsage, never write payment data here.
return false, ErrNotImplemented
}
func (s *service) GetUsage(_ context.Context, _ string, _, _ int64) (bootnodezap.UsageSummary, error) {
// TODO(bootnode-port): port from bootnode/api/billing/__init__.py:usage_summary
return bootnodezap.UsageSummary{}, ErrNotImplemented
}