Skip to content

Commit

Permalink
Generate a unique origin name when creating the client in case multip…
Browse files Browse the repository at this point in the history
…le different are connected, we dont receive responses we aren't expecting
  • Loading branch information
cmmarslender committed Jun 13, 2024
1 parent b4fee52 commit 4545080
Showing 1 changed file with 4 additions and 4 deletions.
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

0 comments on commit 4545080

Please sign in to comment.