Skip to content

Commit

Permalink
support testnet and custom events endpoints (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
cameroncooper authored Sep 27, 2024
1 parent 0be4242 commit a40abd4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/cmd/coinset/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"encoding/json"
"fmt"
"log"
"os"
"os/signal"
"time"
Expand Down Expand Up @@ -40,10 +41,15 @@ func runEvents(cmd *cobra.Command, args []string) {
eventType = args[0]
}

c, _, err := websocket.DefaultDialer.Dial("wss://api.coinset.org/ws", nil)
endpoint := fmt.Sprintf("wss://%s/ws", apiHost())

if api != "" {
endpoint = api
}

c, _, err := websocket.DefaultDialer.Dial(endpoint, nil)
if err != nil {
fmt.Println(err)
return
log.Fatal(err.Error())
}
defer c.Close()

Expand Down
8 changes: 8 additions & 0 deletions internal/cmd/coinset/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ func formatHex(str string) string {
return "0x" + str
}

func apiHost() string {
baseUrl, err := url.Parse(apiRoot())
if err != nil {
log.Fatal(err.Error())
}
return baseUrl.Host
}

func apiRoot() string {
if api != "" {
return api
Expand Down

0 comments on commit a40abd4

Please sign in to comment.