github.com/core-coin/go-core/v2@v2.1.9/tests/gen_sttransaction.go (about)

     1  // Code generated by github.com/fjl/gencodec. DO NOT EDIT.
     2  
     3  package tests
     4  
     5  import (
     6  	"encoding/json"
     7  	"math/big"
     8  
     9  	"github.com/core-coin/go-core/v2/common/hexutil"
    10  	"github.com/core-coin/go-core/v2/common/math"
    11  )
    12  
    13  var _ = (*stTransactionMarshaling)(nil)
    14  
    15  // MarshalJSON marshals as JSON.
    16  func (s stTransaction) MarshalJSON() ([]byte, error) {
    17  	type stTransaction struct {
    18  		EnergyPrice *math.HexOrDecimal256 `json:"energyPrice"`
    19  		Nonce       math.HexOrDecimal64   `json:"nonce"`
    20  		To          string                `json:"to"`
    21  		Data        []string              `json:"data"`
    22  		EnergyLimit []math.HexOrDecimal64 `json:"energyLimit"`
    23  		Value       []string              `json:"value"`
    24  		PrivateKey  hexutil.Bytes         `json:"secretKey"`
    25  	}
    26  	var enc stTransaction
    27  	enc.EnergyPrice = (*math.HexOrDecimal256)(s.EnergyPrice)
    28  	enc.Nonce = math.HexOrDecimal64(s.Nonce)
    29  	enc.To = s.To
    30  	enc.Data = s.Data
    31  	if s.EnergyLimit != nil {
    32  		enc.EnergyLimit = make([]math.HexOrDecimal64, len(s.EnergyLimit))
    33  		for k, v := range s.EnergyLimit {
    34  			enc.EnergyLimit[k] = math.HexOrDecimal64(v)
    35  		}
    36  	}
    37  	enc.Value = s.Value
    38  	enc.PrivateKey = s.PrivateKey
    39  	return json.Marshal(&enc)
    40  }
    41  
    42  // UnmarshalJSON unmarshals from JSON.
    43  func (s *stTransaction) UnmarshalJSON(input []byte) error {
    44  	type stTransaction struct {
    45  		EnergyPrice *math.HexOrDecimal256 `json:"energyPrice"`
    46  		Nonce       *math.HexOrDecimal64  `json:"nonce"`
    47  		To          *string               `json:"to"`
    48  		Data        []string              `json:"data"`
    49  		EnergyLimit []math.HexOrDecimal64 `json:"energyLimit"`
    50  		Value       []string              `json:"value"`
    51  		PrivateKey  *hexutil.Bytes        `json:"secretKey"`
    52  	}
    53  	var dec stTransaction
    54  	if err := json.Unmarshal(input, &dec); err != nil {
    55  		return err
    56  	}
    57  	if dec.EnergyPrice != nil {
    58  		s.EnergyPrice = (*big.Int)(dec.EnergyPrice)
    59  	}
    60  	if dec.Nonce != nil {
    61  		s.Nonce = uint64(*dec.Nonce)
    62  	}
    63  	if dec.To != nil {
    64  		s.To = *dec.To
    65  	}
    66  	if dec.Data != nil {
    67  		s.Data = dec.Data
    68  	}
    69  	if dec.EnergyLimit != nil {
    70  		s.EnergyLimit = make([]uint64, len(dec.EnergyLimit))
    71  		for k, v := range dec.EnergyLimit {
    72  			s.EnergyLimit[k] = uint64(v)
    73  		}
    74  	}
    75  	if dec.Value != nil {
    76  		s.Value = dec.Value
    77  	}
    78  	if dec.PrivateKey != nil {
    79  		s.PrivateKey = *dec.PrivateKey
    80  	}
    81  	return nil
    82  }