@@ -25,15 +25,16 @@ func (c *Client) Close() {
2525}
2626
2727// httpToWS converts an HTTP(S) URL to a WebSocket URL.
28- // go-jsonrpc requires WebSocket for channel-based subscriptions (e.g. Subscribe).
29- // WebSocket connections also support regular RPC calls, so this is backward-compatible.
3028func httpToWS (addr string ) string {
3129 addr = strings .Replace (addr , "https://" , "wss://" , 1 )
3230 addr = strings .Replace (addr , "http://" , "ws://" , 1 )
3331 return addr
3432}
3533
36- // NewClient connects to the celestia-node RPC endpoint
34+ // NewClient connects to the DA RPC endpoint using the address as-is.
35+ // Uses HTTP by default (lazy connection — only connects on first RPC call).
36+ // Does NOT support channel-based subscriptions (e.g. Subscribe).
37+ // For subscription support, use NewWSClient instead.
3738func NewClient (ctx context.Context , addr , token string , authHeaderName string ) (* Client , error ) {
3839 var httpHeader http.Header
3940 if token != "" {
@@ -43,19 +44,16 @@ func NewClient(ctx context.Context, addr, token string, authHeaderName string) (
4344 httpHeader = http.Header {authHeaderName : []string {fmt .Sprintf ("Bearer %s" , token )}}
4445 }
4546
46- // Use WebSocket so that channel-based subscriptions (blob.Subscribe) work.
47- wsAddr := httpToWS (addr )
48-
4947 var cl Client
5048
5149 // Connect to the blob namespace
52- blobCloser , err := jsonrpc .NewClient (ctx , wsAddr , "blob" , & cl .Blob .Internal , httpHeader )
50+ blobCloser , err := jsonrpc .NewClient (ctx , addr , "blob" , & cl .Blob .Internal , httpHeader )
5351 if err != nil {
5452 return nil , fmt .Errorf ("failed to connect to blob namespace: %w" , err )
5553 }
5654
5755 // Connect to the header namespace
58- headerCloser , err := jsonrpc .NewClient (ctx , wsAddr , "header" , & cl .Header .Internal , httpHeader )
56+ headerCloser , err := jsonrpc .NewClient (ctx , addr , "header" , & cl .Header .Internal , httpHeader )
5957 if err != nil {
6058 blobCloser ()
6159 return nil , fmt .Errorf ("failed to connect to header namespace: %w" , err )
@@ -70,6 +68,15 @@ func NewClient(ctx context.Context, addr, token string, authHeaderName string) (
7068 return & cl , nil
7169}
7270
71+ // NewWSClient connects to the DA RPC endpoint over WebSocket.
72+ // Automatically converts http:// to ws:// (and https:// to wss://).
73+ // Supports channel-based subscriptions (e.g. Subscribe).
74+ // Note: WebSocket connections are eager — they connect at creation time
75+ // and will fail immediately if the server is unavailable.
76+ func NewWSClient (ctx context.Context , addr , token string , authHeaderName string ) (* Client , error ) {
77+ return NewClient (ctx , httpToWS (addr ), token , authHeaderName )
78+ }
79+
7380// BlobAPI mirrors celestia-node's blob module (nodebuilder/blob/blob.go).
7481// jsonrpc.NewClient wires Internal.* to RPC stubs.
7582type BlobAPI struct {
0 commit comments