|
|
|
@ -18,19 +18,20 @@ var _ = (*genesisSpecMarshaling)(nil) |
|
|
|
|
// MarshalJSON marshals as JSON.
|
|
|
|
|
func (g Genesis) MarshalJSON() ([]byte, error) { |
|
|
|
|
type Genesis struct { |
|
|
|
|
Config *params.ChainConfig `json:"config"` |
|
|
|
|
Nonce math.HexOrDecimal64 `json:"nonce"` |
|
|
|
|
ShardID uint32 `json:"shardID"` |
|
|
|
|
Timestamp math.HexOrDecimal64 `json:"timestamp"` |
|
|
|
|
ExtraData hexutil.Bytes `json:"extraData"` |
|
|
|
|
GasLimit math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"` |
|
|
|
|
Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"` |
|
|
|
|
Mixhash common.Hash `json:"mixHash"` |
|
|
|
|
Coinbase common.Address `json:"coinbase"` |
|
|
|
|
Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc" gencodec:"required"` |
|
|
|
|
Number math.HexOrDecimal64 `json:"number"` |
|
|
|
|
GasUsed math.HexOrDecimal64 `json:"gasUsed"` |
|
|
|
|
ParentHash common.Hash `json:"parentHash"` |
|
|
|
|
Config *params.ChainConfig `json:"config"` |
|
|
|
|
Nonce math.HexOrDecimal64 `json:"nonce"` |
|
|
|
|
ShardID uint32 `json:"shardID"` |
|
|
|
|
Timestamp math.HexOrDecimal64 `json:"timestamp"` |
|
|
|
|
ExtraData hexutil.Bytes `json:"extraData"` |
|
|
|
|
GasLimit math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"` |
|
|
|
|
Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"` |
|
|
|
|
Mixhash common.Hash `json:"mixHash"` |
|
|
|
|
Coinbase common.Address `json:"coinbase"` |
|
|
|
|
Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc" gencodec:"required"` |
|
|
|
|
ShardStateHash common.Hash `json:"shardStateHash"` |
|
|
|
|
Number math.HexOrDecimal64 `json:"number"` |
|
|
|
|
GasUsed math.HexOrDecimal64 `json:"gasUsed"` |
|
|
|
|
ParentHash common.Hash `json:"parentHash"` |
|
|
|
|
} |
|
|
|
|
var enc Genesis |
|
|
|
|
enc.Config = g.Config |
|
|
|
@ -48,6 +49,7 @@ func (g Genesis) MarshalJSON() ([]byte, error) { |
|
|
|
|
enc.Alloc[common.UnprefixedAddress(k)] = v |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
enc.ShardStateHash = g.ShardStateHash |
|
|
|
|
enc.Number = math.HexOrDecimal64(g.Number) |
|
|
|
|
enc.GasUsed = math.HexOrDecimal64(g.GasUsed) |
|
|
|
|
enc.ParentHash = g.ParentHash |
|
|
|
@ -57,19 +59,20 @@ func (g Genesis) MarshalJSON() ([]byte, error) { |
|
|
|
|
// UnmarshalJSON unmarshals from JSON.
|
|
|
|
|
func (g *Genesis) UnmarshalJSON(input []byte) error { |
|
|
|
|
type Genesis struct { |
|
|
|
|
Config *params.ChainConfig `json:"config"` |
|
|
|
|
Nonce *math.HexOrDecimal64 `json:"nonce"` |
|
|
|
|
ShardID *uint32 `json:"shardID"` |
|
|
|
|
Timestamp *math.HexOrDecimal64 `json:"timestamp"` |
|
|
|
|
ExtraData *hexutil.Bytes `json:"extraData"` |
|
|
|
|
GasLimit *math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"` |
|
|
|
|
Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"` |
|
|
|
|
Mixhash *common.Hash `json:"mixHash"` |
|
|
|
|
Coinbase *common.Address `json:"coinbase"` |
|
|
|
|
Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc" gencodec:"required"` |
|
|
|
|
Number *math.HexOrDecimal64 `json:"number"` |
|
|
|
|
GasUsed *math.HexOrDecimal64 `json:"gasUsed"` |
|
|
|
|
ParentHash *common.Hash `json:"parentHash"` |
|
|
|
|
Config *params.ChainConfig `json:"config"` |
|
|
|
|
Nonce *math.HexOrDecimal64 `json:"nonce"` |
|
|
|
|
ShardID *uint32 `json:"shardID"` |
|
|
|
|
Timestamp *math.HexOrDecimal64 `json:"timestamp"` |
|
|
|
|
ExtraData *hexutil.Bytes `json:"extraData"` |
|
|
|
|
GasLimit *math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"` |
|
|
|
|
Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"` |
|
|
|
|
Mixhash *common.Hash `json:"mixHash"` |
|
|
|
|
Coinbase *common.Address `json:"coinbase"` |
|
|
|
|
Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc" gencodec:"required"` |
|
|
|
|
ShardStateHash *common.Hash `json:"shardStateHash"` |
|
|
|
|
Number *math.HexOrDecimal64 `json:"number"` |
|
|
|
|
GasUsed *math.HexOrDecimal64 `json:"gasUsed"` |
|
|
|
|
ParentHash *common.Hash `json:"parentHash"` |
|
|
|
|
} |
|
|
|
|
var dec Genesis |
|
|
|
|
if err := json.Unmarshal(input, &dec); err != nil { |
|
|
|
@ -111,6 +114,9 @@ func (g *Genesis) UnmarshalJSON(input []byte) error { |
|
|
|
|
for k, v := range dec.Alloc { |
|
|
|
|
g.Alloc[common.Address(k)] = v |
|
|
|
|
} |
|
|
|
|
if dec.ShardStateHash != nil { |
|
|
|
|
g.ShardStateHash = *dec.ShardStateHash |
|
|
|
|
} |
|
|
|
|
if dec.Number != nil { |
|
|
|
|
g.Number = uint64(*dec.Number) |
|
|
|
|
} |
|
|
|
|