This repository has been archived by the owner on Sep 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
arkenv.go
227 lines (204 loc) · 5.61 KB
/
arkenv.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package core
import (
"encoding/json"
"log"
"math/rand"
"net/http"
"strings"
"time"
"github.com/kristjank/ark-go/arkcoin"
)
type ArkNetworkType int
const (
MAINNET = iota
DEVNET
)
const (
SATOSHI = 100000000
)
//Global ARK EnvironmentParams read from acitve peers
var EnvironmentParams = new(ArkEnvParams)
//ArkEnvParams structure to hold parameters from autoconfigure
//structure is filled from peers at arkclient init call
type ArkEnvParams struct {
Success bool `json:"success"`
Network Network `json:"network"`
Fees Fees `json:"fees"`
}
//Fees constant parameters for active configuration
type Fees struct {
Send int64 `json:"send"`
Vote int64 `json:"vote"`
SecondSignature int64 `json:"secondsignature"`
Delegate int64 `json:"delegate"`
MultiSignature int64 `json:"multisignature"`
}
//Network parameters
type Network struct {
Nethash string `json:"nethash"`
Token string `json:"token"`
Symbol string `json:"symbol"`
Explorer string `json:"explorer"`
AddressVersion byte `json:"version"` //this is address generator version!!!
Type ArkNetworkType //holding ark networktype
ActivePeer Peer
}
//SetActiveConfiguration reads arknetwork parameters from the Network
//and fills the EnvironmentParams structure
//selected and connected peer address is returned
func LoadActiveConfiguration(arknetwork ArkNetworkType) string {
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)
selectedPeer := ""
EnvironmentParams.Network.Type = arknetwork
switch arknetwork {
case MAINNET:
log.Println("Active network is MAINNET")
selectedPeer = SeedList[r1.Intn(len(SeedList))]
log.Println("Random peer selected: ", selectedPeer)
case DEVNET:
log.Println("Active network is DEVNET")
selectedPeer = TestSeedList[r1.Intn(len(SeedList))]
log.Println("Random peer selected: ", selectedPeer)
}
//reading basic network params
res, err := http.Get("http://" + selectedPeer + "/api/loader/autoconfigure")
if err != nil {
log.Fatal("Error receiving autoloader params rest from: ", selectedPeer)
}
json.NewDecoder(res.Body).Decode(&EnvironmentParams)
//reading fees
res, err = http.Get("http://" + selectedPeer + "/api/blocks/getfees")
if err != nil {
log.Fatal("Error receiving fees params rest from: ", selectedPeer)
}
json.NewDecoder(res.Body).Decode(&EnvironmentParams)
//getting connected peer params
peerParams := strings.Split(selectedPeer, ":")
peerRes := new(PeerResponse)
res, err = http.Get("http://" + selectedPeer + "/api/peers/get/?ip=" + peerParams[0] + "&port=" + peerParams[1])
if err != nil {
log.Fatal("Error receiving peer status from: ", selectedPeer, err.Error(), res.StatusCode)
}
json.NewDecoder(res.Body).Decode(peerRes)
EnvironmentParams.Network.ActivePeer = peerRes.SinglePeer
return "http://" + selectedPeer
}
func switchNetwork(arkNetwork ArkNetworkType) {
BaseURL = LoadActiveConfiguration(arkNetwork)
var wifHeader = []byte{170}
if arkNetwork == DEVNET {
wifHeader = []byte{239}
}
coinParams := arkcoin.Params{
AddressHeader: EnvironmentParams.Network.AddressVersion,
DumpedPrivateKeyHeader: wifHeader,
}
arkcoin.SetActiveCoinConfiguration(&coinParams)
}
func (s *ArkClient) SetActiveConfiguration(arkNetwork ArkNetworkType) *ArkClient {
switchNetwork(arkNetwork)
return NewArkClient(nil)
}
var SeedList = [...]string{
"5.39.9.240:4001",
"5.39.9.241:4001",
"5.39.9.242:4001",
"5.39.9.243:4001",
"5.39.9.244:4001",
"5.39.9.250:4001",
"5.39.9.251:4001",
"5.39.9.252:4001",
"5.39.9.253:4001",
"5.39.9.254:4001",
"5.39.9.255:4001",
"5.39.53.48:4001",
"5.39.53.49:4001",
"5.39.53.50:4001",
"5.39.53.51:4001",
"5.39.53.52:4001",
"5.39.53.53:4001",
"5.39.53.54:4001",
"5.39.53.55:4001",
"37.59.129.160:4001",
"37.59.129.161:4001",
"37.59.129.162:4001",
"37.59.129.163:4001",
"37.59.129.164:4001",
"37.59.129.165:4001",
"37.59.129.166:4001",
"37.59.129.167:4001",
"37.59.129.168:4001",
"37.59.129.169:4001",
"37.59.129.170:4001",
"37.59.129.171:4001",
"37.59.129.172:4001",
"37.59.129.173:4001",
"37.59.129.174:4001",
"37.59.129.175:4001",
"193.70.72.80:4001",
"193.70.72.81:4001",
"193.70.72.82:4001",
"193.70.72.83:4001",
"193.70.72.84:4001",
"193.70.72.85:4001",
"193.70.72.86:4001",
"193.70.72.87:4001",
"193.70.72.88:4001",
"193.70.72.89:4001",
"193.70.72.90:4001"}
var TestSeedList = [...]string{
"164.8.251.179:4002",
"164.8.251.172:4002",
"164.8.251.91:4002",
"167.114.43.48:4002",
"167.114.29.49:4002",
"167.114.43.43:4002",
"167.114.29.54:4002",
"167.114.29.45:4002",
"167.114.29.40:4002",
"167.114.29.56:4002",
"167.114.43.35:4002",
"167.114.29.51:4002",
"167.114.29.59:4002",
"167.114.43.42:4002",
"167.114.29.34:4002",
"167.114.29.62:4002",
"167.114.43.49:4002",
"167.114.29.44:4002",
"167.114.43.37:4002",
"167.114.29.63:4002",
"167.114.29.42:4002",
"167.114.29.48:4002",
"167.114.29.61:4002",
"167.114.43.36:4002",
"167.114.29.57:4002",
"167.114.43.33:4002",
"167.114.29.52:4002",
"167.114.29.50:4002",
"167.114.43.47:4002",
"167.114.29.47:4002",
"167.114.29.36:4002",
"167.114.29.35:4002",
"167.114.43.39:4002",
"167.114.43.45:4002",
"167.114.29.46:4002",
"167.114.29.41:4002",
"167.114.43.34:4002",
"167.114.29.43:4002",
"167.114.43.41:4002",
"167.114.29.60:4002",
"167.114.43.32:4002",
"167.114.29.55:4002",
"167.114.29.53:4002",
"167.114.29.38:4002",
"167.114.43.40:4002",
"167.114.29.32:4002",
"167.114.43.46:4002",
"167.114.43.38:4002",
"167.114.29.33:4002",
"167.114.43.44:4002",
"167.114.43.50:4002",
"167.114.29.37:4002",
"167.114.29.58:4002",
"167.114.29.39:4002"}