-
Notifications
You must be signed in to change notification settings - Fork 6
/
gen_equality_config.go
82 lines (76 loc) · 2.6 KB
/
gen_equality_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
package params
import (
"encoding/json"
"errors"
"math/big"
"github.com/SecretBlockChain/go-secret/common"
"github.com/SecretBlockChain/go-secret/common/math"
)
var _ = (*equalityConfigMarshaling)(nil)
// MarshalJSON marshals as JSON.
func (e EqualityConfig) MarshalJSON() ([]byte, error) {
type EqualityConfig struct {
Period uint64 `json:"period"`
Epoch uint64 `json:"epoch"`
MaxValidatorsCount uint64 `json:"maxValidatorsCount"`
MinCandidateBalance *math.HexOrDecimal256 `json:"minCandidateBalance" gencodec:"required"`
GenesisTimestamp uint64 `json:"genesisTimestamp"`
Validators []common.Address `json:"validators"`
Pool common.Address `json:"pool"`
Rewards EqualityRewards `json:"rewards"`
}
var enc EqualityConfig
enc.Period = e.Period
enc.Epoch = e.Epoch
enc.MaxValidatorsCount = e.MaxValidatorsCount
enc.MinCandidateBalance = (*math.HexOrDecimal256)(e.MinCandidateBalance)
enc.GenesisTimestamp = e.GenesisTimestamp
enc.Validators = e.Validators
enc.Pool = e.Pool
enc.Rewards = e.Rewards
return json.Marshal(&enc)
}
// UnmarshalJSON unmarshals from JSON.
func (e *EqualityConfig) UnmarshalJSON(input []byte) error {
type EqualityConfig struct {
Period *uint64 `json:"period"`
Epoch *uint64 `json:"epoch"`
MaxValidatorsCount *uint64 `json:"maxValidatorsCount"`
MinCandidateBalance *math.HexOrDecimal256 `json:"minCandidateBalance" gencodec:"required"`
GenesisTimestamp *uint64 `json:"genesisTimestamp"`
Validators []common.Address `json:"validators"`
Pool *common.Address `json:"pool"`
Rewards *EqualityRewards `json:"rewards"`
}
var dec EqualityConfig
if err := json.Unmarshal(input, &dec); err != nil {
return err
}
if dec.Period != nil {
e.Period = *dec.Period
}
if dec.Epoch != nil {
e.Epoch = *dec.Epoch
}
if dec.MaxValidatorsCount != nil {
e.MaxValidatorsCount = *dec.MaxValidatorsCount
}
if dec.MinCandidateBalance == nil {
return errors.New("missing required field 'minCandidateBalance' for EqualityConfig")
}
e.MinCandidateBalance = (*big.Int)(dec.MinCandidateBalance)
if dec.GenesisTimestamp != nil {
e.GenesisTimestamp = *dec.GenesisTimestamp
}
if dec.Validators != nil {
e.Validators = dec.Validators
}
if dec.Pool != nil {
e.Pool = *dec.Pool
}
if dec.Rewards != nil {
e.Rewards = *dec.Rewards
}
return nil
}