-
Notifications
You must be signed in to change notification settings - Fork 19
/
heights.go
50 lines (41 loc) · 1.36 KB
/
heights.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
// Copyright 2016 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package factom
import (
"encoding/json"
"fmt"
)
// HeightsResponse is a list of the various current heights of blocks from
// factomd. These show the current heights of blocks on the network as well as
// the heights of the blocks saved in the local factomd database.
type HeightsResponse struct {
DirectoryBlockHeight int64 `json:"directoryblockheight"`
LeaderHeight int64 `json:"leaderheight"`
EntryBlockHeight int64 `json:"entryblockheight"`
EntryHeight int64 `json:"entryheight"`
}
func (d *HeightsResponse) String() string {
var s string
s += fmt.Sprintln("DirectoryBlockHeight:", d.DirectoryBlockHeight)
s += fmt.Sprintln("LeaderHeight:", d.LeaderHeight)
s += fmt.Sprintln("EntryBlockHeight:", d.EntryBlockHeight)
s += fmt.Sprintln("EntryHeight:", d.EntryHeight)
return s
}
// GetHeights requests the list of heights from the factomd API.
func GetHeights() (*HeightsResponse, error) {
req := NewJSON2Request("heights", APICounter(), nil)
resp, err := factomdRequest(req)
if err != nil {
return nil, err
}
if resp.Error != nil {
return nil, resp.Error
}
heights := new(HeightsResponse)
if err := json.Unmarshal(resp.JSONResult(), heights); err != nil {
return nil, err
}
return heights, nil
}