-
Notifications
You must be signed in to change notification settings - Fork 205
/
test_core.go
54 lines (44 loc) · 888 Bytes
/
test_core.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
package main
import (
"encoding/json"
"log"
"net/http"
"os"
"time"
)
const timeout = 3 * time.Minute
type Info struct {
Info struct {
State string `json:"state"`
} `json:"info"`
}
func main() {
startTime := time.Now()
for {
time.Sleep(5 * time.Second)
logLine("Waiting for stellar-core to start catching up and sync")
if time.Since(startTime) > timeout {
logLine("Timeout")
os.Exit(-1)
}
resp, err := http.Get("http://localhost:11626/info")
if err != nil {
logLine(err)
continue
}
var info Info
decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(&info)
if err != nil {
logLine(err)
continue
}
logLine("Stellar-core is " + info.Info.State)
if info.Info.State == "Catching up" || info.Info.State == "Synced!" {
os.Exit(0)
}
}
}
func logLine(text interface{}) {
log.Println("\033[32;1m[test]\033[0m", text)
}