github.com/alanchchen/go-ethereum@v1.6.6-0.20170601190819-6171d01b1195/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/ethereum/go-ethereum/common"
    11  	"github.com/ethereum/go-ethereum/common/hexutil"
    12  	"github.com/ethereum/go-ethereum/common/math"
    13  	"github.com/ethereum/go-ethereum/params"
    14  )
    15  
    16  func (g Genesis) MarshalJSON() ([]byte, error) {
    17  	type Genesis struct {
    18  		Config     *params.ChainConfig                         `json:"config"`
    19  		Nonce      math.HexOrDecimal64                         `json:"nonce"`
    20  		Timestamp  math.HexOrDecimal64                         `json:"timestamp"`
    21  		ParentHash common.Hash                                 `json:"parentHash"`
    22  		ExtraData  hexutil.Bytes                               `json:"extraData"`
    23  		GasLimit   math.HexOrDecimal64                         `json:"gasLimit"   gencodec:"required"`
    24  		Difficulty *math.HexOrDecimal256                       `json:"difficulty" gencodec:"required"`
    25  		Mixhash    common.Hash                                 `json:"mixHash"`
    26  		Coinbase   common.Address                              `json:"coinbase"`
    27  		Alloc      map[common.UnprefixedAddress]GenesisAccount `json:"alloc"      gencodec:"required"`
    28  	}
    29  	var enc Genesis
    30  	enc.Config = g.Config
    31  	enc.Nonce = math.HexOrDecimal64(g.Nonce)
    32  	enc.Timestamp = math.HexOrDecimal64(g.Timestamp)
    33  	enc.ParentHash = g.ParentHash
    34  	enc.ExtraData = g.ExtraData
    35  	enc.GasLimit = math.HexOrDecimal64(g.GasLimit)
    36  	enc.Difficulty = (*math.HexOrDecimal256)(g.Difficulty)
    37  	enc.Mixhash = g.Mixhash
    38  	enc.Coinbase = g.Coinbase
    39  	if g.Alloc != nil {
    40  		enc.Alloc = make(map[common.UnprefixedAddress]GenesisAccount, len(g.Alloc))
    41  		for k, v := range g.Alloc {
    42  			enc.Alloc[common.UnprefixedAddress(k)] = v
    43  		}
    44  	}
    45  	return json.Marshal(&enc)
    46  }
    47  
    48  func (g *Genesis) UnmarshalJSON(input []byte) error {
    49  	type Genesis struct {
    50  		Config     *params.ChainConfig                         `json:"config"`
    51  		Nonce      *math.HexOrDecimal64                        `json:"nonce"`
    52  		Timestamp  *math.HexOrDecimal64                        `json:"timestamp"`
    53  		ParentHash *common.Hash                                `json:"parentHash"`
    54  		ExtraData  hexutil.Bytes                               `json:"extraData"`
    55  		GasLimit   *math.HexOrDecimal64                        `json:"gasLimit"   gencodec:"required"`
    56  		Difficulty *math.HexOrDecimal256                       `json:"difficulty" gencodec:"required"`
    57  		Mixhash    *common.Hash                                `json:"mixHash"`
    58  		Coinbase   *common.Address                             `json:"coinbase"`
    59  		Alloc      map[common.UnprefixedAddress]GenesisAccount `json:"alloc"      gencodec:"required"`
    60  	}
    61  	var dec Genesis
    62  	if err := json.Unmarshal(input, &dec); err != nil {
    63  		return err
    64  	}
    65  	if dec.Config != nil {
    66  		g.Config = dec.Config
    67  	}
    68  	if dec.Nonce != nil {
    69  		g.Nonce = uint64(*dec.Nonce)
    70  	}
    71  	if dec.Timestamp != nil {
    72  		g.Timestamp = uint64(*dec.Timestamp)
    73  	}
    74  	if dec.ParentHash != nil {
    75  		g.ParentHash = *dec.ParentHash
    76  	}
    77  	if dec.ExtraData != nil {
    78  		g.ExtraData = dec.ExtraData
    79  	}
    80  	if dec.GasLimit == nil {
    81  		return errors.New("missing required field 'gasLimit' for Genesis")
    82  	}
    83  	g.GasLimit = uint64(*dec.GasLimit)
    84  	if dec.Difficulty == nil {
    85  		return errors.New("missing required field 'difficulty' for Genesis")
    86  	}
    87  	g.Difficulty = (*big.Int)(dec.Difficulty)
    88  	if dec.Mixhash != nil {
    89  		g.Mixhash = *dec.Mixhash
    90  	}
    91  	if dec.Coinbase != nil {
    92  		g.Coinbase = *dec.Coinbase
    93  	}
    94  	if dec.Alloc == nil {
    95  		return errors.New("missing required field 'alloc' for Genesis")
    96  	}
    97  	g.Alloc = make(GenesisAlloc, len(dec.Alloc))
    98  	for k, v := range dec.Alloc {
    99  		g.Alloc[common.Address(k)] = v
   100  	}
   101  	return nil
   102  }