|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This file provides guidance to AI coding agents (Claude Code, Codex, Cursor, Copilot, and others) |
| 4 | +working in this repository. It is loaded into agent context automatically — keep it concise. |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +`github.com/onflow/flow-go-sdk` is the reference Go SDK for the Flow blockchain. It provides |
| 9 | +client packages for the Flow Access API over gRPC and HTTP, Cadence-aware transaction and |
| 10 | +script helpers, ECDSA/BLS crypto primitives, and account-creation templates. The module is |
| 11 | +compatible with the Flow Emulator for local development. |
| 12 | + |
| 13 | +## Build and Test Commands |
| 14 | + |
| 15 | +Targets from the root `Makefile`: |
| 16 | + |
| 17 | +- `make test` — full test suite with coverage (writes `coverage.txt`). Sets `CGO_CFLAGS` via `crypto_adx_flag.mk`. |
| 18 | +- `make coverage` — runs `test`, then `go tool cover -html=coverage.txt`. |
| 19 | +- `make generate` — installs `mockery v2.53.5` and runs `go generate ./...` to regenerate mocks. |
| 20 | +- `make check-tidy` — runs `generate`, then `go mod tidy`, then fails if the working tree is dirty. |
| 21 | +- `make check-headers` — runs `./check-headers.sh`; fails if any `.go` file is missing the Apache-2.0 header. |
| 22 | +- `make ci` — full CI pipeline: `check-tidy` + `test` + `coverage`. Matches `.github/workflows/ci.yml`. |
| 23 | +- `make generate-openapi` — regenerates `access/http/models/` from the upstream Flow OpenAPI spec (requires `swagger-codegen`). |
| 24 | + |
| 25 | +Examples live in a separate Go module under `examples/` with its own `Makefile`. Run via |
| 26 | +`make -C examples <target>` (e.g. `make -C examples send-transactions`). Examples require |
| 27 | +a running Flow Emulator — see `examples/README.md`. |
| 28 | + |
| 29 | +## Architecture |
| 30 | + |
| 31 | +- Root package `flow` — core domain types: `Account`, `Transaction`, `Block`, `Event`, `Collection`, `Address`. |
| 32 | +- `access/` — `Client` interface (the primary SDK surface). Two implementations: |
| 33 | + - `access/grpc/` — gRPC client (`grpc.NewClient`, `grpc.MainnetHost`, `grpc.TestnetHost`, `grpc.EmulatorHost`). Recommended transport per README. |
| 34 | + - `access/http/` — REST client. `access/http/models/` is generated from OpenAPI. |
| 35 | +- `crypto/` — key generation, signing, hashing. `crypto/awskms/` and `crypto/cloudkms/` provide AWS KMS and Google Cloud KMS signers. |
| 36 | +- `templates/` — prebuilt Cadence transactions for account creation and key management. |
| 37 | +- `test/` — test fixtures (`entities.go`, `greetings.go`, `signer.go`). |
| 38 | +- `client/` — **deprecated**; re-exports `access/grpc`. New code should import `access/grpc` directly (see `client/client.go` doc comment). |
| 39 | +- `examples/` — runnable end-to-end examples against the Flow Emulator. Separate Go module with a `replace` directive back to the SDK root (`examples/go.mod`). |
| 40 | + |
| 41 | +## Conventions and Gotchas |
| 42 | + |
| 43 | +- **Go 1.25.0** required (`go.mod`). CI pins `go-version: '1.25'` in `.github/workflows/ci.yml`. |
| 44 | +- **CGO is required by default** for BLS support (via `github.com/onflow/crypto`). Build with `CGO_ENABLED=1`. You can build with `CGO_ENABLED=0` but must also pass the `no-cgo` build tag; any BLS call will then panic at runtime (README: Installing). |
| 45 | +- **ADX instructions**: `crypto_adx_flag.mk` detects CPU support and sets `CRYPTO_FLAG` for BLST. Always invoke via the `Makefile` (not raw `go test`) to pick up the flag on older machines. |
| 46 | +- **Regenerate mocks after interface changes**: run `make generate` whenever you touch `access.Client`, `access/grpc.RPCClient`, `access/grpc.ExecutionDataRPCClient`, or `access/http.handler` — `go:generate` directives in those files drive `mockery`. `make check-tidy` fails CI if generated output is not committed. |
| 47 | +- **Apache-2.0 license header required** on every `.go` file — enforced by `check-headers.sh` in CI. |
| 48 | +- **Do not edit `client/`** — deprecated shim retained for backward compatibility. |
| 49 | +- `CONTRIBUTING.md` mentions `make lint` — **no such target exists** in the Makefile. Use `gofmt` and `go vet` directly. |
| 50 | +- When writing portable code, depend on the `access.Client` interface so callers can swap gRPC/HTTP; reach for `grpc.BaseClient` / `http.BaseClient` only when transport-specific options are needed (`access/README.md`). |
| 51 | + |
| 52 | +## Files Not to Modify |
| 53 | + |
| 54 | +- `access/http/models/*.go` — generated by `swagger-codegen` via `make generate-openapi`. |
| 55 | +- `access/grpc/mocks/*.go`, `access/mocks/Client.go`, `access/http/mock_handler.go` — generated by `mockery` via `make generate`. |
| 56 | +- `client/client.go` — deprecated shim. |
| 57 | +- `go.sum` — managed by `go mod`. |
0 commit comments