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