github.com/aeternity/aepp-sdk-go@v1.0.3-0.20190606142815-1c0ffdc21fd9/generated/models/off_chain_new_contract.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package models 4 5 // This file was generated by the swagger tool. 6 // Editing this file might prove futile when you re-run the swagger generate command 7 8 import ( 9 "bytes" 10 "encoding/json" 11 12 strfmt "github.com/go-openapi/strfmt" 13 14 "github.com/go-openapi/errors" 15 "github.com/go-openapi/swag" 16 "github.com/go-openapi/validate" 17 18 utils "github.com/aeternity/aepp-sdk-go/utils" 19 ) 20 21 // OffChainNewContract off chain new contract 22 // swagger:model OffChainNewContract 23 type OffChainNewContract struct { 24 25 // abi version 26 // Required: true 27 AbiVersion Uint16 `json:"abi_version"` 28 29 // Contract call data 30 // Required: true 31 CallData EncodedByteArray `json:"call_data"` 32 33 // code 34 // Required: true 35 Code *ByteCode `json:"code"` 36 37 // deposit 38 // Required: true 39 Deposit utils.BigInt `json:"deposit"` 40 41 // Contract owner 42 // Required: true 43 Owner EncodedPubkey `json:"owner"` 44 45 // vm version 46 // Required: true 47 VMVersion Uint16 `json:"vm_version"` 48 } 49 50 // Op gets the op of this subtype 51 func (m *OffChainNewContract) Op() string { 52 return "OffChainNewContract" 53 } 54 55 // SetOp sets the op of this subtype 56 func (m *OffChainNewContract) SetOp(val string) { 57 58 } 59 60 // AbiVersion gets the abi version of this subtype 61 62 // CallData gets the call data of this subtype 63 64 // Code gets the code of this subtype 65 66 // Deposit gets the deposit of this subtype 67 68 // Owner gets the owner of this subtype 69 70 // VMVersion gets the vm version of this subtype 71 72 // UnmarshalJSON unmarshals this object with a polymorphic type from a JSON structure 73 func (m *OffChainNewContract) UnmarshalJSON(raw []byte) error { 74 var data struct { 75 76 // abi version 77 // Required: true 78 AbiVersion Uint16 `json:"abi_version"` 79 80 // Contract call data 81 // Required: true 82 CallData EncodedByteArray `json:"call_data"` 83 84 // code 85 // Required: true 86 Code *ByteCode `json:"code"` 87 88 // deposit 89 // Required: true 90 Deposit utils.BigInt `json:"deposit"` 91 92 // Contract owner 93 // Required: true 94 Owner EncodedPubkey `json:"owner"` 95 96 // vm version 97 // Required: true 98 VMVersion Uint16 `json:"vm_version"` 99 } 100 buf := bytes.NewBuffer(raw) 101 dec := json.NewDecoder(buf) 102 dec.UseNumber() 103 104 if err := dec.Decode(&data); err != nil { 105 return err 106 } 107 108 var base struct { 109 /* Just the base type fields. Used for unmashalling polymorphic types.*/ 110 111 Op string `json:"op"` 112 } 113 buf = bytes.NewBuffer(raw) 114 dec = json.NewDecoder(buf) 115 dec.UseNumber() 116 117 if err := dec.Decode(&base); err != nil { 118 return err 119 } 120 121 var result OffChainNewContract 122 123 if base.Op != result.Op() { 124 /* Not the type we're looking for. */ 125 return errors.New(422, "invalid op value: %q", base.Op) 126 } 127 128 result.AbiVersion = data.AbiVersion 129 130 result.CallData = data.CallData 131 132 result.Code = data.Code 133 134 result.Deposit = data.Deposit 135 136 result.Owner = data.Owner 137 138 result.VMVersion = data.VMVersion 139 140 *m = result 141 142 return nil 143 } 144 145 // MarshalJSON marshals this object with a polymorphic type to a JSON structure 146 func (m OffChainNewContract) MarshalJSON() ([]byte, error) { 147 var b1, b2, b3 []byte 148 var err error 149 b1, err = json.Marshal(struct { 150 151 // abi version 152 // Required: true 153 AbiVersion Uint16 `json:"abi_version"` 154 155 // Contract call data 156 // Required: true 157 CallData EncodedByteArray `json:"call_data"` 158 159 // code 160 // Required: true 161 Code *ByteCode `json:"code"` 162 163 // deposit 164 // Required: true 165 Deposit utils.BigInt `json:"deposit"` 166 167 // Contract owner 168 // Required: true 169 Owner EncodedPubkey `json:"owner"` 170 171 // vm version 172 // Required: true 173 VMVersion Uint16 `json:"vm_version"` 174 }{ 175 176 AbiVersion: m.AbiVersion, 177 178 CallData: m.CallData, 179 180 Code: m.Code, 181 182 Deposit: m.Deposit, 183 184 Owner: m.Owner, 185 186 VMVersion: m.VMVersion, 187 }, 188 ) 189 if err != nil { 190 return nil, err 191 } 192 b2, err = json.Marshal(struct { 193 Op string `json:"op"` 194 }{ 195 196 Op: m.Op(), 197 }, 198 ) 199 if err != nil { 200 return nil, err 201 } 202 203 return swag.ConcatJSON(b1, b2, b3), nil 204 } 205 206 // Validate validates this off chain new contract 207 func (m *OffChainNewContract) Validate(formats strfmt.Registry) error { 208 var res []error 209 210 if err := m.validateAbiVersion(formats); err != nil { 211 res = append(res, err) 212 } 213 214 if err := m.validateCallData(formats); err != nil { 215 res = append(res, err) 216 } 217 218 if err := m.validateCode(formats); err != nil { 219 res = append(res, err) 220 } 221 222 if err := m.validateDeposit(formats); err != nil { 223 res = append(res, err) 224 } 225 226 if err := m.validateOwner(formats); err != nil { 227 res = append(res, err) 228 } 229 230 if err := m.validateVMVersion(formats); err != nil { 231 res = append(res, err) 232 } 233 234 if len(res) > 0 { 235 return errors.CompositeValidationError(res...) 236 } 237 return nil 238 } 239 240 func (m *OffChainNewContract) validateAbiVersion(formats strfmt.Registry) error { 241 242 if err := m.AbiVersion.Validate(formats); err != nil { 243 if ve, ok := err.(*errors.Validation); ok { 244 return ve.ValidateName("abi_version") 245 } 246 return err 247 } 248 249 return nil 250 } 251 252 func (m *OffChainNewContract) validateCallData(formats strfmt.Registry) error { 253 254 if err := m.CallData.Validate(formats); err != nil { 255 if ve, ok := err.(*errors.Validation); ok { 256 return ve.ValidateName("call_data") 257 } 258 return err 259 } 260 261 return nil 262 } 263 264 func (m *OffChainNewContract) validateCode(formats strfmt.Registry) error { 265 266 if err := validate.Required("code", "body", m.Code); err != nil { 267 return err 268 } 269 270 if m.Code != nil { 271 if err := m.Code.Validate(formats); err != nil { 272 if ve, ok := err.(*errors.Validation); ok { 273 return ve.ValidateName("code") 274 } 275 return err 276 } 277 } 278 279 return nil 280 } 281 282 func (m *OffChainNewContract) validateDeposit(formats strfmt.Registry) error { 283 284 if err := m.Deposit.Validate(formats); err != nil { 285 if ve, ok := err.(*errors.Validation); ok { 286 return ve.ValidateName("deposit") 287 } 288 return err 289 } 290 291 return nil 292 } 293 294 func (m *OffChainNewContract) validateOwner(formats strfmt.Registry) error { 295 296 if err := m.Owner.Validate(formats); err != nil { 297 if ve, ok := err.(*errors.Validation); ok { 298 return ve.ValidateName("owner") 299 } 300 return err 301 } 302 303 return nil 304 } 305 306 func (m *OffChainNewContract) validateVMVersion(formats strfmt.Registry) error { 307 308 if err := m.VMVersion.Validate(formats); err != nil { 309 if ve, ok := err.(*errors.Validation); ok { 310 return ve.ValidateName("vm_version") 311 } 312 return err 313 } 314 315 return nil 316 } 317 318 // MarshalBinary interface implementation 319 func (m *OffChainNewContract) MarshalBinary() ([]byte, error) { 320 if m == nil { 321 return nil, nil 322 } 323 return swag.WriteJSON(m) 324 } 325 326 // UnmarshalBinary interface implementation 327 func (m *OffChainNewContract) UnmarshalBinary(b []byte) error { 328 var res OffChainNewContract 329 if err := swag.ReadJSON(b, &res); err != nil { 330 return err 331 } 332 *m = res 333 return nil 334 }