-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.go
61 lines (50 loc) · 1.84 KB
/
module.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
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package rewardmanager
import (
"fmt"
"github.com/cgcardona/r-subnet-evm/precompile/contract"
"github.com/cgcardona/r-subnet-evm/precompile/modules"
"github.com/cgcardona/r-subnet-evm/precompile/precompileconfig"
"github.com/ethereum/go-ethereum/common"
)
var _ contract.Configurator = &configurator{}
// ConfigKey is the key used in json config files to specify this precompile config.
// must be unique across all precompiles.
const ConfigKey = "rewardManagerConfig"
var ContractAddress = common.HexToAddress("0x0200000000000000000000000000000000000004")
var Module = modules.Module{
ConfigKey: ConfigKey,
Address: ContractAddress,
Contract: RewardManagerPrecompile,
Configurator: &configurator{},
}
type configurator struct{}
func init() {
if err := modules.RegisterModule(Module); err != nil {
panic(err)
}
}
func (*configurator) MakeConfig() precompileconfig.Config {
return new(Config)
}
// Configure configures [state] with the initial state for the precompile.
func (*configurator) Configure(chainConfig contract.ChainConfig, cfg precompileconfig.Config, state contract.StateDB, _ contract.BlockContext) error {
config, ok := cfg.(*Config)
if !ok {
return fmt.Errorf("incorrect config %T: %v", config, config)
}
// configure the RewardManager with the given initial configuration
if config.InitialRewardConfig != nil {
config.InitialRewardConfig.Configure(state)
} else if chainConfig.AllowedFeeRecipients() {
// configure the RewardManager according to chainConfig
EnableAllowFeeRecipients(state)
} else {
// chainConfig does not have any reward address
// if chainConfig does not enable fee recipients
// default to disabling rewards
DisableFeeRewards(state)
}
return config.Configure(state, ContractAddress)
}