-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathremoteNodes.go
55 lines (40 loc) · 1.28 KB
/
remoteNodes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"strconv"
log "github.com/sirupsen/logrus"
)
type nodes struct {
Nodes []node `json:"nodes"`
}
type node struct {
Name string `json:"name"`
URL string `json:"url"`
Port uint64 `json:"port"`
SSL bool `json:"ssl"`
}
const urlTurtleCoinRemoteNodes = "https://raw.githubusercontent.com/turtlecoin/turtlecoin-nodes-json/master/turtlecoin-nodes.json"
func requestListRemoteNodes() (remoteNodes []node) {
theNodes := new(nodes)
err := getJSONFromHTTPRequest(urlTurtleCoinRemoteNodes, theNodes)
if err != nil {
// if error getting the list, include only one node - the default one
var defaultNode node
defaultNode.Name = defaultRemoteDaemonName
defaultNode.URL = defaultRemoteDaemonAddress
defaultPort, err := strconv.ParseUint(defaultRemoteDaemonPort, 10, 64)
if err != nil {
log.Fatal("error parsing remote node port: ", err)
}
defaultNode.Port = defaultPort
defaultNode.SSL = defaultRemoteDaemonSSL
remoteNodes = append(remoteNodes, defaultNode)
} else {
remoteNodes = theNodes.Nodes
}
// add an item for displaying the custom node in the dropdown list
var customNode node
customNode.Name = "Custom (change in settings)"
customNode.URL = "Custom (change in settings)"
remoteNodes = append(remoteNodes, customNode)
return remoteNodes
}