github.com/aeternity/aepp-sdk-go@v1.0.3-0.20190606142815-1c0ffdc21fd9/generated/models/off_chain_withdrawal.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 17 utils "github.com/aeternity/aepp-sdk-go/utils" 18 ) 19 20 // OffChainWithdrawal off chain withdrawal 21 // swagger:model OffChainWithdrawal 22 type OffChainWithdrawal struct { 23 24 // amount 25 // Required: true 26 Amount utils.BigInt `json:"amount"` 27 28 // Withdrawer of tokens 29 // Required: true 30 To EncodedPubkey `json:"to"` 31 } 32 33 // Op gets the op of this subtype 34 func (m *OffChainWithdrawal) Op() string { 35 return "OffChainWithdrawal" 36 } 37 38 // SetOp sets the op of this subtype 39 func (m *OffChainWithdrawal) SetOp(val string) { 40 41 } 42 43 // Amount gets the amount of this subtype 44 45 // To gets the to of this subtype 46 47 // UnmarshalJSON unmarshals this object with a polymorphic type from a JSON structure 48 func (m *OffChainWithdrawal) UnmarshalJSON(raw []byte) error { 49 var data struct { 50 51 // amount 52 // Required: true 53 Amount utils.BigInt `json:"amount"` 54 55 // Withdrawer of tokens 56 // Required: true 57 To EncodedPubkey `json:"to"` 58 } 59 buf := bytes.NewBuffer(raw) 60 dec := json.NewDecoder(buf) 61 dec.UseNumber() 62 63 if err := dec.Decode(&data); err != nil { 64 return err 65 } 66 67 var base struct { 68 /* Just the base type fields. Used for unmashalling polymorphic types.*/ 69 70 Op string `json:"op"` 71 } 72 buf = bytes.NewBuffer(raw) 73 dec = json.NewDecoder(buf) 74 dec.UseNumber() 75 76 if err := dec.Decode(&base); err != nil { 77 return err 78 } 79 80 var result OffChainWithdrawal 81 82 if base.Op != result.Op() { 83 /* Not the type we're looking for. */ 84 return errors.New(422, "invalid op value: %q", base.Op) 85 } 86 87 result.Amount = data.Amount 88 89 result.To = data.To 90 91 *m = result 92 93 return nil 94 } 95 96 // MarshalJSON marshals this object with a polymorphic type to a JSON structure 97 func (m OffChainWithdrawal) MarshalJSON() ([]byte, error) { 98 var b1, b2, b3 []byte 99 var err error 100 b1, err = json.Marshal(struct { 101 102 // amount 103 // Required: true 104 Amount utils.BigInt `json:"amount"` 105 106 // Withdrawer of tokens 107 // Required: true 108 To EncodedPubkey `json:"to"` 109 }{ 110 111 Amount: m.Amount, 112 113 To: m.To, 114 }, 115 ) 116 if err != nil { 117 return nil, err 118 } 119 b2, err = json.Marshal(struct { 120 Op string `json:"op"` 121 }{ 122 123 Op: m.Op(), 124 }, 125 ) 126 if err != nil { 127 return nil, err 128 } 129 130 return swag.ConcatJSON(b1, b2, b3), nil 131 } 132 133 // Validate validates this off chain withdrawal 134 func (m *OffChainWithdrawal) Validate(formats strfmt.Registry) error { 135 var res []error 136 137 if err := m.validateAmount(formats); err != nil { 138 res = append(res, err) 139 } 140 141 if err := m.validateTo(formats); err != nil { 142 res = append(res, err) 143 } 144 145 if len(res) > 0 { 146 return errors.CompositeValidationError(res...) 147 } 148 return nil 149 } 150 151 func (m *OffChainWithdrawal) validateAmount(formats strfmt.Registry) error { 152 153 if err := m.Amount.Validate(formats); err != nil { 154 if ve, ok := err.(*errors.Validation); ok { 155 return ve.ValidateName("amount") 156 } 157 return err 158 } 159 160 return nil 161 } 162 163 func (m *OffChainWithdrawal) validateTo(formats strfmt.Registry) error { 164 165 if err := m.To.Validate(formats); err != nil { 166 if ve, ok := err.(*errors.Validation); ok { 167 return ve.ValidateName("to") 168 } 169 return err 170 } 171 172 return nil 173 } 174 175 // MarshalBinary interface implementation 176 func (m *OffChainWithdrawal) MarshalBinary() ([]byte, error) { 177 if m == nil { 178 return nil, nil 179 } 180 return swag.WriteJSON(m) 181 } 182 183 // UnmarshalBinary interface implementation 184 func (m *OffChainWithdrawal) UnmarshalBinary(b []byte) error { 185 var res OffChainWithdrawal 186 if err := swag.ReadJSON(b, &res); err != nil { 187 return err 188 } 189 *m = res 190 return nil 191 }