github.com/theQRL/go-zond@v0.2.1/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/theQRL/go-zond/common"
    11  	"github.com/theQRL/go-zond/common/hexutil"
    12  	"github.com/theQRL/go-zond/common/math"
    13  	"github.com/theQRL/go-zond/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  		Timestamp     math.HexOrDecimal64                         `json:"timestamp"`
    23  		ExtraData     hexutil.Bytes                               `json:"extraData"`
    24  		GasLimit      math.HexOrDecimal64                         `json:"gasLimit"   gencodec:"required"`
    25  		Mixhash       common.Hash                                 `json:"mixHash"`
    26  		Coinbase      common.Address                              `json:"coinbase"`
    27  		Alloc         map[common.Address]GenesisAccount `json:"alloc"      gencodec:"required"`
    28  		Number        math.HexOrDecimal64                         `json:"number"`
    29  		GasUsed       math.HexOrDecimal64                         `json:"gasUsed"`
    30  		ParentHash    common.Hash                                 `json:"parentHash"`
    31  		BaseFee       *math.HexOrDecimal256                       `json:"baseFeePerGas"`
    32  	}
    33  	var enc Genesis
    34  	enc.Config = g.Config
    35  	enc.Timestamp = math.HexOrDecimal64(g.Timestamp)
    36  	enc.ExtraData = g.ExtraData
    37  	enc.GasLimit = math.HexOrDecimal64(g.GasLimit)
    38  	enc.Mixhash = g.Mixhash
    39  	enc.Coinbase = g.Coinbase
    40  	if g.Alloc != nil {
    41  		enc.Alloc = make(map[common.Address]GenesisAccount, len(g.Alloc))
    42  		for k, v := range g.Alloc {
    43  			enc.Alloc[k] = v
    44  		}
    45  	}
    46  	enc.Number = math.HexOrDecimal64(g.Number)
    47  	enc.GasUsed = math.HexOrDecimal64(g.GasUsed)
    48  	enc.ParentHash = g.ParentHash
    49  	enc.BaseFee = (*math.HexOrDecimal256)(g.BaseFee)
    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  		Timestamp     *math.HexOrDecimal64                        `json:"timestamp"`
    58  		ExtraData     *hexutil.Bytes                              `json:"extraData"`
    59  		GasLimit      *math.HexOrDecimal64                        `json:"gasLimit"   gencodec:"required"`
    60  		Mixhash       *common.Hash                                `json:"mixHash"`
    61  		Coinbase      *common.Address                             `json:"coinbase"`
    62  		Alloc         map[common.Address]GenesisAccount `json:"alloc"      gencodec:"required"`
    63  		Number        *math.HexOrDecimal64                        `json:"number"`
    64  		GasUsed       *math.HexOrDecimal64                        `json:"gasUsed"`
    65  		ParentHash    *common.Hash                                `json:"parentHash"`
    66  		BaseFee       *math.HexOrDecimal256                       `json:"baseFeePerGas"`
    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.Timestamp != nil {
    76  		g.Timestamp = uint64(*dec.Timestamp)
    77  	}
    78  	if dec.ExtraData != nil {
    79  		g.ExtraData = *dec.ExtraData
    80  	}
    81  	if dec.GasLimit == nil {
    82  		return errors.New("missing required field 'gasLimit' for Genesis")
    83  	}
    84  	g.GasLimit = uint64(*dec.GasLimit)
    85  	if dec.Mixhash != nil {
    86  		g.Mixhash = *dec.Mixhash
    87  	}
    88  	if dec.Coinbase != nil {
    89  		g.Coinbase = *dec.Coinbase
    90  	}
    91  	if dec.Alloc == nil {
    92  		return errors.New("missing required field 'alloc' for Genesis")
    93  	}
    94  	g.Alloc = make(GenesisAlloc, len(dec.Alloc))
    95  	for k, v := range dec.Alloc {
    96  		g.Alloc[common.Address(k)] = v
    97  	}
    98  	if dec.Number != nil {
    99  		g.Number = uint64(*dec.Number)
   100  	}
   101  	if dec.GasUsed != nil {
   102  		g.GasUsed = uint64(*dec.GasUsed)
   103  	}
   104  	if dec.ParentHash != nil {
   105  		g.ParentHash = *dec.ParentHash
   106  	}
   107  	if dec.BaseFee != nil {
   108  		g.BaseFee = (*big.Int)(dec.BaseFee)
   109  	}
   110  	return nil
   111  }