Introducing a new way to review your PRs.

Read the announcement

solana-foundation / solana-go

Go SDK library and RPC client for the Solana Blockchain

View on GitHub

26 documents · Updated Nov 16, 2026

docs / supporting-utilities

Supporting utilities and diagnostics

The SDK provides small support systems that help callers inspect values, produce readable text, and understand runtime behavior. These utilities sit beside transaction and RPC execution: comparison reports explain how data changed, text helpers turn SDK values into human-readable output, and logging hooks connect the SDK to the host application's diagnostics.

Utility roles

The support layer connects SDK state to two common human tasks: reading output and finding change. It does not define a separate business flow; it gives transaction, program, RPC, and application code a shared way to present and inspect results.

The main paths are:

NeedUtility roleResult
Compare two valuesData-difference reportingStructured events for added, changed, or removed data
Show SDK valuesText helpersPlain or terminal-formatted text
Explain runtime behaviorLogging integrationTrace, debug, warning, and error records through the host logger

Data-difference reporting

The diff package compares two values and reports each difference as an event. A difference has a kind, a path into the value, and the old or new value that matters for that kind. This lets callers react to a specific change instead of parsing one large formatted result. (Data-difference reporting)

Difference events

Difference events use three meanings: added means only the new value exists, removed means only the old value exists, and changed means both values exist but differ. Slice changes are exposed as removal and addition events so callers can treat a replacement as two clear list operations.

Event paths identify nested fields and list positions. Callers can match a path pattern when they need to focus on one part of a larger value. The event also exposes an element selected for the event kind, which gives consumers one value to inspect without handling old and new values separately.

References: diff/diff.go• L27-47 diff/diff.go• L54-166 diff/diff.go• L195-210 diff/diff.go• L226-266

Comparison boundaries

The comparison API is callback-based. Callers must provide an event callback, and they can add comparison options when the default comparison rules are not enough. This makes the package useful for assertions, change summaries, and targeted diagnostics without tying it to a particular output format.

References: diff/diff.go• L31-47 diff/diff.go• L195-210 diff/diff_test.go• L25-147

Text output

The text package turns values into output for terminals and diagnostic views. It covers simple string and line helpers, color and emphasis, structured value encoding, and tree-shaped output. The related formatting package uses these helpers to present programs, instructions, parameters, accounts, and account metadata. (Text helpers)

Structured value encoding

The text encoder writes primitive values and nested arrays, slices, maps, and structs to an io.Writer. Types can provide a text encoding rule when their normal Go shape is not the clearest display. Struct tags can also select compact or skipped fields, so the same value can support a readable diagnostic view without changing its wire meaning.

References: text/interface.go• L15-18 text/encoder.go• L33-72 text/encoder.go• L79-163 text/encoder.go• L181-247 text/tag.go• L22-45

Terminal presentation

Terminal helpers add color, background color, bold text, highlighting, and stable colors derived from a string. Color output can be disabled through the package switch, which lets the same presentation work in terminals, logs, and tests without escape codes. (Text helpers)

References: text/tools.go• L26-53 text/tools.go• L55-188 text/tools.go• L200-256 text/tools_test.go• L9-40 text/rgbterm.go• L67-97

Domain formatting

The text/format package adds labels and layout for common SDK concepts. It combines readable names with public keys, account roles, and multi-line parameter values so callers can present instruction context as a human-facing diagnostic record.

References: text/…/format.go• L26-43 text/…/format.go• L46-76

Logging integration

Logging integration gives the SDK a shared path to the application's structured logger. The root SDK, RPC client, WebSocket client, and difference reporter register separate logger names and use trace checks to keep detailed diagnostics available without making them part of normal data results. (Logging integration)

Logger scopes

Each major support or execution area has its own logging scope. This keeps SDK-wide, RPC, WebSocket, and comparison records distinct while allowing the host application to configure them through the common logging package. The RPC and WebSocket layers use these scopes for connection, message, subscription, and delivery diagnostics.

References: logging.go• L18-30 rpc/logging.go• L18-29 rpc/…/logging.go• L18-29 diff/logging.go• L15-29 rpc/…/client.go• L256-284 rpc/…/client.go• L330-374

Diagnostic levels

Trace and debug records explain internal progress. Warnings and errors report conditions that can affect delivery or cleanup. Logging therefore complements returned errors and callbacks: returned values describe the caller's contract, while logs explain the path that led to the result.

References: diff/diff.go• L218-274 rpc/…/client.go• L256-284 rpc/…/client.go• L330-374 rpc/…/client.go• L459-469 rpc/…/client.go• L542-544

Utility relationships

The utilities form a support loop around SDK activity. A caller can compare values to find a change, format the affected values for a person, and use scoped logs to explain how the surrounding operation reached that state.

This diagram shows how a value or runtime event moves through the support layer.

flowchart LR
    A[SDK value or runtime event] --> B{Support need}
    B -->|Compare| C[Difference events]
    B -->|Present| D[Text output]
    B -->|Diagnose| E[Scoped log record]
    C --> D
    C --> E

For a wider view of how comparison and presentation fit together, see Comparison, text, and logging.

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep difference event kinds, path patterns, and old/new value rules aligned with callers that filter or summarize events.
  • Preserve the no-color output path when changing terminal styles, because formatted values can also be used in logs and tests.
  • Keep logger scopes stable when moving diagnostic records, so host logging filters continue to select the same subsystem.
  • When adding a new structured value type, decide whether its text view needs a custom encoding rule instead of exposing its raw shape.

Important failure modes

TriggerConsequenceGuard
Calling the difference entry point without an event callbackThe comparison stops with a panic instead of returning a reportAlways provide an OnEvent callback
Treating a list replacement as one changed eventConsumers miss the package's remove-plus-add meaning for slice changesHandle added and removed events for list paths
Leaving terminal color enabled for a plain-text destinationOutput contains escape sequences that reduce readabilitySet text.DisableColors for non-terminal output
Filtering logs by an old or wrong scope nameUseful records are hidden from the host diagnosticsKeep the registered scope names and logging filters aligned

Key files

FileWhy to read it
diff/diff.goDefines the comparison event model and path behavior.
text/encoder.goShows how values become structured human-readable output.
text/tools.goDefines shared plain-text and terminal presentation helpers.
text/…/format.goShows how common SDK concepts receive readable labels.
logging.goDefines the root SDK logging scope.
rpc/logging.goDefines the RPC logging scope.
rpc/…/logging.goDefines the WebSocket logging scope.
diff/logging.goConnects comparison diagnostics to the shared logger.