github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/chain/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/neatio-net/neatio/params"
    11  	"github.com/neatio-net/neatio/utilities/common"
    12  	"github.com/neatio-net/neatio/utilities/common/hexutil"
    13  	"github.com/neatio-net/neatio/utilities/common/math"
    14  )
    15  
    16  var _ = (*genesisSpecMarshaling)(nil)
    17  
    18  func (g Genesis) MarshalJSON() ([]byte, error) {
    19  	type Genesis struct {
    20  		Config     *params.ChainConfig                         `json:"config"`
    21  		Nonce      math.HexOrDecimal64                         `json:"nonce"`
    22  		Timestamp  math.HexOrDecimal64                         `json:"timestamp"`
    23  		ExtraData  hexutil.Bytes                               `json:"extraData"`
    24  		GasLimit   math.HexOrDecimal64                         `json:"gasLimit"   gencodec:"required"`
    25  		Difficulty *math.HexOrDecimal256                       `json:"difficulty" gencodec:"required"`
    26  		Mixhash    common.Hash                                 `json:"mixHash"`
    27  		Coinbase   common.Address                              `json:"coinbase"`
    28  		Alloc      map[common.UnprefixedAddress]GenesisAccount `json:"alloc"      gencodec:"required"`
    29  		Number     math.HexOrDecimal64                         `json:"number"`
    30  		GasUsed    math.HexOrDecimal64                         `json:"gasUsed"`
    31  		ParentHash common.Hash                                 `json:"parentHash"`
    32  	}
    33  	var enc Genesis
    34  	enc.Config = g.Config
    35  	enc.Nonce = math.HexOrDecimal64(g.Nonce)
    36  	enc.Timestamp = math.HexOrDecimal64(g.Timestamp)
    37  	enc.ExtraData = g.ExtraData
    38  	enc.GasLimit = math.HexOrDecimal64(g.GasLimit)
    39  	enc.Difficulty = (*math.HexOrDecimal256)(g.Difficulty)
    40  	enc.Mixhash = g.Mixhash
    41  	enc.Coinbase = g.Coinbase
    42  	if g.Alloc != nil {
    43  		enc.Alloc = make(map[common.UnprefixedAddress]GenesisAccount, len(g.Alloc))
    44  		for k, v := range g.Alloc {
    45  			enc.Alloc[common.UnprefixedAddress(k)] = v
    46  		}
    47  	}
    48  	enc.Number = math.HexOrDecimal64(g.Number)
    49  	enc.GasUsed = math.HexOrDecimal64(g.GasUsed)
    50  	enc.ParentHash = g.ParentHash
    51  	return json.Marshal(&enc)
    52  }
    53  
    54  func (g GenesisWrite) MarshalJSON() ([]byte, error) {
    55  	type GenesisW struct {
    56  		Config     *params.ChainConfig       `json:"config"`
    57  		Nonce      math.HexOrDecimal64       `json:"nonce"`
    58  		Timestamp  math.HexOrDecimal64       `json:"timestamp"`
    59  		ExtraData  hexutil.Bytes             `json:"extraData"`
    60  		GasLimit   math.HexOrDecimal64       `json:"gasLimit"   gencodec:"required"`
    61  		Difficulty *math.HexOrDecimal256     `json:"difficulty" gencodec:"required"`
    62  		Mixhash    common.Hash               `json:"mixHash"`
    63  		Coinbase   string                    `json:"coinbase"`
    64  		Alloc      map[string]GenesisAccount `json:"alloc"      gencodec:"required"`
    65  		Number     math.HexOrDecimal64       `json:"number"`
    66  		GasUsed    math.HexOrDecimal64       `json:"gasUsed"`
    67  		ParentHash common.Hash               `json:"parentHash"`
    68  	}
    69  	var enc GenesisW
    70  	enc.Config = g.Config
    71  	enc.Nonce = math.HexOrDecimal64(g.Nonce)
    72  	enc.Timestamp = math.HexOrDecimal64(g.Timestamp)
    73  	enc.ExtraData = g.ExtraData
    74  	enc.GasLimit = math.HexOrDecimal64(g.GasLimit)
    75  	enc.Difficulty = (*math.HexOrDecimal256)(g.Difficulty)
    76  	enc.Mixhash = g.Mixhash
    77  	enc.Coinbase = g.Coinbase
    78  	if g.Alloc != nil {
    79  		enc.Alloc = make(map[string]GenesisAccount, len(g.Alloc))
    80  		for k, v := range g.Alloc {
    81  			enc.Alloc[k] = v
    82  		}
    83  	}
    84  	enc.Number = math.HexOrDecimal64(g.Number)
    85  	enc.GasUsed = math.HexOrDecimal64(g.GasUsed)
    86  	enc.ParentHash = g.ParentHash
    87  	return json.Marshal(&enc)
    88  }
    89  
    90  func (g *Genesis) UnmarshalJSON(input []byte) error {
    91  	type Genesis struct {
    92  		Config     *params.ChainConfig                         `json:"config"`
    93  		Nonce      *math.HexOrDecimal64                        `json:"nonce"`
    94  		Timestamp  *math.HexOrDecimal64                        `json:"timestamp"`
    95  		ExtraData  *hexutil.Bytes                              `json:"extraData"`
    96  		GasLimit   *math.HexOrDecimal64                        `json:"gasLimit"   gencodec:"required"`
    97  		Difficulty *math.HexOrDecimal256                       `json:"difficulty" gencodec:"required"`
    98  		Mixhash    *common.Hash                                `json:"mixHash"`
    99  		Coinbase   *common.Address                             `json:"coinbase"`
   100  		Alloc      map[common.UnprefixedAddress]GenesisAccount `json:"alloc"      gencodec:"required"`
   101  		Number     *math.HexOrDecimal64                        `json:"number"`
   102  		GasUsed    *math.HexOrDecimal64                        `json:"gasUsed"`
   103  		ParentHash *common.Hash                                `json:"parentHash"`
   104  	}
   105  	var dec Genesis
   106  	if err := json.Unmarshal(input, &dec); err != nil {
   107  		return err
   108  	}
   109  	if dec.Config != nil {
   110  		g.Config = dec.Config
   111  	}
   112  	if dec.Nonce != nil {
   113  		g.Nonce = uint64(*dec.Nonce)
   114  	}
   115  	if dec.Timestamp != nil {
   116  		g.Timestamp = uint64(*dec.Timestamp)
   117  	}
   118  	if dec.ExtraData != nil {
   119  		g.ExtraData = *dec.ExtraData
   120  	}
   121  	if dec.GasLimit == nil {
   122  		return errors.New("missing required field 'gasLimit' for Genesis")
   123  	}
   124  	g.GasLimit = uint64(*dec.GasLimit)
   125  	if dec.Difficulty == nil {
   126  		return errors.New("missing required field 'difficulty' for Genesis")
   127  	}
   128  	g.Difficulty = (*big.Int)(dec.Difficulty)
   129  	if dec.Mixhash != nil {
   130  		g.Mixhash = *dec.Mixhash
   131  	}
   132  	if dec.Coinbase != nil {
   133  		g.Coinbase = *dec.Coinbase
   134  	}
   135  	if dec.Alloc == nil {
   136  		return errors.New("missing required field 'alloc' for Genesis")
   137  	}
   138  	g.Alloc = make(GenesisAlloc, len(dec.Alloc))
   139  	for k, v := range dec.Alloc {
   140  		g.Alloc[common.Address(k)] = v
   141  	}
   142  	if dec.Number != nil {
   143  		g.Number = uint64(*dec.Number)
   144  	}
   145  	if dec.GasUsed != nil {
   146  		g.GasUsed = uint64(*dec.GasUsed)
   147  	}
   148  	if dec.ParentHash != nil {
   149  		g.ParentHash = *dec.ParentHash
   150  	}
   151  	return nil
   152  }
   153  
   154  func (g *GenesisWrite) UnmarshalJSON(input []byte) error {
   155  	type Genesis struct {
   156  		Config     *params.ChainConfig       `json:"config"`
   157  		Nonce      *math.HexOrDecimal64      `json:"nonce"`
   158  		Timestamp  *math.HexOrDecimal64      `json:"timestamp"`
   159  		ExtraData  *hexutil.Bytes            `json:"extraData"`
   160  		GasLimit   *math.HexOrDecimal64      `json:"gasLimit"   gencodec:"required"`
   161  		Difficulty *math.HexOrDecimal256     `json:"difficulty" gencodec:"required"`
   162  		Mixhash    *common.Hash              `json:"mixHash"`
   163  		Coinbase   string                    `json:"coinbase"`
   164  		Alloc      map[string]GenesisAccount `json:"alloc"      gencodec:"required"`
   165  		Number     *math.HexOrDecimal64      `json:"number"`
   166  		GasUsed    *math.HexOrDecimal64      `json:"gasUsed"`
   167  		ParentHash *common.Hash              `json:"parentHash"`
   168  	}
   169  	var dec Genesis
   170  	if err := json.Unmarshal(input, &dec); err != nil {
   171  		return err
   172  	}
   173  	if dec.Config != nil {
   174  		g.Config = dec.Config
   175  	}
   176  	if dec.Nonce != nil {
   177  		g.Nonce = uint64(*dec.Nonce)
   178  	}
   179  	if dec.Timestamp != nil {
   180  		g.Timestamp = uint64(*dec.Timestamp)
   181  	}
   182  	if dec.ExtraData != nil {
   183  		g.ExtraData = *dec.ExtraData
   184  	}
   185  	if dec.GasLimit == nil {
   186  		return errors.New("missing required field 'gasLimit' for Genesis")
   187  	}
   188  	g.GasLimit = uint64(*dec.GasLimit)
   189  	if dec.Difficulty == nil {
   190  		return errors.New("missing required field 'difficulty' for Genesis")
   191  	}
   192  	g.Difficulty = (*big.Int)(dec.Difficulty)
   193  	if dec.Mixhash != nil {
   194  		g.Mixhash = *dec.Mixhash
   195  	}
   196  	if dec.Coinbase != "" {
   197  		g.Coinbase = dec.Coinbase
   198  	}
   199  	if dec.Alloc == nil {
   200  		return errors.New("missing required field 'alloc' for Genesis")
   201  	}
   202  	g.Alloc = make(GenesisAllocWrite, len(dec.Alloc))
   203  	for k, v := range dec.Alloc {
   204  		g.Alloc[k] = v
   205  	}
   206  	if dec.Number != nil {
   207  		g.Number = uint64(*dec.Number)
   208  	}
   209  	if dec.GasUsed != nil {
   210  		g.GasUsed = uint64(*dec.GasUsed)
   211  	}
   212  	if dec.ParentHash != nil {
   213  		g.ParentHash = *dec.ParentHash
   214  	}
   215  	return nil
   216  }