Skip to content

Add URL() method to rpcclient.Client to expose configured URL #5885

@leighmcculloch

Description

@leighmcculloch

What problem does your feature solve?

The rpcclient.Client struct stores the RPC URL internally but doesn't expose it:

type Client struct {
	url        string  // unexported
	cli        *jrpc2.Client
	mx         sync.RWMutex
	httpClient *http.Client
}

When wrapping the client in another type, there's no way to retrieve the URL it was configured with. This is useful for debugging, logging, and testing purposes.

For comparison, horizonclient.Client has an exported HorizonURL field that can be accessed directly.

What would you like to see?

Add a URL() method to rpcclient.Client that returns the configured URL:

// URL returns the RPC server URL this client is configured to use.
func (c *Client) URL() string {
	return c.url
}

What alternatives are there?

  1. Store a duplicate copy of the URL - This is what we're currently doing in stellar/friendbot when wrapping the client, but it's redundant since the client already has this information.

  2. Export the url field - Change url to URL to make it exported. However, a getter method is preferred as it maintains encapsulation and allows for future flexibility.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions