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