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