|
1 | 1 | package node |
2 | 2 |
|
| 3 | +import ( |
| 4 | + stdJSON "encoding/json" |
| 5 | + |
| 6 | + "github.com/pkg/errors" |
| 7 | +) |
| 8 | + |
3 | 9 | // InvalidBlock - |
4 | 10 | type InvalidBlock struct { |
5 | 11 | Hash string `json:"block"` |
@@ -30,3 +36,103 @@ type Savepoint struct { |
30 | 36 | Hash string `json:"block_hash"` |
31 | 37 | Level uint64 `json:"level"` |
32 | 38 | } |
| 39 | + |
| 40 | +// MempoolResponse - |
| 41 | +type MempoolResponse struct { |
| 42 | + Applied []Applied `json:"applied"` |
| 43 | + Refused []Failed `json:"refused"` |
| 44 | + BranchRefused []Failed `json:"branch_refused"` |
| 45 | + BranchDelayed []Failed `json:"branch_delayed"` |
| 46 | +} |
| 47 | + |
| 48 | +// Applied - |
| 49 | +type Applied struct { |
| 50 | + Hash string `json:"hash"` |
| 51 | + Branch string `json:"branch"` |
| 52 | + Signature string `json:"signature"` |
| 53 | + Contents []Content `json:"contents"` |
| 54 | + Raw stdJSON.RawMessage `json:"raw"` |
| 55 | +} |
| 56 | + |
| 57 | +// UnmarshalJSON - |
| 58 | +func (a *Applied) UnmarshalJSON(data []byte) error { |
| 59 | + type buf Applied |
| 60 | + if err := json.Unmarshal(data, (*buf)(a)); err != nil { |
| 61 | + return err |
| 62 | + } |
| 63 | + a.Raw = data |
| 64 | + return nil |
| 65 | +} |
| 66 | + |
| 67 | +// Failed - |
| 68 | +type Failed struct { |
| 69 | + Hash string `json:"-"` |
| 70 | + Protocol string `json:"protocol"` |
| 71 | + Branch string `json:"branch"` |
| 72 | + Contents []Content `json:"contents"` |
| 73 | + Signature string `json:"signature,omitempty"` |
| 74 | + Error stdJSON.RawMessage `json:"error,omitempty"` |
| 75 | + Raw stdJSON.RawMessage `json:"raw"` |
| 76 | +} |
| 77 | + |
| 78 | +// UnmarshalJSON - |
| 79 | +func (f *Failed) UnmarshalJSON(data []byte) error { |
| 80 | + var body []stdJSON.RawMessage |
| 81 | + if err := json.Unmarshal(data, &body); err != nil { |
| 82 | + return err |
| 83 | + } |
| 84 | + if len(body) != 2 { |
| 85 | + return errors.Errorf("Invalid failed operation body %s", string(data)) |
| 86 | + } |
| 87 | + if err := json.Unmarshal(body[0], &f.Hash); err != nil { |
| 88 | + return err |
| 89 | + } |
| 90 | + type buf Failed |
| 91 | + if err := json.Unmarshal(body[1], (*buf)(f)); err != nil { |
| 92 | + return err |
| 93 | + } |
| 94 | + f.Raw = data |
| 95 | + return nil |
| 96 | +} |
| 97 | + |
| 98 | +// FailedMonitor - |
| 99 | +type FailedMonitor struct { |
| 100 | + Hash string `json:"hash"` |
| 101 | + Protocol string `json:"protocol"` |
| 102 | + Branch string `json:"branch"` |
| 103 | + Contents []Content `json:"contents"` |
| 104 | + Signature string `json:"signature,omitempty"` |
| 105 | + Error stdJSON.RawMessage `json:"error,omitempty"` |
| 106 | + Raw stdJSON.RawMessage `json:"raw"` |
| 107 | +} |
| 108 | + |
| 109 | +// UnmarshalJSON - |
| 110 | +func (f *FailedMonitor) UnmarshalJSON(data []byte) error { |
| 111 | + type buf FailedMonitor |
| 112 | + if err := json.Unmarshal(data, (*buf)(f)); err != nil { |
| 113 | + return err |
| 114 | + } |
| 115 | + f.Raw = data |
| 116 | + return nil |
| 117 | +} |
| 118 | + |
| 119 | +// Contents - |
| 120 | +type Content struct { |
| 121 | + Kind string `json:"kind"` |
| 122 | + Body stdJSON.RawMessage `json:"-"` |
| 123 | +} |
| 124 | + |
| 125 | +// UnmarshalJSON - |
| 126 | +func (c *Content) UnmarshalJSON(data []byte) error { |
| 127 | + type buf Content |
| 128 | + if err := json.Unmarshal(data, (*buf)(c)); err != nil { |
| 129 | + return err |
| 130 | + } |
| 131 | + c.Body = data |
| 132 | + return nil |
| 133 | +} |
| 134 | + |
| 135 | +// IsManager - |
| 136 | +func IsManager(kind string) bool { |
| 137 | + return kind == KindDelegation || kind == KindOrigination || kind == KindReveal || kind == KindTransaction |
| 138 | +} |
0 commit comments