Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a unique origin name when creating the client #131

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/websocketclient/websocketclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ import (
"github.com/chia-network/go-chia-libs/pkg/util"
)

const origin string = "go-chia-rpc"

// WebsocketClient connects to Chia RPC via websockets
type WebsocketClient struct {
config *config.ChiaConfig
baseURL *url.URL
logger *slog.Logger
origin string

// Request timeout
Timeout time.Duration
Expand Down Expand Up @@ -64,6 +63,7 @@ func NewWebsocketClient(cfg *config.ChiaConfig, options ...rpcinterface.ClientOp
c := &WebsocketClient{
config: cfg,
logger: slog.New(rpcinterface.SlogInfo()),
origin: fmt.Sprintf("go-chia-rpc-%d", time.Now().UnixNano()),

Timeout: 10 * time.Second, // Default, overridable with client option

Expand Down Expand Up @@ -165,7 +165,7 @@ func (c *WebsocketClient) Do(req *rpcinterface.Request, v interface{}) (*http.Re
}
request := &types.WebsocketRequest{
Command: string(req.Endpoint),
Origin: origin,
Origin: c.origin,
Destination: destination,
Data: data,
RequestID: util.GenerateRequestID(),
Expand Down Expand Up @@ -238,7 +238,7 @@ func (c *WebsocketClient) responseHelper(request *types.WebsocketRequest, v inte
// Different from Subscribe with a custom service - that is more for subscribing to built in events emitted by Chia
// This call will subscribe `go-chia-rpc` origin for any requests we specifically make of the server
func (c *WebsocketClient) SubscribeSelf() error {
return c.Subscribe(origin)
return c.Subscribe(c.origin)
}

// Subscribe adds a subscription to a particular service
Expand Down