Skip to content

feat(rpc): add NewWithCommitment / NewWithTimeout / NewWithTimeoutAndCommitment (#414)#436

Open
ozpool wants to merge 1 commit into
solana-foundation:mainfrom
ozpool:feat/rpc-client-constructors-414
Open

feat(rpc): add NewWithCommitment / NewWithTimeout / NewWithTimeoutAndCommitment (#414)#436
ozpool wants to merge 1 commit into
solana-foundation:mainfrom
ozpool:feat/rpc-client-constructors-414

Conversation

@ozpool
Copy link
Copy Markdown

@ozpool ozpool commented May 15, 2026

Description

Fixes #414. Adds the three rpc.Client constructor variants the issue asks for, plus a DefaultCommitment() accessor so callers can read the pinned commitment back without exporting a new field.

  • NewWithCommitment(url, commitment) pins a CommitmentType on the returned *Client. Methods that take an explicit commitment continue to honor whatever the caller passes; the stored value is exposed through Client.DefaultCommitment so consumers can use it as a fallback rather than threading it through every call site themselves.
  • NewWithTimeout(url, timeout) lifts the hardcoded http.Client timeout. The same value is also bound to the dialer's connect timeout and the transport's idle connection timeout so long-haul reads, connect, and pool eviction stay aligned.
  • NewWithTimeoutAndCommitment(url, timeout, commitment) is the combined variant, mirroring the rust-sdk RpcClient::new_with_timeout_and_commitment ergonomics.

The new constructors compose New / a small newHTTPWithTimeout helper, leaving the existing 5-minute default for callers using New unchanged. No behavior change for existing call sites.

Tests

Added rpc/client_constructors_test.go covering:

  • New returns an empty default commitment.
  • NewWithCommitment stores the pinned CommitmentFinalized value.
  • NewWithTimeout propagates the timeout to the underlying http.Client.Timeout.
  • NewWithTimeout does not pin a commitment.
  • NewWithTimeoutAndCommitment stores both the commitment and the timeout.
$ go test ./rpc/ -run "TestNew_DefaultCommitment_EmptyByDefault|TestNewWithCommitment_StoresDefault|TestNewWithTimeout_HonorsTimeoutOnHTTPClient|TestNewWithTimeout_DefaultCommitmentEmpty|TestNewWithTimeoutAndCommitment_StoresBoth" -v
PASS
ok      github.com/gagliardetto/solana-go/rpc   0.599s

…Commitment

Adds the three rpc.Client constructor variants requested in solana-foundation#414, plus a
DefaultCommitment() accessor so callers can read the pinned commitment back
without exporting a new field. The new constructors compose New / a small
newHTTPWithTimeout helper, leaving the existing 5-minute default for
callers using New unchanged.

- NewWithCommitment(url, commitment) pins a CommitmentType on the
  returned *Client. Methods that take an explicit commitment continue to
  honor whatever the caller passes; the stored value is exposed through
  Client.DefaultCommitment so consumers can use it as a fallback rather
  than threading it through every call site themselves.
- NewWithTimeout(url, timeout) lifts the hardcoded http.Client timeout.
  The same value is also bound to the dialer's connect timeout and the
  transport's idle connection timeout so long-haul reads, connect, and
  pool eviction stay aligned.
- NewWithTimeoutAndCommitment is the combined variant, mirroring the
  rust-sdk RpcClient::new_with_timeout_and_commitment ergonomics.

Adds rpc/client_constructors_test.go covering the empty-default case,
each constructor's stored state, and the http.Client.Timeout the
custom-timeout constructors emit.

Fixes solana-foundation#414
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Request] Add missing RPC Client constructors (with commitment, with timeout)

1 participant