-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
118 lines (100 loc) · 3.4 KB
/
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// Code generated
// This file is a generated precompile contract with stubbed abstract functions.
package rewardmanager
import (
"math/big"
"github.com/cgcardona/r-subnet-evm/precompile/allowlist"
"github.com/cgcardona/r-subnet-evm/precompile/contract"
"github.com/cgcardona/r-subnet-evm/precompile/precompileconfig"
"github.com/ethereum/go-ethereum/common"
)
var _ precompileconfig.Config = &Config{}
type InitialRewardConfig struct {
AllowFeeRecipients bool `json:"allowFeeRecipients"`
RewardAddress common.Address `json:"rewardAddress,omitempty"`
}
func (i *InitialRewardConfig) Equal(other *InitialRewardConfig) bool {
if other == nil {
return false
}
return i.AllowFeeRecipients == other.AllowFeeRecipients && i.RewardAddress == other.RewardAddress
}
func (i *InitialRewardConfig) Verify() error {
switch {
case i.AllowFeeRecipients && i.RewardAddress != (common.Address{}):
return ErrCannotEnableBothRewards
default:
return nil
}
}
func (i *InitialRewardConfig) Configure(state contract.StateDB) error {
// enable allow fee recipients
if i.AllowFeeRecipients {
EnableAllowFeeRecipients(state)
} else if i.RewardAddress == (common.Address{}) {
// if reward address is empty and allow fee recipients is false
// then disable rewards
DisableFeeRewards(state)
} else {
// set reward address
return StoreRewardAddress(state, i.RewardAddress)
}
return nil
}
// Config implements the StatefulPrecompileConfig interface while adding in the
// RewardManager specific precompile config.
type Config struct {
allowlist.AllowListConfig
precompileconfig.Upgrade
InitialRewardConfig *InitialRewardConfig `json:"initialRewardConfig,omitempty"`
}
// NewConfig returns a config for a network upgrade at [blockTimestamp] that enables
// RewardManager with the given [admins] and [enableds] as members of the allowlist with [initialConfig] as initial rewards config if specified.
func NewConfig(blockTimestamp *big.Int, admins []common.Address, enableds []common.Address, initialConfig *InitialRewardConfig) *Config {
return &Config{
AllowListConfig: allowlist.AllowListConfig{
AdminAddresses: admins,
EnabledAddresses: enableds,
},
Upgrade: precompileconfig.Upgrade{BlockTimestamp: blockTimestamp},
InitialRewardConfig: initialConfig,
}
}
// NewDisableConfig returns config for a network upgrade at [blockTimestamp]
// that disables RewardManager.
func NewDisableConfig(blockTimestamp *big.Int) *Config {
return &Config{
Upgrade: precompileconfig.Upgrade{
BlockTimestamp: blockTimestamp,
Disable: true,
},
}
}
func (*Config) Key() string { return ConfigKey }
func (c *Config) Verify() error {
if c.InitialRewardConfig != nil {
if err := c.InitialRewardConfig.Verify(); err != nil {
return err
}
}
return c.AllowListConfig.Verify()
}
// Equal returns true if [cfg] is a [*RewardManagerConfig] and it has been configured identical to [c].
func (c *Config) Equal(cfg precompileconfig.Config) bool {
// typecast before comparison
other, ok := (cfg).(*Config)
if !ok {
return false
}
if c.InitialRewardConfig != nil {
if other.InitialRewardConfig == nil {
return false
}
if !c.InitialRewardConfig.Equal(other.InitialRewardConfig) {
return false
}
}
return c.Upgrade.Equal(&other.Upgrade) && c.AllowListConfig.Equal(&other.AllowListConfig)
}