Comparison, text, and logging utilities
These utilities support diagnosis and human inspection around the SDK's core Solana data flows. The diff package explains how two values differ, the text packages turn values and domain objects into readable output, and the logging integration exposes internal events through the SDK's structured logging system. They help engineers inspect state and failures without changing the functional APIs that build, encode, or send Solana data.
Utility role
The utilities form a support layer around functional SDK operations. Comparison produces structured change events, text produces display output, and logging records internal activity for an operator or developer.
The parent page, Supporting utilities, places these tools beside the other helpers that aid inspection and integration.
Comparison diagnostics
The diff package compares two Go values and reports only the changes. It is suited to state inspection, update diagnosis, and checks where a complete serialized value would hide the important difference.
Structured value differences
github.com/gagliardetto/solana-go/diff reports each difference as an event with a path, a kind, and the old or new value. A kind is one of added, changed, or removed, so a caller can handle a change without parsing display text. The path describes where the value sits inside a struct or slice.
The package sends events to a callback. It does not return a replacement value, apply a patch, or decide whether a difference is valid for a Solana instruction or transaction. Callers remain responsible for the business meaning of each event.
References: diff/diff.go• L27-52 diff/diff.go• L54-110 diff/diff.go• L195-210
Difference filtering
An event can match a field path or a path pattern for a slice position. This lets a diagnostic focus on one part of a nested value while keeping the full comparison independent of the caller's rules.
Slice changes use added and removed events rather than a semantic move operation. A caller that needs to treat a reorder as a move must apply that meaning outside the comparison utility.
The following flow shows the boundary between comparison and caller action:
flowchart LR
A[Left value] --> C[Value comparison]
B[Right value] --> C
C --> E[Change events]
E --> F[Path or kind filter]
F --> G[Diagnostic or caller decision]
References: diff/diff.go• L75-104 diff/diff.go• L113-148 diff/diff.go• L226-266
Text presentation
The text package provides readable output for values that are hard to inspect in binary or default Go form. It supports nested values, domain-specific display types, indentation, and optional terminal color so command-line diagnostics can show structure without changing the underlying value.
Human-readable values
github.com/gagliardetto/solana-go/text accepts ordinary scalar, pointer, array, slice, map, and struct values. It can also use a type's TextEncode method through the TextEncodable contract when a type needs a specific display form.
The package includes display types for values such as hexadecimal bytes, booleans, fixed-width integers, and 128-bit numbers. These types affect presentation only. They do not replace the SDK's binary encoders, transaction builders, instruction builders, or RPC methods.
Struct text tags can request a linear layout, omit a type name, or skip a field. This gives a domain type control over diagnostic output while keeping the normal data model unchanged.
References: text/interface.go• L15-18 text/encoder.go• L33-72 text/encoder.go• L79-163 text/types.go• L25-40 text/types.go• L87-140 text/tag.go• L22-45
Terminal and tree output
Text helpers support two common inspection forms. The reflective encoder writes nested values to an io.Writer, while tree output lets a type describe a hierarchical view through the treeout model. Small string helpers add spacing, line breaks, highlighting, and color for command-line messages.
Color is optional presentation state. Set text.DisableColors when output must remain plain, such as logs, redirected command output, or comparisons of generated text. Color helpers return the input unchanged when this switch is enabled.
References: text/encoder.go• L38-52 text/encoder.go• L167-247 text/tree.go• L23-40 text/tools.go• L26-53 text/tools.go• L55-66 text/tools.go• L242-255
Structured logging
The SDK connects its packages to streamingfast/logging and uses zap loggers for structured diagnostic records. Logging is an observation channel for internal behavior. It is not part of transaction or instruction semantics.
Logger scope
The root SDK package registers a logger under the SDK module name. The diff package registers its own scope and checks a trace setting before writing path traversal and event details. This keeps verbose comparison traces opt-in while preserving a shared structured logging setup.
Other SDK areas can register their own scopes in the same way. A logger that is not configured remains a no-op logger, so callers can use the library without setting up logging first.
References: logging.go• L18-30 diff/logging.go• L17-30 diff/diff.go• L218-274
Functional API boundary
These packages explain or display SDK data, but they do not perform the SDK's main functional work. The comparison utility observes two values, the text utility renders a value, and logging records an event; none of them sends an RPC request, signs a transaction, encodes an instruction for the chain, or changes caller state.
Use the functional APIs when the program must create valid Solana data or communicate with the network. Add these utilities when the program must answer why two states differ, make a value readable to a person, or preserve structured evidence about an internal path.
Change checklist
When these files or sections are changed, remember to consider these:
- Preserve the
diff.Eventcontract when changing comparison behavior. Consumers may depend on event kind, path text, and the old or new value being present for the selected kind. - Keep slice reporting aligned with path matching. Added and removed slice events use path forms that can include unknown source or destination indexes.
- Keep
TextEncodableoutput separate from binary and wire encodings. A display change must not silently change data sent to Solana. - Keep plain-output behavior aligned with
text.DisableColors. Command output and log capture can depend on the absence of terminal escape codes. - Keep logging scopes stable when moving diagnostic calls. Operators may enable trace output by package scope.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
Calling diff.Diff without an OnEvent option | The comparison panics instead of reporting changes | Always provide an event callback for diagnostic comparisons |
| Treating slice add/remove events as a move operation | A reorder can be given the wrong business meaning | Interpret slice paths and event kinds in the caller |
| Comparing colored text or logging colored output | Escape codes can make text differ even when its visible content matches | Set text.DisableColors for plain or machine-captured output |
| Expecting text output to define wire data | A readable representation can be mistaken for a valid binary or RPC value | Use the SDK's functional encoders and RPC APIs for network data |
Key files
| File | Why to read it |
|---|---|
| diff/diff.go | Defines comparison events, paths, filtering, and callback flow |
| text/encoder.go | Shows the general purpose of readable nested-value output |
| text/types.go | Shows how special display forms represent numeric and byte values |
| text/tools.go | Shows plain string, color, and highlighting helpers |
| text/tree.go | Shows the tree-shaped inspection interface |
| logging.go | Shows the root structured logging registration |
| diff/logging.go | Shows the comparison package's logging scope and trace boundary |