Files
dex/sdk/go/client/grpc_backend.go
zeekay 0d72ccf5a3 lx/dex: gate gRPC transport behind the grpc build tag
Default build pulls zero gRPC code; rebuild with `-tags=grpc` to opt
into gRPC.

Decomplected via a `grpcBackend` interface in `sdk/go/client` and a
`grpcSubClient` interface in `client/go`. The default build wires a
no-op backend (`*_nogrpc.go`); the `grpc` build wires the real
protobuf-backed client (`*_grpc.go`). Public methods stay the same in
both builds — the gRPC fast path is preferred when wired, else
JSON-RPC / WebSocket.

Files gated:
- pkg/grpc/pb/lxdex_grpc.pb.go            (//go:build grpc)
- pkg/proto/engine/proto/lx_engine_grpc.pb.go (//go:build grpc)

Files refactored:
- sdk/go/client.go: //go:build grpc with stub in client_nogrpc.go
- sdk/go/client/client.go: gRPC removed from method bodies; backed by
  the grpcBackend interface (grpc_backend{,_grpc,_nogrpc}.go)
- client/go/main.go: GrpcClient + ConnectGrpc moved to grpc.go
  (//go:build grpc); nogrpc.go stubs ConnectGrpc with a clear error

Verification:
- go build ./... (default) clean across sdk/go, client/go, top-level
- go build -tags=grpc ./... clean across all three modules
- go test ./... and go test -tags=grpc ./... green
- go list -deps shows 0 google.golang.org/grpc packages in default
  builds of sdk/go/client and client/go; 62 packages with -tags=grpc

READMEs in sdk/go and client/go document the build-tag opt-in.
2026-05-16 17:54:11 -07:00

31 lines
1.2 KiB
Go

// Package client — gRPC backend interface.
//
// Always compiled. The default build provides a no-op implementation in
// grpc_backend_nogrpc.go; building with `-tags=grpc` substitutes the
// real implementation in grpc_backend_grpc.go.
package client
import (
"context"
"errors"
)
// ErrGRPCNotBuilt is returned when a gRPC-only method is invoked in
// the default build. Rebuild with `go build -tags=grpc` to enable
// gRPC support.
var ErrGRPCNotBuilt = errors.New("client: gRPC support requires the `grpc` build tag (rebuild with -tags=grpc)")
// grpcBackend abstracts the gRPC transport. The ok return is true when
// the backend handled the call; the JSON-RPC fallback in the public
// method is used when ok is false.
type grpcBackend interface {
connect(ctx context.Context, addr string) error
close() error
placeOrder(ctx context.Context, order *Order) (resp *OrderResponse, ok bool, err error)
cancelOrder(ctx context.Context, orderID uint64) (ok bool, err error)
getOrderBook(ctx context.Context, symbol string, depth int32) (ob *OrderBook, ok bool, err error)
getTrades(ctx context.Context, symbol string, limit int32) (trades []*Trade, ok bool, err error)
streamOrderBook(ctx context.Context, symbol string) (<-chan *OrderBook, error)
}