-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwork.go
424 lines (401 loc) · 12.2 KB
/
work.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"time"
"github.com/andrewarrow/wolfservers/digitalocean"
"github.com/andrewarrow/wolfservers/display"
"github.com/andrewarrow/wolfservers/files"
"github.com/andrewarrow/wolfservers/keys"
"github.com/andrewarrow/wolfservers/linode"
"github.com/andrewarrow/wolfservers/network"
"github.com/andrewarrow/wolfservers/runner"
"github.com/andrewarrow/wolfservers/sqlite"
"github.com/andrewarrow/wolfservers/vultr"
"github.com/justincampbell/timeago"
)
func AddARecord() {
ip := argMap["ip"]
name := argMap["name"]
digitalocean.AddRecord(pats["do"], "wolfschedule.com", ip, name)
}
func MainList() {
digitalocean.ListDroplets(pats["do"], ip2name)
vultr.ListServers(pats["vultr"], ip2name)
linode.ListServers(pats["linode"], ip2name)
fmt.Println("")
if argMap["keys"] == "true" {
sum := int64(0)
for _, ip := range ProducerIps(pats) {
//fmt.Println("ip", ip)
jsonString := network.DoIpGet(ip)
//fmt.Println("ip", jsonString)
var ls LsDataHolder
json.Unmarshal([]byte(jsonString), &ls)
tokens := strings.Split(ls.M.Date, " ")
month := tokens[0]
day := tokens[1]
hoursMins := tokens[2]
if len(tokens) == 5 {
month = tokens[0]
day = tokens[2]
hoursMins = tokens[3]
}
ts, _ := time.Parse("Jan 2, 2006 15:04",
fmt.Sprintf("%s %s, 2021 %s", month, day, hoursMins))
ago := timeago.FromDuration(time.Since(ts))
fmt.Printf("%s %s %d %0.2f %d %d %d\n", ip2name[ip],
display.LeftAligned(ago, 20),
ls.M.Tip.Epoch, float64(ls.M.Amount)/1000000.0, ls.M.Tip.Slot,
ls.M.Tip.Block, ls.M.Balance)
sum += ls.M.Amount
}
fmt.Printf("Total %0.2f\n", float64(sum)/1000000.0)
}
}
func Phases() {
fmt.Println("")
fmt.Println(" 1. Seed : new VM from provider, ip address known")
fmt.Println(" 2. Growing : cardano-node installed, sync started")
fmt.Println(" 3. Growing : sync complete, now generate block-producer keys")
fmt.Println(" 4. Growing : also setup payment, stake keys, send real ADA")
fmt.Println(" 5. Growing : build 1st tx, copy tx.raw to cold, sign, run hot")
fmt.Println(" 6. Growing : register your stake pool with DNS A record")
fmt.Println(" 7. Growing : pool.cert,deleg.cert to hot")
fmt.Println(" 8. Growing : build 2nd tx, copy tx.raw to cold, sign, run hot")
fmt.Println(" 9. Exciting : find your data on block explorers pooltool.io")
fmt.Println("10. Next : configure your topology files")
fmt.Println("11. Next : wait four hours!")
fmt.Println("12. Then : fetch your relay node buddies")
fmt.Println("13. MakeSure : must see the Processed TX number increasing")
fmt.Println("14. AndThen : wait an epoch or two and then...")
fmt.Println("15. OMG : checking stake pool rewards!")
fmt.Println("")
}
func IpAndName() (string, string) {
ip := argMap["ip"]
name := ip2name[ip]
return ip, name
}
func PaymentAddress() {
_, name := IpAndName()
pa, sa := sqlite.PaymentAddressQuery(name)
fmt.Println(pa, sa)
}
func foo() {
command := ""
if command == "" {
} else if command == "phases" {
} else if command == "next" {
ip := argMap["ip"]
name := ip2name[ip]
nodeKeySize := sqlite.NodeKeysQuery(name)
//paymentAddr := sqlite.PaymentKeysQuery(name)
fmt.Println(nodeKeySize)
//ioutil.WriteFile("payment.addr", []byte(paymentAddr), 0755)
//ScpFileToHot(name, "payment.addr", ip)
//os.Remove("payment.addr")
//if paymentAddr == "" {
// keys.MakePayment(name)
//}
} else if command == "tx-delegate" {
ip := argMap["ip"]
name := ip2name[ip]
ps, ss := sqlite.PaymentAndStakeSigning(name)
ioutil.WriteFile("payment.skey", []byte(ps), 0755)
ioutil.WriteFile("stake.skey", []byte(ss), 0755)
sqlite.CreateNodeKeysOnDisk(name)
keys.SignTxDelegate()
ScpFileToHot(name, "tx.signed", ip)
os.Remove("tx.raw")
os.Remove("tx.signed")
os.Remove("payment.skey")
os.Remove("stake.skey")
os.Remove("node.counter")
os.Remove("node.skey")
os.Remove("node.vkey")
result := runner.HotExec(name, ip, "cardano-cli transaction submit --tx-file /root/cardano-my-node/tx.signed --mainnet")
fmt.Println(result)
} else if command == "tx" {
} else if command == "deleg.cert" {
ip := argMap["ip"]
name := ip2name[ip]
sv := sqlite.PaymentStakeV(name)
ioutil.WriteFile("stake.vkey", []byte(sv), 0755)
sqlite.CreateNodeKeysOnDisk(name)
keys.Delegation()
ScpFileToHot(name, "deleg.cert", ip)
os.Remove("stake.vkey")
os.Remove("node.counter")
os.Remove("node.skey")
os.Remove("node.vkey")
os.Remove("deleg.cert")
} else if command == "pool.cert" {
ip := argMap["ip"]
name := ip2name[ip]
hash := "5318dc07f229acbace49e666124b528c99a36763857f67a2f379d428166577fa"
code := "3A81"
sv := sqlite.PaymentStakeV(name)
ioutil.WriteFile("stake.vkey", []byte(sv), 0755)
runner.ScpFileToCold(name, "vrf.vkey", ip)
sqlite.CreateNodeKeysOnDisk(name)
// 9997821299
// 9997.82
keys.StakePoolRegCert(9000, 2, hash, code)
ScpFileToHot(name, "pool.cert", ip)
os.Remove("stake.vkey")
os.Remove("node.counter")
os.Remove("node.skey")
os.Remove("node.vkey")
os.Remove("pool.cert")
} else if command == "stake.cert" {
ip := argMap["ip"]
name := ip2name[ip]
sv := sqlite.PaymentStakeV(name)
ioutil.WriteFile("stake.vkey", []byte(sv), 0755)
keys.MakeStakeCert()
ScpFileToHot(name, "stake.cert", ip)
os.Remove("stake.vkey")
os.Remove("stake.cert")
} else if command == "keys" {
digitalocean.ListKeys()
} else if command == "cold" {
ip := argMap["ip"]
name := ip2name[ip]
runner.ScpFileToCold(name, "tx.raw", ip)
} else if command == "hot" {
ip := argMap["ip"]
RunHot(ip2name[ip], ip)
} else if command == "issue-op-cert" {
ip := argMap["ip"]
name := ip2name[ip]
// 1. download kes.vkey
CatKesV(name, ip)
// 2. use node.skey from sqlite
sqlite.CreateNodeKeysOnDisk(name)
// 3. get startKesPeriod from hot
startKesPeriod := RunHot(name, ip)
// 4. keys.IssueOpCert(startKesPeriod)
keys.IssueOpCert(startKesPeriod)
// 5. upload node.cert to hot
ScpFileToHot(name, "node.cert", ip)
// 6. delete local kes.vkey, node.skey
os.Remove("kes.vkey")
os.Remove("node.cert")
os.Remove("node.counter")
os.Remove("node.skey")
os.Remove("node.vkey")
} else if command == "add-pat" {
provider := argMap["provider"]
pat := argMap["pat"]
sqlite.InsertPat(provider, pat)
} else if command == "show-oath" {
} else if command == "add-oath" {
} else if command == "comments" {
} else if command == "touch" {
} else if command == "deploy" {
} else if command == "temp" {
ip := argMap["ip"]
name := ip2name[ip]
ScpFileToHot(name, "scripts/stake.register", ip)
ScpFileToHot(name, "scripts/delegate.pool", ip)
} else if command == "poolMetaData" {
code := argMap["code"]
GenPoolMetaData(code)
} else if command == "ready-params" {
ip := argMap["ip"]
name := ip2name[ip]
o := runner.HotExec(name, ip, "cardano-cli query protocol-parameters --mainnet --out-file /root/cardano-my-node/params.json")
fmt.Println(o)
} else if command == "sqlite" {
sqlite.List()
} else if command == "images" {
digitalocean.ListImages(1)
digitalocean.ListImages(2)
} else if command == "producer" {
// https://www.coincashew.com/coins/overview-ada/guide-how-to-build-a-haskell-stakepool-node
dest := argMap["producer"]
PrepDest(dest)
MakeProducer(argMap["relay"])
ScpFile(ip2name[dest], "scripts/cardano.setup", dest)
ScpFile(ip2name[dest], "scripts/stake.register", dest)
ScpFile(ip2name[dest], "scripts/delegate.pool", dest)
ScpFile(ip2name[dest], "producer.sh", dest)
fmt.Println("1. ssh as root")
fmt.Println("2. run cardano.setup")
fmt.Println("3. . .bashrc")
fmt.Println("4. run producer.sh")
} else if command == "relay" {
dest := argMap["relay"]
PrepDest(dest)
MakeRelay(argMap["producer"])
ScpFile(ip2name[dest], "scripts/cardano.setup", dest)
ScpFile(ip2name[dest], "scripts/stake.register", dest)
ScpFile(ip2name[dest], "scripts/delegate.pool", dest)
ScpFile(ip2name[dest], "relay.sh", dest)
fmt.Println("1. ssh as root")
fmt.Println("2. run cardano.setup")
fmt.Println("3. . .bashrc")
fmt.Println("4. run relay.sh")
} else if command == "update-ips" {
} else if command == "ssh" {
} else if command == "update-ed" {
name := argMap["name"]
keys.UpdateRowForEds(name)
} else if command == "update-ids" {
producer := argMap["producer"]
relay := argMap["relay"]
name := argMap["name"]
sqlite.UpdateIds(name, producer, relay)
} else if command == "fresh2linode" {
if argMap["sure"] == "" {
return
}
linode.CreateServer(pats["linode"], "producer")
linode.CreateServer(pats["linode"], "relay")
} else if command == "fresh2vultr" {
if argMap["sure"] == "" {
return
}
vultr.CreateServer(pats["vultr"], "producer")
vultr.CreateServer(pats["vultr"], "relay")
} else if command == "fresh2do" {
if argMap["sure"] == "" {
return
}
// make 2 droplets, name one producer one relay, wait for their ips
// size := "s-4vcpu-8gb"
size := "s-1vcpu-2gb"
keys := digitalocean.ListKeyFingerprints()
key := keys[0]
digitalocean.CreateDroplet(pats["do"], "producer", size, key)
digitalocean.CreateDroplet(pats["do"], "relay", size, key)
} else if command == "node-keys" {
ip := argMap["ip"]
name := ip2name[ip]
keys.MakeNode(name)
keys.MakePayment(name)
ScpFileToHot(name, "payment.addr", ip)
} else if command == "domains-do" {
digitalocean.ListDomainRecords(pats["do"], "wolfschedule.com")
} else if command == "add-a-record" {
} else if command == "danger-do" {
} else if command == "danger-vultr" {
} else if command == "danger-linode" {
} else if command == "ed255" {
}
}
func MainSsh() {
ip := argMap["ip"]
name := ip2name[ip]
user := "aa"
if argMap["root"] == "true" {
user = "root"
}
SshAsUser(user, name, ip)
}
func Ed255() {
if argMap["provider"] == "" {
return
}
provider := argMap["provider"]
if provider == "linode" {
ids := linode.ListKeys(pats["linode"])
for _, id := range ids {
linode.DeleteSshKey(pats["linode"], id)
}
name, pubKey := keys.MakeEd("LINODE")
linode.CreateSshKey(pats["linode"], name, strings.TrimSpace(pubKey))
} else if provider == "vultr" {
ids := vultr.ListKeys(pats["vultr"])
for _, id := range ids {
vultr.DeleteKey(pats["vultr"], id)
}
name, pubKey := keys.MakeEd("VULTR")
vultr.CreateKey(pats["vultr"], name, strings.TrimSpace(pubKey))
} else if provider == "do" {
ids := digitalocean.ListKeys()
for _, id := range ids {
digitalocean.DeleteKey(id)
}
name, pubKey := keys.MakeEd("DO")
digitalocean.CreateKey(name, strings.TrimSpace(pubKey))
}
}
func UpdateIps() {
producer := argMap["producer"]
relay := argMap["relay"]
name := argMap["name"]
sqlite.UpdateIps(name, producer, relay)
}
func DeployEyes() {
for _, ip := range ProducerIps(pats) {
name := ip2name[ip]
fmt.Println(name)
ScpFileToAa(name, "eyes.next", ip)
}
}
func RunTx() {
ip := argMap["ip"]
name := ip2name[ip]
ps, ss := sqlite.PaymentAndStakeSigning(name)
ioutil.WriteFile("payment.skey", []byte(ps), 0755)
ioutil.WriteFile("stake.skey", []byte(ss), 0755)
keys.SignTx()
ScpFileToHot(name, "tx.signed", ip)
os.Remove("tx.raw")
os.Remove("tx.signed")
os.Remove("payment.skey")
os.Remove("stake.skey")
result := runner.HotExec(name, ip, "cardano-cli transaction submit --tx-file /root/cardano-my-node/tx.signed --mainnet")
fmt.Println(result)
}
func DangerDo() {
if argMap["ID"] == "" {
return
}
id, _ := strconv.Atoi(argMap["ID"])
digitalocean.RemoveDroplet(pats["do"], id)
}
func DangerLinode() {
if argMap["ID"] == "" {
return
}
id, _ := strconv.Atoi(argMap["ID"])
linode.RemoveServer(pats["linode"], id)
}
func DangerVultr() {
if argMap["ID"] == "" {
return
}
vultr.RemoveServer(pats["vultr"], argMap["ID"])
}
func AddOath() {
name := argMap["name"]
seed := argMap["seed"]
username := argMap["username"]
password := argMap["password"]
sqlite.InsertOath(name, seed, username, password)
}
func Comments() {
in := argMap["in"]
files.RemoveComments(in)
}
func Fresh1Vultr() {
if argMap["sure"] == "" {
return
}
vultr.CreateServer(pats["vultr"], "bitclout")
}
func BitClout() {
dest := argMap["producer"]
PrepDest(dest)
MakeBitClout()
ScpFile(ip2name[dest], "scripts/bitclout.setup", dest)
fmt.Println("1. ssh as root")
fmt.Println("2. run bitclout.setup")
}