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