-
Notifications
You must be signed in to change notification settings - Fork 4
/
chain_data.go
142 lines (125 loc) · 3.6 KB
/
chain_data.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package node
import (
stdJSON "encoding/json"
"github.com/pkg/errors"
)
// InvalidBlock -
type InvalidBlock struct {
Hash string `json:"block"`
Level uint64 `json:"level"`
Errors []interface{} `json:"errors"`
}
// Bootstrapped -
type Bootstrapped struct {
Bootstrapped bool `json:"bootstrapped"`
SyncState string `json:"sync_state"`
}
// Caboose -
type Caboose struct {
Hash string `json:"block_hash"`
Level uint64 `json:"level"`
}
// Checkpoint -
type Checkpoint struct {
Hash string `json:"block_hash"`
Level uint64 `json:"level"`
}
// Savepoint -
type Savepoint struct {
Hash string `json:"block_hash"`
Level uint64 `json:"level"`
}
// MempoolResponse -
type MempoolResponse struct {
Applied []Applied `json:"applied"`
Refused []Failed `json:"refused"`
BranchRefused []Failed `json:"branch_refused"`
BranchDelayed []Failed `json:"branch_delayed"`
Outdated []Failed `json:"outdated"`
}
// Applied -
type Applied struct {
Hash string `json:"hash"`
Branch string `json:"branch"`
Signature string `json:"signature"`
Contents []Content `json:"contents"`
Raw stdJSON.RawMessage `json:"raw"`
}
// UnmarshalJSON -
func (a *Applied) UnmarshalJSON(data []byte) error {
type buf Applied
if err := json.Unmarshal(data, (*buf)(a)); err != nil {
return err
}
a.Raw = data
return nil
}
// Failed -
type Failed struct {
Hash string `json:"-"`
Protocol string `json:"protocol"`
Branch string `json:"branch"`
Contents []Content `json:"contents"`
Signature string `json:"signature,omitempty"`
Error stdJSON.RawMessage `json:"error,omitempty"`
Raw stdJSON.RawMessage `json:"raw"`
}
// UnmarshalJSON -
func (f *Failed) UnmarshalJSON(data []byte) error {
var body []stdJSON.RawMessage
if err := json.Unmarshal(data, &body); err != nil {
return err
}
if len(body) != 2 {
return errors.Errorf("Invalid failed operation body %s", string(data))
}
if err := json.Unmarshal(body[0], &f.Hash); err != nil {
return err
}
type buf Failed
if err := json.Unmarshal(body[1], (*buf)(f)); err != nil {
return err
}
f.Raw = data
return nil
}
// FailedMonitor -
type FailedMonitor struct {
Hash string `json:"hash"`
Protocol string `json:"protocol"`
Branch string `json:"branch"`
Contents []Content `json:"contents"`
Signature string `json:"signature,omitempty"`
Error stdJSON.RawMessage `json:"error,omitempty"`
Raw stdJSON.RawMessage `json:"raw"`
}
// UnmarshalJSON -
func (f *FailedMonitor) UnmarshalJSON(data []byte) error {
type buf FailedMonitor
if err := json.Unmarshal(data, (*buf)(f)); err != nil {
return err
}
f.Raw = data
return nil
}
// Contents -
type Content struct {
Kind string `json:"kind"`
Body stdJSON.RawMessage `json:"-"`
}
// UnmarshalJSON -
func (c *Content) UnmarshalJSON(data []byte) error {
type buf Content
if err := json.Unmarshal(data, (*buf)(c)); err != nil {
return err
}
c.Body = data
return nil
}
// IsManager -
func IsManager(kind string) bool {
return kind == KindOrigination || kind == KindReveal || kind == KindTransaction || kind == KindSetDepositsLimit ||
kind == KindDelegation || kind == KindRegisterGlobalConstant || kind == KindTxRollupCommit || kind == KindTxRollupDispatchTickets ||
kind == KindTxRollupFinalizeCommitment || kind == KindTxRollupOrigination || kind == KindTxRollupRejection ||
kind == KindTxRollupRemoveCommitment || kind == KindTxRollupReturnBond || kind == KindTxRollupSubmitBatch
}