github.com/agwab/go-ethereum@v1.9.7/tests/gen_difficultytest.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/ethereum/go-ethereum/common"
    10  	"github.com/ethereum/go-ethereum/common/math"
    11  )
    12  
    13  var _ = (*difficultyTestMarshaling)(nil)
    14  
    15  // MarshalJSON marshals as JSON.
    16  func (d DifficultyTest) MarshalJSON() ([]byte, error) {
    17  	type DifficultyTest struct {
    18  		ParentTimestamp    math.HexOrDecimal64   `json:"parentTimestamp"`
    19  		ParentDifficulty   *math.HexOrDecimal256 `json:"parentDifficulty"`
    20  		UncleHash          common.Hash           `json:"parentUncles"`
    21  		CurrentTimestamp   math.HexOrDecimal64   `json:"currentTimestamp"`
    22  		CurrentBlockNumber math.HexOrDecimal64   `json:"currentBlockNumber"`
    23  		CurrentDifficulty  *math.HexOrDecimal256 `json:"currentDifficulty"`
    24  	}
    25  	var enc DifficultyTest
    26  	enc.ParentTimestamp = math.HexOrDecimal64(d.ParentTimestamp)
    27  	enc.ParentDifficulty = (*math.HexOrDecimal256)(d.ParentDifficulty)
    28  	enc.UncleHash = d.UncleHash
    29  	enc.CurrentTimestamp = math.HexOrDecimal64(d.CurrentTimestamp)
    30  	enc.CurrentBlockNumber = math.HexOrDecimal64(d.CurrentBlockNumber)
    31  	enc.CurrentDifficulty = (*math.HexOrDecimal256)(d.CurrentDifficulty)
    32  	return json.Marshal(&enc)
    33  }
    34  
    35  // UnmarshalJSON unmarshals from JSON.
    36  func (d *DifficultyTest) UnmarshalJSON(input []byte) error {
    37  	type DifficultyTest struct {
    38  		ParentTimestamp    *math.HexOrDecimal64  `json:"parentTimestamp"`
    39  		ParentDifficulty   *math.HexOrDecimal256 `json:"parentDifficulty"`
    40  		UncleHash          *common.Hash          `json:"parentUncles"`
    41  		CurrentTimestamp   *math.HexOrDecimal64  `json:"currentTimestamp"`
    42  		CurrentBlockNumber *math.HexOrDecimal64  `json:"currentBlockNumber"`
    43  		CurrentDifficulty  *math.HexOrDecimal256 `json:"currentDifficulty"`
    44  	}
    45  	var dec DifficultyTest
    46  	if err := json.Unmarshal(input, &dec); err != nil {
    47  		return err
    48  	}
    49  	if dec.ParentTimestamp != nil {
    50  		d.ParentTimestamp = uint64(*dec.ParentTimestamp)
    51  	}
    52  	if dec.ParentDifficulty != nil {
    53  		d.ParentDifficulty = (*big.Int)(dec.ParentDifficulty)
    54  	}
    55  	if dec.UncleHash != nil {
    56  		d.UncleHash = *dec.UncleHash
    57  	}
    58  	if dec.CurrentTimestamp != nil {
    59  		d.CurrentTimestamp = uint64(*dec.CurrentTimestamp)
    60  	}
    61  	if dec.CurrentBlockNumber != nil {
    62  		d.CurrentBlockNumber = uint64(*dec.CurrentBlockNumber)
    63  	}
    64  	if dec.CurrentDifficulty != nil {
    65  		d.CurrentDifficulty = (*big.Int)(dec.CurrentDifficulty)
    66  	}
    67  	return nil
    68  }