github.com/aeternity/aepp-sdk-go@v1.0.3-0.20190606142815-1c0ffdc21fd9/generated/models/generic_signed_tx.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  	"io"
    12  	"strconv"
    13  
    14  	strfmt "github.com/go-openapi/strfmt"
    15  
    16  	"github.com/go-openapi/errors"
    17  	"github.com/go-openapi/runtime"
    18  	"github.com/go-openapi/swag"
    19  	"github.com/go-openapi/validate"
    20  
    21  	utils "github.com/aeternity/aepp-sdk-go/utils"
    22  )
    23  
    24  // GenericSignedTx generic signed tx
    25  // swagger:model GenericSignedTx
    26  type GenericSignedTx struct {
    27  
    28  	// Value "none" means no block in the chain includes the transaction
    29  	// Required: true
    30  	BlockHash EncodedHash `json:"block_hash"`
    31  
    32  	// block height
    33  	// Required: true
    34  	BlockHeight utils.BigInt `json:"block_height"`
    35  
    36  	// hash
    37  	// Required: true
    38  	Hash EncodedHash `json:"hash"`
    39  
    40  	// signatures required unless for Generalized Account Meta transactions
    41  	// Min Items: 1
    42  	Signatures []EncodedValue `json:"signatures"`
    43  
    44  	txField GenericTx
    45  }
    46  
    47  // Tx gets the tx of this base type
    48  func (m *GenericSignedTx) Tx() GenericTx {
    49  	return m.txField
    50  }
    51  
    52  // SetTx sets the tx of this base type
    53  func (m *GenericSignedTx) SetTx(val GenericTx) {
    54  	m.txField = val
    55  }
    56  
    57  // UnmarshalJSON unmarshals this object with a polymorphic type from a JSON structure
    58  func (m *GenericSignedTx) UnmarshalJSON(raw []byte) error {
    59  	var data struct {
    60  		BlockHash EncodedHash `json:"block_hash"`
    61  
    62  		BlockHeight utils.BigInt `json:"block_height"`
    63  
    64  		Hash EncodedHash `json:"hash"`
    65  
    66  		Signatures []EncodedValue `json:"signatures"`
    67  
    68  		Tx json.RawMessage `json:"tx"`
    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  	propTx, err := UnmarshalGenericTx(bytes.NewBuffer(data.Tx), runtime.JSONConsumer())
    79  	if err != nil && err != io.EOF {
    80  		return err
    81  	}
    82  
    83  	var result GenericSignedTx
    84  
    85  	// block_hash
    86  	result.BlockHash = data.BlockHash
    87  
    88  	// block_height
    89  	result.BlockHeight = data.BlockHeight
    90  
    91  	// hash
    92  	result.Hash = data.Hash
    93  
    94  	// signatures
    95  	result.Signatures = data.Signatures
    96  
    97  	// tx
    98  	result.txField = propTx
    99  
   100  	*m = result
   101  
   102  	return nil
   103  }
   104  
   105  // MarshalJSON marshals this object with a polymorphic type to a JSON structure
   106  func (m GenericSignedTx) MarshalJSON() ([]byte, error) {
   107  	var b1, b2, b3 []byte
   108  	var err error
   109  	b1, err = json.Marshal(struct {
   110  		BlockHash EncodedHash `json:"block_hash"`
   111  
   112  		BlockHeight utils.BigInt `json:"block_height"`
   113  
   114  		Hash EncodedHash `json:"hash"`
   115  
   116  		Signatures []EncodedValue `json:"signatures"`
   117  	}{
   118  
   119  		BlockHash: m.BlockHash,
   120  
   121  		BlockHeight: m.BlockHeight,
   122  
   123  		Hash: m.Hash,
   124  
   125  		Signatures: m.Signatures,
   126  	},
   127  	)
   128  	if err != nil {
   129  		return nil, err
   130  	}
   131  	b2, err = json.Marshal(struct {
   132  		Tx GenericTx `json:"tx"`
   133  	}{
   134  
   135  		Tx: m.txField,
   136  	},
   137  	)
   138  	if err != nil {
   139  		return nil, err
   140  	}
   141  
   142  	return swag.ConcatJSON(b1, b2, b3), nil
   143  }
   144  
   145  // Validate validates this generic signed tx
   146  func (m *GenericSignedTx) Validate(formats strfmt.Registry) error {
   147  	var res []error
   148  
   149  	if err := m.validateBlockHash(formats); err != nil {
   150  		res = append(res, err)
   151  	}
   152  
   153  	if err := m.validateBlockHeight(formats); err != nil {
   154  		res = append(res, err)
   155  	}
   156  
   157  	if err := m.validateHash(formats); err != nil {
   158  		res = append(res, err)
   159  	}
   160  
   161  	if err := m.validateSignatures(formats); err != nil {
   162  		res = append(res, err)
   163  	}
   164  
   165  	if err := m.validateTx(formats); err != nil {
   166  		res = append(res, err)
   167  	}
   168  
   169  	if len(res) > 0 {
   170  		return errors.CompositeValidationError(res...)
   171  	}
   172  	return nil
   173  }
   174  
   175  func (m *GenericSignedTx) validateBlockHash(formats strfmt.Registry) error {
   176  
   177  	if err := m.BlockHash.Validate(formats); err != nil {
   178  		if ve, ok := err.(*errors.Validation); ok {
   179  			return ve.ValidateName("block_hash")
   180  		}
   181  		return err
   182  	}
   183  
   184  	return nil
   185  }
   186  
   187  func (m *GenericSignedTx) validateBlockHeight(formats strfmt.Registry) error {
   188  
   189  	if err := m.BlockHeight.Validate(formats); err != nil {
   190  		if ve, ok := err.(*errors.Validation); ok {
   191  			return ve.ValidateName("block_height")
   192  		}
   193  		return err
   194  	}
   195  
   196  	return nil
   197  }
   198  
   199  func (m *GenericSignedTx) validateHash(formats strfmt.Registry) error {
   200  
   201  	if err := m.Hash.Validate(formats); err != nil {
   202  		if ve, ok := err.(*errors.Validation); ok {
   203  			return ve.ValidateName("hash")
   204  		}
   205  		return err
   206  	}
   207  
   208  	return nil
   209  }
   210  
   211  func (m *GenericSignedTx) validateSignatures(formats strfmt.Registry) error {
   212  
   213  	if swag.IsZero(m.Signatures) { // not required
   214  		return nil
   215  	}
   216  
   217  	iSignaturesSize := int64(len(m.Signatures))
   218  
   219  	if err := validate.MinItems("signatures", "body", iSignaturesSize, 1); err != nil {
   220  		return err
   221  	}
   222  
   223  	for i := 0; i < len(m.Signatures); i++ {
   224  
   225  		if err := m.Signatures[i].Validate(formats); err != nil {
   226  			if ve, ok := err.(*errors.Validation); ok {
   227  				return ve.ValidateName("signatures" + "." + strconv.Itoa(i))
   228  			}
   229  			return err
   230  		}
   231  
   232  	}
   233  
   234  	return nil
   235  }
   236  
   237  func (m *GenericSignedTx) validateTx(formats strfmt.Registry) error {
   238  
   239  	if err := m.Tx().Validate(formats); err != nil {
   240  		if ve, ok := err.(*errors.Validation); ok {
   241  			return ve.ValidateName("tx")
   242  		}
   243  		return err
   244  	}
   245  
   246  	return nil
   247  }
   248  
   249  // MarshalBinary interface implementation
   250  func (m *GenericSignedTx) MarshalBinary() ([]byte, error) {
   251  	if m == nil {
   252  		return nil, nil
   253  	}
   254  	return swag.WriteJSON(m)
   255  }
   256  
   257  // UnmarshalBinary interface implementation
   258  func (m *GenericSignedTx) UnmarshalBinary(b []byte) error {
   259  	var res GenericSignedTx
   260  	if err := swag.ReadJSON(b, &res); err != nil {
   261  		return err
   262  	}
   263  	*m = res
   264  	return nil
   265  }