/
off_chain_call_contract.go
401 lines (292 loc) · 8.24 KB
/
off_chain_call_contract.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"bytes"
"encoding/json"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// OffChainCallContract off chain call contract
// swagger:model OffChainCallContract
type OffChainCallContract struct {
// ABI version for the call/calldata
// Maximum: 65535
// Minimum: 0
AbiVersion *int64 `json:"abi_version,omitempty"`
// Amount of tokens to transfer to the contract
// Required: true
Amount *uint64 `json:"amount"`
// Contract call data
// Required: true
CallData EncodedByteArray `json:"call_data"`
// Contract caller
// Required: true
Caller EncodedHash `json:"caller"`
// Contract address
// Required: true
Contract EncodedHash `json:"contract"`
// Gas limit for the contract call
// Required: true
Gas *uint64 `json:"gas"`
// Gas price for the contract call
// Required: true
GasPrice *uint64 `json:"gas_price"`
// ABI version for the call/calldata
// Maximum: 65535
// Minimum: 0
VMVersion *int64 `json:"vm_version,omitempty"`
}
// Op gets the op of this subtype
func (m *OffChainCallContract) Op() string {
return "OffChainCallContract"
}
// SetOp sets the op of this subtype
func (m *OffChainCallContract) SetOp(val string) {
}
// AbiVersion gets the abi version of this subtype
// Amount gets the amount of this subtype
// CallData gets the call data of this subtype
// Caller gets the caller of this subtype
// Contract gets the contract of this subtype
// Gas gets the gas of this subtype
// GasPrice gets the gas price of this subtype
// VMVersion gets the vm version of this subtype
// UnmarshalJSON unmarshals this object with a polymorphic type from a JSON structure
func (m *OffChainCallContract) UnmarshalJSON(raw []byte) error {
var data struct {
// ABI version for the call/calldata
// Maximum: 65535
// Minimum: 0
AbiVersion *int64 `json:"abi_version,omitempty"`
// Amount of tokens to transfer to the contract
// Required: true
Amount *uint64 `json:"amount"`
// Contract call data
// Required: true
CallData EncodedByteArray `json:"call_data"`
// Contract caller
// Required: true
Caller EncodedHash `json:"caller"`
// Contract address
// Required: true
Contract EncodedHash `json:"contract"`
// Gas limit for the contract call
// Required: true
Gas *uint64 `json:"gas"`
// Gas price for the contract call
// Required: true
GasPrice *uint64 `json:"gas_price"`
// ABI version for the call/calldata
// Maximum: 65535
// Minimum: 0
VMVersion *int64 `json:"vm_version,omitempty"`
}
buf := bytes.NewBuffer(raw)
dec := json.NewDecoder(buf)
dec.UseNumber()
if err := dec.Decode(&data); err != nil {
return err
}
var base struct {
/* Just the base type fields. Used for unmashalling polymorphic types.*/
Op string `json:"op"`
}
buf = bytes.NewBuffer(raw)
dec = json.NewDecoder(buf)
dec.UseNumber()
if err := dec.Decode(&base); err != nil {
return err
}
var result OffChainCallContract
if base.Op != result.Op() {
/* Not the type we're looking for. */
return errors.New(422, "invalid op value: %q", base.Op)
}
result.AbiVersion = data.AbiVersion
result.Amount = data.Amount
result.CallData = data.CallData
result.Caller = data.Caller
result.Contract = data.Contract
result.Gas = data.Gas
result.GasPrice = data.GasPrice
result.VMVersion = data.VMVersion
*m = result
return nil
}
// MarshalJSON marshals this object with a polymorphic type to a JSON structure
func (m OffChainCallContract) MarshalJSON() ([]byte, error) {
var b1, b2, b3 []byte
var err error
b1, err = json.Marshal(struct {
// ABI version for the call/calldata
// Maximum: 65535
// Minimum: 0
AbiVersion *int64 `json:"abi_version,omitempty"`
// Amount of tokens to transfer to the contract
// Required: true
Amount *uint64 `json:"amount"`
// Contract call data
// Required: true
CallData EncodedByteArray `json:"call_data"`
// Contract caller
// Required: true
Caller EncodedHash `json:"caller"`
// Contract address
// Required: true
Contract EncodedHash `json:"contract"`
// Gas limit for the contract call
// Required: true
Gas *uint64 `json:"gas"`
// Gas price for the contract call
// Required: true
GasPrice *uint64 `json:"gas_price"`
// ABI version for the call/calldata
// Maximum: 65535
// Minimum: 0
VMVersion *int64 `json:"vm_version,omitempty"`
}{
AbiVersion: m.AbiVersion,
Amount: m.Amount,
CallData: m.CallData,
Caller: m.Caller,
Contract: m.Contract,
Gas: m.Gas,
GasPrice: m.GasPrice,
VMVersion: m.VMVersion,
},
)
if err != nil {
return nil, err
}
b2, err = json.Marshal(struct {
Op string `json:"op"`
}{
Op: m.Op(),
},
)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2, b3), nil
}
// Validate validates this off chain call contract
func (m *OffChainCallContract) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateAbiVersion(formats); err != nil {
res = append(res, err)
}
if err := m.validateAmount(formats); err != nil {
res = append(res, err)
}
if err := m.validateCallData(formats); err != nil {
res = append(res, err)
}
if err := m.validateCaller(formats); err != nil {
res = append(res, err)
}
if err := m.validateContract(formats); err != nil {
res = append(res, err)
}
if err := m.validateGas(formats); err != nil {
res = append(res, err)
}
if err := m.validateGasPrice(formats); err != nil {
res = append(res, err)
}
if err := m.validateVMVersion(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *OffChainCallContract) validateAbiVersion(formats strfmt.Registry) error {
if swag.IsZero(m.AbiVersion) { // not required
return nil
}
if err := validate.MinimumInt("abi_version", "body", int64(*m.AbiVersion), 0, false); err != nil {
return err
}
if err := validate.MaximumInt("abi_version", "body", int64(*m.AbiVersion), 65535, false); err != nil {
return err
}
return nil
}
func (m *OffChainCallContract) validateAmount(formats strfmt.Registry) error {
if err := validate.Required("amount", "body", m.Amount); err != nil {
return err
}
return nil
}
func (m *OffChainCallContract) validateCallData(formats strfmt.Registry) error {
if err := m.CallData.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("call_data")
}
return err
}
return nil
}
func (m *OffChainCallContract) validateCaller(formats strfmt.Registry) error {
if err := m.Caller.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("caller")
}
return err
}
return nil
}
func (m *OffChainCallContract) validateContract(formats strfmt.Registry) error {
if err := m.Contract.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("contract")
}
return err
}
return nil
}
func (m *OffChainCallContract) validateGas(formats strfmt.Registry) error {
if err := validate.Required("gas", "body", m.Gas); err != nil {
return err
}
return nil
}
func (m *OffChainCallContract) validateGasPrice(formats strfmt.Registry) error {
if err := validate.Required("gas_price", "body", m.GasPrice); err != nil {
return err
}
return nil
}
func (m *OffChainCallContract) validateVMVersion(formats strfmt.Registry) error {
if swag.IsZero(m.VMVersion) { // not required
return nil
}
if err := validate.MinimumInt("vm_version", "body", int64(*m.VMVersion), 0, false); err != nil {
return err
}
if err := validate.MaximumInt("vm_version", "body", int64(*m.VMVersion), 65535, false); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *OffChainCallContract) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *OffChainCallContract) UnmarshalBinary(b []byte) error {
var res OffChainCallContract
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}