-
Notifications
You must be signed in to change notification settings - Fork 16
/
tendermint.go
62 lines (57 loc) · 1.48 KB
/
tendermint.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
package types
import (
"encoding/json"
"strconv"
"time"
)
func GetBlockHeight(msg []byte) (uint64, error) {
t := new(NewBlockJSON)
err := json.Unmarshal(msg, t)
if err != nil {
return 0, err
}
if t.Result.Data.Value.Block.Header.Height == "" {
return 0, nil
}
return strconv.ParseUint(t.Result.Data.Value.Block.Header.Height, 10, 64)
}
// todo mercilex split in concrete types instead of anonymous
type NewBlockJSON struct {
Jsonrpc string `json:"jsonrpc"`
ID int `json:"id"`
Result struct {
Query string `json:"query"`
Data struct {
Type string `json:"type"`
Value struct {
Block struct {
Header struct {
ChainID string `json:"chain_id"`
Height string `json:"height"`
Time time.Time `json:"time"`
LastCommitHash string `json:"last_commit_hash"`
} `json:"header"`
Data struct {
Txs []interface{} `json:"txs"`
} `json:"data"`
} `json:"block"`
ResultBeginBlock struct {
Events []TmEvent `json:"events"`
} `json:"result_begin_block"`
ResultEndBlock struct {
ValidatorUpdates []interface{} `json:"validator_updates"`
Events []TmEvent `json:"events"`
} `json:"result_end_block"`
} `json:"value"`
} `json:"data"`
} `json:"result"`
}
type TmEvent struct {
Type string `json:"type"`
Attributes []TmEventAttribute
}
type TmEventAttribute struct {
Key string `json:"key"`
Value string `json:"value"`
Index bool `json:"index"`
}