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