-
Notifications
You must be signed in to change notification settings - Fork 0
/
casper.go
54 lines (41 loc) · 1.35 KB
/
casper.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"
"html/template"
"io/ioutil"
"log"
"net/http"
)
func casperHandler(w http.ResponseWriter, r *http.Request) {
getCasperData()
if r.Method != "POST" {
t, err := template.ParseFiles("templates/casper.html", "templates/header.html", "templates/footer.html")
if err != nil {
log.Fatal(w, err.Error())
return
}
t.ExecuteTemplate(w, "casper", casperData)
return
}
}
func getCasperData() {
res, err := http.Get(casperNodeURL)
checkErr(err)
body, err := ioutil.ReadAll(res.Body)
checkErr(err)
var nodeData CasperResponse
json.Unmarshal(body, &nodeData)
casperData.APIVersion = nodeData.APIVersion
casperData.BuildVersion = nodeData.BuildVersion
casperData.ChainspecName = nodeData.ChainspecName
casperData.OurPublicSigningKey = nodeData.OurPublicSigningKey
casperData.StartingStateRootHash = nodeData.StartingStateRootHash
casperData.Hash = nodeData.LastAddedBlockInfo.Hash
casperData.Timestamp = nodeData.LastAddedBlockInfo.Timestamp
casperData.EraID = nodeData.LastAddedBlockInfo.EraID
casperData.Height = nodeData.LastAddedBlockInfo.Height
casperData.StateRootHash = nodeData.LastAddedBlockInfo.StateRootHash
casperData.Creator = nodeData.LastAddedBlockInfo.Creator
casperData.ActivationPoint = nodeData.NextUpgrade.ActivationPoint
casperData.ProtocolVersion = nodeData.NextUpgrade.ProtocolVersion
}