github.com/aeternity/aepp-sdk-go/v4@v4.0.1/swagguard/node/models/off_chain_update.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  // OffChainUpdate off chain update
    22  // swagger:discriminator OffChainUpdate op
    23  type OffChainUpdate interface {
    24  	runtime.Validatable
    25  
    26  	// op
    27  	// Required: true
    28  	Op() string
    29  	SetOp(string)
    30  }
    31  
    32  type offChainUpdate struct {
    33  	opField string
    34  }
    35  
    36  // Op gets the op of this polymorphic type
    37  func (m *offChainUpdate) Op() string {
    38  	return "OffChainUpdate"
    39  }
    40  
    41  // SetOp sets the op of this polymorphic type
    42  func (m *offChainUpdate) SetOp(val string) {
    43  
    44  }
    45  
    46  // UnmarshalOffChainUpdateSlice unmarshals polymorphic slices of OffChainUpdate
    47  func UnmarshalOffChainUpdateSlice(reader io.Reader, consumer runtime.Consumer) ([]OffChainUpdate, error) {
    48  	var elements []json.RawMessage
    49  	if err := consumer.Consume(reader, &elements); err != nil {
    50  		return nil, err
    51  	}
    52  
    53  	var result []OffChainUpdate
    54  	for _, element := range elements {
    55  		obj, err := unmarshalOffChainUpdate(element, consumer)
    56  		if err != nil {
    57  			return nil, err
    58  		}
    59  		result = append(result, obj)
    60  	}
    61  	return result, nil
    62  }
    63  
    64  // UnmarshalOffChainUpdate unmarshals polymorphic OffChainUpdate
    65  func UnmarshalOffChainUpdate(reader io.Reader, consumer runtime.Consumer) (OffChainUpdate, error) {
    66  	// we need to read this twice, so first into a buffer
    67  	data, err := ioutil.ReadAll(reader)
    68  	if err != nil {
    69  		return nil, err
    70  	}
    71  	return unmarshalOffChainUpdate(data, consumer)
    72  }
    73  
    74  func unmarshalOffChainUpdate(data []byte, consumer runtime.Consumer) (OffChainUpdate, error) {
    75  	buf := bytes.NewBuffer(data)
    76  	buf2 := bytes.NewBuffer(data)
    77  
    78  	// the first time this is read is to fetch the value of the op property.
    79  	var getType struct {
    80  		Op string `json:"op"`
    81  	}
    82  	if err := consumer.Consume(buf, &getType); err != nil {
    83  		return nil, err
    84  	}
    85  
    86  	if err := validate.RequiredString("op", "body", getType.Op); err != nil {
    87  		return nil, err
    88  	}
    89  
    90  	// The value of op is used to determine which type to create and unmarshal the data into
    91  	switch getType.Op {
    92  	case "OffChainCallContract":
    93  		var result OffChainCallContract
    94  		if err := consumer.Consume(buf2, &result); err != nil {
    95  			return nil, err
    96  		}
    97  		return &result, nil
    98  
    99  	case "OffChainDeposit":
   100  		var result OffChainDeposit
   101  		if err := consumer.Consume(buf2, &result); err != nil {
   102  			return nil, err
   103  		}
   104  		return &result, nil
   105  
   106  	case "OffChainNewContract":
   107  		var result OffChainNewContract
   108  		if err := consumer.Consume(buf2, &result); err != nil {
   109  			return nil, err
   110  		}
   111  		return &result, nil
   112  
   113  	case "OffChainTransfer":
   114  		var result OffChainTransfer
   115  		if err := consumer.Consume(buf2, &result); err != nil {
   116  			return nil, err
   117  		}
   118  		return &result, nil
   119  
   120  	case "OffChainUpdate":
   121  		var result offChainUpdate
   122  		if err := consumer.Consume(buf2, &result); err != nil {
   123  			return nil, err
   124  		}
   125  		return &result, nil
   126  
   127  	case "OffChainWithdrawal":
   128  		var result OffChainWithdrawal
   129  		if err := consumer.Consume(buf2, &result); err != nil {
   130  			return nil, err
   131  		}
   132  		return &result, nil
   133  
   134  	}
   135  	return nil, errors.New(422, "invalid op value: %q", getType.Op)
   136  
   137  }
   138  
   139  // Validate validates this off chain update
   140  func (m *offChainUpdate) Validate(formats strfmt.Registry) error {
   141  	return nil
   142  }