github.com/ava-labs/subnet-evm@v0.6.4/accounts/abi/bind/precompilebind/precompile_config_template.go (about) 1 // (c) 2019-2022, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 package precompilebind 4 5 // tmplSourcePrecompileConfigGo is the Go precompiled config source template. 6 const tmplSourcePrecompileConfigGo = ` 7 // Code generated 8 // This file is a generated precompile contract config with stubbed abstract functions. 9 // The file is generated by a template. Please inspect every code and comment in this file before use. 10 11 package {{.Package}} 12 13 import ( 14 "github.com/ava-labs/subnet-evm/precompile/precompileconfig" 15 {{- if .Contract.AllowList}} 16 "github.com/ava-labs/subnet-evm/precompile/allowlist" 17 18 "github.com/ethereum/go-ethereum/common" 19 {{- end}} 20 21 ) 22 23 var _ precompileconfig.Config = &Config{} 24 25 // Config implements the precompileconfig.Config interface and 26 // adds specific configuration for {{.Contract.Type}}. 27 type Config struct { 28 {{- if .Contract.AllowList}} 29 allowlist.AllowListConfig 30 {{- end}} 31 precompileconfig.Upgrade 32 // CUSTOM CODE STARTS HERE 33 // Add your own custom fields for Config here 34 } 35 36 // NewConfig returns a config for a network upgrade at [blockTimestamp] that enables 37 // {{.Contract.Type}} {{- if .Contract.AllowList}} with the given [admins], [enableds] and [managers] members of the allowlist {{end}}. 38 func NewConfig(blockTimestamp *uint64{{if .Contract.AllowList}}, admins []common.Address, enableds []common.Address, managers []common.Address{{end}}) *Config { 39 return &Config{ 40 {{- if .Contract.AllowList}} 41 AllowListConfig: allowlist.AllowListConfig{ 42 AdminAddresses: admins, 43 EnabledAddresses: enableds, 44 ManagerAddresses: managers, 45 }, 46 {{- end}} 47 Upgrade: precompileconfig.Upgrade{BlockTimestamp: blockTimestamp}, 48 } 49 } 50 51 // NewDisableConfig returns config for a network upgrade at [blockTimestamp] 52 // that disables {{.Contract.Type}}. 53 func NewDisableConfig(blockTimestamp *uint64) *Config { 54 return &Config{ 55 Upgrade: precompileconfig.Upgrade{ 56 BlockTimestamp: blockTimestamp, 57 Disable: true, 58 }, 59 } 60 } 61 62 // Key returns the key for the {{.Contract.Type}} precompileconfig. 63 // This should be the same key as used in the precompile module. 64 func (*Config) Key() string { return ConfigKey } 65 66 // Verify tries to verify Config and returns an error accordingly. 67 func (c *Config) Verify(chainConfig precompileconfig.ChainConfig) error { 68 {{- if .Contract.AllowList}} 69 // Verify AllowList first 70 if err := c.AllowListConfig.Verify(chainConfig, c.Upgrade); err != nil { 71 return err 72 } 73 {{- end}} 74 // CUSTOM CODE STARTS HERE 75 // Add your own custom verify code for Config here 76 // and return an error accordingly 77 return nil 78 } 79 80 // Equal returns true if [s] is a [*Config] and it has been configured identical to [c]. 81 func (c *Config) Equal(s precompileconfig.Config) bool { 82 // typecast before comparison 83 other, ok := (s).(*Config) 84 if !ok { 85 return false 86 } 87 // CUSTOM CODE STARTS HERE 88 // modify this boolean accordingly with your custom Config, to check if [other] and the current [c] are equal 89 // if Config contains only Upgrade {{- if .Contract.AllowList}} and AllowListConfig {{end}} you can skip modifying it. 90 equals := c.Upgrade.Equal(&other.Upgrade) {{- if .Contract.AllowList}} && c.AllowListConfig.Equal(&other.AllowListConfig) {{end}} 91 return equals 92 } 93 `