github.com/ethereum/go-ethereum@v1.14.3/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/core/types"
    14  	"github.com/ethereum/go-ethereum/params"
    15  )
    16  
    17  var _ = (*genesisSpecMarshaling)(nil)
    18  
    19  // MarshalJSON marshals as JSON.
    20  func (g Genesis) MarshalJSON() ([]byte, error) {
    21  	type Genesis struct {
    22  		Config        *params.ChainConfig                        `json:"config"`
    23  		Nonce         math.HexOrDecimal64                        `json:"nonce"`
    24  		Timestamp     math.HexOrDecimal64                        `json:"timestamp"`
    25  		ExtraData     hexutil.Bytes                              `json:"extraData"`
    26  		GasLimit      math.HexOrDecimal64                        `json:"gasLimit"   gencodec:"required"`
    27  		Difficulty    *math.HexOrDecimal256                      `json:"difficulty" gencodec:"required"`
    28  		Mixhash       common.Hash                                `json:"mixHash"`
    29  		Coinbase      common.Address                             `json:"coinbase"`
    30  		Alloc         map[common.UnprefixedAddress]types.Account `json:"alloc"      gencodec:"required"`
    31  		Number        math.HexOrDecimal64                        `json:"number"`
    32  		GasUsed       math.HexOrDecimal64                        `json:"gasUsed"`
    33  		ParentHash    common.Hash                                `json:"parentHash"`
    34  		BaseFee       *math.HexOrDecimal256                      `json:"baseFeePerGas"`
    35  		ExcessBlobGas *math.HexOrDecimal64                       `json:"excessBlobGas"`
    36  		BlobGasUsed   *math.HexOrDecimal64                       `json:"blobGasUsed"`
    37  	}
    38  	var enc Genesis
    39  	enc.Config = g.Config
    40  	enc.Nonce = math.HexOrDecimal64(g.Nonce)
    41  	enc.Timestamp = math.HexOrDecimal64(g.Timestamp)
    42  	enc.ExtraData = g.ExtraData
    43  	enc.GasLimit = math.HexOrDecimal64(g.GasLimit)
    44  	enc.Difficulty = (*math.HexOrDecimal256)(g.Difficulty)
    45  	enc.Mixhash = g.Mixhash
    46  	enc.Coinbase = g.Coinbase
    47  	if g.Alloc != nil {
    48  		enc.Alloc = make(map[common.UnprefixedAddress]types.Account, len(g.Alloc))
    49  		for k, v := range g.Alloc {
    50  			enc.Alloc[common.UnprefixedAddress(k)] = v
    51  		}
    52  	}
    53  	enc.Number = math.HexOrDecimal64(g.Number)
    54  	enc.GasUsed = math.HexOrDecimal64(g.GasUsed)
    55  	enc.ParentHash = g.ParentHash
    56  	enc.BaseFee = (*math.HexOrDecimal256)(g.BaseFee)
    57  	enc.ExcessBlobGas = (*math.HexOrDecimal64)(g.ExcessBlobGas)
    58  	enc.BlobGasUsed = (*math.HexOrDecimal64)(g.BlobGasUsed)
    59  	return json.Marshal(&enc)
    60  }
    61  
    62  // UnmarshalJSON unmarshals from JSON.
    63  func (g *Genesis) UnmarshalJSON(input []byte) error {
    64  	type Genesis struct {
    65  		Config        *params.ChainConfig                        `json:"config"`
    66  		Nonce         *math.HexOrDecimal64                       `json:"nonce"`
    67  		Timestamp     *math.HexOrDecimal64                       `json:"timestamp"`
    68  		ExtraData     *hexutil.Bytes                             `json:"extraData"`
    69  		GasLimit      *math.HexOrDecimal64                       `json:"gasLimit"   gencodec:"required"`
    70  		Difficulty    *math.HexOrDecimal256                      `json:"difficulty" gencodec:"required"`
    71  		Mixhash       *common.Hash                               `json:"mixHash"`
    72  		Coinbase      *common.Address                            `json:"coinbase"`
    73  		Alloc         map[common.UnprefixedAddress]types.Account `json:"alloc"      gencodec:"required"`
    74  		Number        *math.HexOrDecimal64                       `json:"number"`
    75  		GasUsed       *math.HexOrDecimal64                       `json:"gasUsed"`
    76  		ParentHash    *common.Hash                               `json:"parentHash"`
    77  		BaseFee       *math.HexOrDecimal256                      `json:"baseFeePerGas"`
    78  		ExcessBlobGas *math.HexOrDecimal64                       `json:"excessBlobGas"`
    79  		BlobGasUsed   *math.HexOrDecimal64                       `json:"blobGasUsed"`
    80  	}
    81  	var dec Genesis
    82  	if err := json.Unmarshal(input, &dec); err != nil {
    83  		return err
    84  	}
    85  	if dec.Config != nil {
    86  		g.Config = dec.Config
    87  	}
    88  	if dec.Nonce != nil {
    89  		g.Nonce = uint64(*dec.Nonce)
    90  	}
    91  	if dec.Timestamp != nil {
    92  		g.Timestamp = uint64(*dec.Timestamp)
    93  	}
    94  	if dec.ExtraData != nil {
    95  		g.ExtraData = *dec.ExtraData
    96  	}
    97  	if dec.GasLimit == nil {
    98  		return errors.New("missing required field 'gasLimit' for Genesis")
    99  	}
   100  	g.GasLimit = uint64(*dec.GasLimit)
   101  	if dec.Difficulty == nil {
   102  		return errors.New("missing required field 'difficulty' for Genesis")
   103  	}
   104  	g.Difficulty = (*big.Int)(dec.Difficulty)
   105  	if dec.Mixhash != nil {
   106  		g.Mixhash = *dec.Mixhash
   107  	}
   108  	if dec.Coinbase != nil {
   109  		g.Coinbase = *dec.Coinbase
   110  	}
   111  	if dec.Alloc == nil {
   112  		return errors.New("missing required field 'alloc' for Genesis")
   113  	}
   114  	g.Alloc = make(types.GenesisAlloc, len(dec.Alloc))
   115  	for k, v := range dec.Alloc {
   116  		g.Alloc[common.Address(k)] = v
   117  	}
   118  	if dec.Number != nil {
   119  		g.Number = uint64(*dec.Number)
   120  	}
   121  	if dec.GasUsed != nil {
   122  		g.GasUsed = uint64(*dec.GasUsed)
   123  	}
   124  	if dec.ParentHash != nil {
   125  		g.ParentHash = *dec.ParentHash
   126  	}
   127  	if dec.BaseFee != nil {
   128  		g.BaseFee = (*big.Int)(dec.BaseFee)
   129  	}
   130  	if dec.ExcessBlobGas != nil {
   131  		g.ExcessBlobGas = (*uint64)(dec.ExcessBlobGas)
   132  	}
   133  	if dec.BlobGasUsed != nil {
   134  		g.BlobGasUsed = (*uint64)(dec.BlobGasUsed)
   135  	}
   136  	return nil
   137  }