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