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