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

     1  // Code generated by github.com/fjl/gencodec. DO NOT EDIT.
     2  
     3  package core
     4  
     5  import (
     6  	"encoding/json"
     7  	"errors"
     8  	"math/big"
     9  
    10  	"github.com/core-coin/go-core/v2/common"
    11  	"github.com/core-coin/go-core/v2/common/hexutil"
    12  	"github.com/core-coin/go-core/v2/common/math"
    13  	"github.com/core-coin/go-core/v2/params"
    14  )
    15  
    16  var _ = (*genesisSpecMarshaling)(nil)
    17  
    18  // MarshalJSON marshals as JSON.
    19  func (g Genesis) MarshalJSON() ([]byte, error) {
    20  	type Genesis struct {
    21  		Config      *params.ChainConfig                         `json:"config"`
    22  		Nonce       math.HexOrDecimal64                         `json:"nonce"`
    23  		Timestamp   math.HexOrDecimal64                         `json:"timestamp"`
    24  		ExtraData   hexutil.Bytes                               `json:"extraData"`
    25  		EnergyLimit math.HexOrDecimal64                         `json:"energyLimit"   gencodec:"required"`
    26  		Difficulty  *math.HexOrDecimal256                       `json:"difficulty" gencodec:"required"`
    27  		Coinbase    common.Address                              `json:"coinbase"`
    28  		Alloc       map[common.UnprefixedAddress]GenesisAccount `json:"alloc"      gencodec:"required"`
    29  		Number      math.HexOrDecimal64                         `json:"number"`
    30  		EnergyUsed  math.HexOrDecimal64                         `json:"energyUsed"`
    31  		ParentHash  common.Hash                                 `json:"parentHash"`
    32  	}
    33  	var enc Genesis
    34  	enc.Config = g.Config
    35  	enc.Nonce = math.HexOrDecimal64(g.Nonce)
    36  	enc.Timestamp = math.HexOrDecimal64(g.Timestamp)
    37  	enc.ExtraData = g.ExtraData
    38  	enc.EnergyLimit = math.HexOrDecimal64(g.EnergyLimit)
    39  	enc.Difficulty = (*math.HexOrDecimal256)(g.Difficulty)
    40  	enc.Coinbase = g.Coinbase
    41  	if g.Alloc != nil {
    42  		enc.Alloc = make(map[common.UnprefixedAddress]GenesisAccount, len(g.Alloc))
    43  		for k, v := range g.Alloc {
    44  			enc.Alloc[common.UnprefixedAddress(k)] = v
    45  		}
    46  	}
    47  	enc.Number = math.HexOrDecimal64(g.Number)
    48  	enc.EnergyUsed = math.HexOrDecimal64(g.EnergyUsed)
    49  	enc.ParentHash = g.ParentHash
    50  	return json.Marshal(&enc)
    51  }
    52  
    53  // UnmarshalJSON unmarshals from JSON.
    54  func (g *Genesis) UnmarshalJSON(input []byte) error {
    55  	type Genesis struct {
    56  		Config      *params.ChainConfig                         `json:"config"`
    57  		Nonce       *math.HexOrDecimal64                        `json:"nonce"`
    58  		Timestamp   *math.HexOrDecimal64                        `json:"timestamp"`
    59  		ExtraData   *hexutil.Bytes                              `json:"extraData"`
    60  		EnergyLimit *math.HexOrDecimal64                        `json:"energyLimit"   gencodec:"required"`
    61  		Difficulty  *math.HexOrDecimal256                       `json:"difficulty" gencodec:"required"`
    62  		Coinbase    *common.Address                             `json:"coinbase"`
    63  		Alloc       map[common.UnprefixedAddress]GenesisAccount `json:"alloc"      gencodec:"required"`
    64  		Number      *math.HexOrDecimal64                        `json:"number"`
    65  		EnergyUsed  *math.HexOrDecimal64                        `json:"energyUsed"`
    66  		ParentHash  *common.Hash                                `json:"parentHash"`
    67  	}
    68  	var dec Genesis
    69  	if err := json.Unmarshal(input, &dec); err != nil {
    70  		return err
    71  	}
    72  	if dec.Config != nil {
    73  		g.Config = dec.Config
    74  	}
    75  	if dec.Nonce != nil {
    76  		g.Nonce = uint64(*dec.Nonce)
    77  	}
    78  	if dec.Timestamp != nil {
    79  		g.Timestamp = uint64(*dec.Timestamp)
    80  	}
    81  	if dec.ExtraData != nil {
    82  		g.ExtraData = *dec.ExtraData
    83  	}
    84  	if dec.EnergyLimit == nil {
    85  		return errors.New("missing required field 'energyLimit' for Genesis")
    86  	}
    87  	g.EnergyLimit = uint64(*dec.EnergyLimit)
    88  	if dec.Difficulty == nil {
    89  		return errors.New("missing required field 'difficulty' for Genesis")
    90  	}
    91  	g.Difficulty = (*big.Int)(dec.Difficulty)
    92  	if dec.Coinbase != nil {
    93  		g.Coinbase = *dec.Coinbase
    94  	}
    95  	if dec.Alloc == nil {
    96  		return errors.New("missing required field 'alloc' for Genesis")
    97  	}
    98  	g.Alloc = make(GenesisAlloc, len(dec.Alloc))
    99  	for k, v := range dec.Alloc {
   100  		g.Alloc[common.Address(k)] = v
   101  	}
   102  	if dec.Number != nil {
   103  		g.Number = uint64(*dec.Number)
   104  	}
   105  	if dec.EnergyUsed != nil {
   106  		g.EnergyUsed = uint64(*dec.EnergyUsed)
   107  	}
   108  	if dec.ParentHash != nil {
   109  		g.ParentHash = *dec.ParentHash
   110  	}
   111  	return nil
   112  }