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