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