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