-
Notifications
You must be signed in to change notification settings - Fork 206
/
types.go
114 lines (101 loc) · 2.77 KB
/
types.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
package types
import (
"bytes"
"encoding/json"
)
const (
APIInterfaceJsonRPC = "jsonrpc"
APIInterfaceTendermintRPC = "tendermintrpc"
APIInterfaceRest = "rest"
APIInterfaceGrpc = "grpc"
)
const (
ParamChangeEventName = "param_change"
SpecAddEventName = "spec_add"
SpecModifyEventName = "spec_modify"
SpecRefreshEventName = "spec_refresh"
)
const (
EncodingBase64 = "base64"
EncodingHex = "hex"
)
const (
NOT_APPLICABLE int64 = -1
LATEST_BLOCK int64 = -2
EARLIEST_BLOCK int64 = -3
PENDING_BLOCK int64 = -4
SAFE_BLOCK int64 = -5
FINALIZED_BLOCK int64 = -6
)
const (
DEFAULT_PARSED_RESULT_INDEX = 0
)
// allows unmarshaling parser func
func (s PARSER_FUNC) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString(`"`)
buffer.WriteString(PARSER_FUNC_name[int32(s)])
buffer.WriteString(`"`)
return buffer.Bytes(), nil
}
// UnmarshalJSON unmashals a quoted json string to the enum value
func (s *PARSER_FUNC) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
if err != nil {
return err
}
// Note that if the string cannot be found then it will be set to the zero value, 'Created' in this case.
*s = PARSER_FUNC(PARSER_FUNC_value[j])
return nil
}
// allows unmarshaling parser func
func (s FUNCTION_TAG) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString(`"`)
buffer.WriteString(s.String())
buffer.WriteString(`"`)
return buffer.Bytes(), nil
}
// UnmarshalJSON unmashals a quoted json string to the enum value
func (s *FUNCTION_TAG) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
if err != nil {
return err
}
// Note that if the string cannot be found then it will be set to the zero value, 'Created' in this case.
*s = FUNCTION_TAG(FUNCTION_TAG_value[j])
return nil
}
// allows unmarshaling header type
func (s Header_HeaderType) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString(`"`)
buffer.WriteString(Header_HeaderType_name[int32(s)])
buffer.WriteString(`"`)
return buffer.Bytes(), nil
}
// UnmarshalJSON unmarshals a quoted json string to the enum value
func (s *Header_HeaderType) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
if err != nil {
return err
}
// Note that if the string cannot be found then it will be set to the zero value, 'Created' in this case.
*s = Header_HeaderType(Header_HeaderType_value[j])
return nil
}
func IsFinalizedBlock(requestedBlock, latestBlock int64, finalizationCriteria uint32) bool {
switch requestedBlock {
case NOT_APPLICABLE:
return false
// TODO: handle safe & finalized key words, currently returns false
default:
if requestedBlock < 0 {
return false
}
if requestedBlock <= latestBlock-int64(finalizationCriteria) {
return true
}
}
return false
}