github.com/aeternity/aepp-sdk-go/v4@v4.0.1/swagguard/node/models/generic_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  	"io/ioutil"
    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/validate"
    19  )
    20  
    21  // GenericTx generic tx
    22  // swagger:discriminator GenericTx type
    23  type GenericTx interface {
    24  	runtime.Validatable
    25  
    26  	// type
    27  	// Required: true
    28  	Type() string
    29  	SetType(string)
    30  
    31  	// version
    32  	// Required: true
    33  	Version() *uint32
    34  	SetVersion(*uint32)
    35  }
    36  
    37  type genericTx struct {
    38  	typeField string
    39  
    40  	versionField *uint32
    41  }
    42  
    43  // Type gets the type of this polymorphic type
    44  func (m *genericTx) Type() string {
    45  	return "GenericTx"
    46  }
    47  
    48  // SetType sets the type of this polymorphic type
    49  func (m *genericTx) SetType(val string) {
    50  
    51  }
    52  
    53  // Version gets the version of this polymorphic type
    54  func (m *genericTx) Version() *uint32 {
    55  	return m.versionField
    56  }
    57  
    58  // SetVersion sets the version of this polymorphic type
    59  func (m *genericTx) SetVersion(val *uint32) {
    60  	m.versionField = val
    61  }
    62  
    63  // UnmarshalGenericTxSlice unmarshals polymorphic slices of GenericTx
    64  func UnmarshalGenericTxSlice(reader io.Reader, consumer runtime.Consumer) ([]GenericTx, error) {
    65  	var elements []json.RawMessage
    66  	if err := consumer.Consume(reader, &elements); err != nil {
    67  		return nil, err
    68  	}
    69  
    70  	var result []GenericTx
    71  	for _, element := range elements {
    72  		obj, err := unmarshalGenericTx(element, consumer)
    73  		if err != nil {
    74  			return nil, err
    75  		}
    76  		result = append(result, obj)
    77  	}
    78  	return result, nil
    79  }
    80  
    81  // UnmarshalGenericTx unmarshals polymorphic GenericTx
    82  func UnmarshalGenericTx(reader io.Reader, consumer runtime.Consumer) (GenericTx, error) {
    83  	// we need to read this twice, so first into a buffer
    84  	data, err := ioutil.ReadAll(reader)
    85  	if err != nil {
    86  		return nil, err
    87  	}
    88  	return unmarshalGenericTx(data, consumer)
    89  }
    90  
    91  func unmarshalGenericTx(data []byte, consumer runtime.Consumer) (GenericTx, error) {
    92  	buf := bytes.NewBuffer(data)
    93  	buf2 := bytes.NewBuffer(data)
    94  
    95  	// the first time this is read is to fetch the value of the type property.
    96  	var getType struct {
    97  		Type string `json:"type"`
    98  	}
    99  	if err := consumer.Consume(buf, &getType); err != nil {
   100  		return nil, err
   101  	}
   102  
   103  	if err := validate.RequiredString("type", "body", getType.Type); err != nil {
   104  		return nil, err
   105  	}
   106  
   107  	// The value of type is used to determine which type to create and unmarshal the data into
   108  	switch getType.Type {
   109  	case "ChannelCloseMutualTxJSON", "ChannelCloseMutualTx":
   110  		var result ChannelCloseMutualTxJSON
   111  		if err := consumer.Consume(buf2, &result); err != nil {
   112  			return nil, err
   113  		}
   114  		return &result, nil
   115  
   116  	case "ChannelCloseSoloTxJSON", "ChannelCloseSoloTx":
   117  		var result ChannelCloseSoloTxJSON
   118  		if err := consumer.Consume(buf2, &result); err != nil {
   119  			return nil, err
   120  		}
   121  		return &result, nil
   122  
   123  	case "ChannelCreateTxJSON", "ChannelCreateTx":
   124  		var result ChannelCreateTxJSON
   125  		if err := consumer.Consume(buf2, &result); err != nil {
   126  			return nil, err
   127  		}
   128  		return &result, nil
   129  
   130  	case "ChannelDepositTxJSON", "ChannelDepositTx":
   131  		var result ChannelDepositTxJSON
   132  		if err := consumer.Consume(buf2, &result); err != nil {
   133  			return nil, err
   134  		}
   135  		return &result, nil
   136  
   137  	case "ChannelForceProgressTxJSON", "ChannelForceProgressTx":
   138  		var result ChannelForceProgressTxJSON
   139  		if err := consumer.Consume(buf2, &result); err != nil {
   140  			return nil, err
   141  		}
   142  		return &result, nil
   143  
   144  	case "ChannelSettleTxJSON", "ChannelSettleTx":
   145  		var result ChannelSettleTxJSON
   146  		if err := consumer.Consume(buf2, &result); err != nil {
   147  			return nil, err
   148  		}
   149  		return &result, nil
   150  
   151  	case "ChannelSlashTxJSON", "ChannelSlashTx":
   152  		var result ChannelSLASHTxJSON
   153  		if err := consumer.Consume(buf2, &result); err != nil {
   154  			return nil, err
   155  		}
   156  		return &result, nil
   157  
   158  	case "ChannelSnapshotSoloTxJSON", "ChannelSnapshotSoloTx":
   159  		var result ChannelSnapshotSoloTxJSON
   160  		if err := consumer.Consume(buf2, &result); err != nil {
   161  			return nil, err
   162  		}
   163  		return &result, nil
   164  
   165  	case "ChannelWithdrawalTxJSON", "ChannelWithdrawalTx":
   166  		var result ChannelWithdrawalTxJSON
   167  		if err := consumer.Consume(buf2, &result); err != nil {
   168  			return nil, err
   169  		}
   170  		return &result, nil
   171  
   172  	case "ContractCallTxJSON", "ContractCallTx":
   173  		var result ContractCallTxJSON
   174  		if err := consumer.Consume(buf2, &result); err != nil {
   175  			return nil, err
   176  		}
   177  		return &result, nil
   178  
   179  	case "ContractCreateTxJSON", "ContractCreateTx":
   180  		var result ContractCreateTxJSON
   181  		if err := consumer.Consume(buf2, &result); err != nil {
   182  			return nil, err
   183  		}
   184  		return &result, nil
   185  
   186  	case "GenericTx":
   187  		var result genericTx
   188  		if err := consumer.Consume(buf2, &result); err != nil {
   189  			return nil, err
   190  		}
   191  		return &result, nil
   192  
   193  	case "NameClaimTxJSON", "NameClaimTx":
   194  		var result NameClaimTxJSON
   195  		if err := consumer.Consume(buf2, &result); err != nil {
   196  			return nil, err
   197  		}
   198  		return &result, nil
   199  
   200  	case "NamePreclaimTxJSON", "NamePreclaimTx":
   201  		var result NamePreclaimTxJSON
   202  		if err := consumer.Consume(buf2, &result); err != nil {
   203  			return nil, err
   204  		}
   205  		return &result, nil
   206  
   207  	case "NameRevokeTxJSON", "NameRevokeTx":
   208  		var result NameRevokeTxJSON
   209  		if err := consumer.Consume(buf2, &result); err != nil {
   210  			return nil, err
   211  		}
   212  		return &result, nil
   213  
   214  	case "NameTransferTxJSON", "NameTransferTx":
   215  		var result NameTransferTxJSON
   216  		if err := consumer.Consume(buf2, &result); err != nil {
   217  			return nil, err
   218  		}
   219  		return &result, nil
   220  
   221  	case "NameUpdateTxJSON", "NameUpdateTx":
   222  		var result NameUpdateTxJSON
   223  		if err := consumer.Consume(buf2, &result); err != nil {
   224  			return nil, err
   225  		}
   226  		return &result, nil
   227  
   228  	case "OracleExtendTxJSON", "OracleExtendTx":
   229  		var result OracleExtendTxJSON
   230  		if err := consumer.Consume(buf2, &result); err != nil {
   231  			return nil, err
   232  		}
   233  		return &result, nil
   234  
   235  	case "OracleQueryTxJSON", "OracleQueryTx":
   236  		var result OracleQueryTxJSON
   237  		if err := consumer.Consume(buf2, &result); err != nil {
   238  			return nil, err
   239  		}
   240  		return &result, nil
   241  
   242  	case "OracleRegisterTxJSON", "OracleRegisterTx":
   243  		var result OracleRegisterTxJSON
   244  		if err := consumer.Consume(buf2, &result); err != nil {
   245  			return nil, err
   246  		}
   247  		return &result, nil
   248  
   249  	case "OracleResponseTxJSON", "OracleResponseTx":
   250  		var result OracleResponseTxJSON
   251  		if err := consumer.Consume(buf2, &result); err != nil {
   252  			return nil, err
   253  		}
   254  		return &result, nil
   255  
   256  	case "SpendTxJSON", "SpendTx":
   257  		var result SpendTxJSON
   258  		if err := consumer.Consume(buf2, &result); err != nil {
   259  			return nil, err
   260  		}
   261  		return &result, nil
   262  
   263  	}
   264  	return nil, errors.New(422, "invalid type value: %q", getType.Type)
   265  
   266  }
   267  
   268  // Validate validates this generic tx
   269  func (m *genericTx) Validate(formats strfmt.Registry) error {
   270  	var res []error
   271  
   272  	if err := m.validateVersion(formats); err != nil {
   273  		res = append(res, err)
   274  	}
   275  
   276  	if len(res) > 0 {
   277  		return errors.CompositeValidationError(res...)
   278  	}
   279  	return nil
   280  }
   281  
   282  func (m *genericTx) validateVersion(formats strfmt.Registry) error {
   283  
   284  	if err := validate.Required("version", "body", m.Version()); err != nil {
   285  		return err
   286  	}
   287  
   288  	return nil
   289  }