github.com/cgcardona/r-subnet-evm@v0.1.5/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  	"math/big"
    15  
    16  	"github.com/cgcardona/r-subnet-evm/precompile/precompileconfig"
    17  	{{- if .Contract.AllowList}}
    18  	"github.com/cgcardona/r-subnet-evm/precompile/allowlist"
    19  
    20  	"github.com/ethereum/go-ethereum/common"
    21  	{{- end}}
    22  
    23  )
    24  
    25  var _ precompileconfig.Config = &Config{}
    26  
    27  // Config implements the precompileconfig.Config interface and
    28  // adds specific configuration for {{.Contract.Type}}.
    29  type Config struct {
    30  	{{- if .Contract.AllowList}}
    31  	allowlist.AllowListConfig
    32  	{{- end}}
    33  	precompileconfig.Upgrade
    34  	// CUSTOM CODE STARTS HERE
    35  	// Add your own custom fields for Config here
    36  }
    37  
    38  // NewConfig returns a config for a network upgrade at [blockTimestamp] that enables
    39  // {{.Contract.Type}} {{- if .Contract.AllowList}} with the given [admins] as members of the allowlist {{end}}.
    40  func NewConfig(blockTimestamp *big.Int{{if .Contract.AllowList}}, admins []common.Address, enableds []common.Address,{{end}}) *Config {
    41  	return &Config{
    42  		{{- if .Contract.AllowList}}
    43  		AllowListConfig: allowlist.AllowListConfig{
    44  			AdminAddresses: admins,
    45  			EnabledAddresses: enableds,
    46  		},
    47  		{{- end}}
    48  		Upgrade: precompileconfig.Upgrade{BlockTimestamp: blockTimestamp},
    49  	}
    50  }
    51  
    52  // NewDisableConfig returns config for a network upgrade at [blockTimestamp]
    53  // that disables {{.Contract.Type}}.
    54  func NewDisableConfig(blockTimestamp *big.Int) *Config {
    55  	return &Config{
    56  		Upgrade: precompileconfig.Upgrade{
    57  			BlockTimestamp: blockTimestamp,
    58  			Disable:        true,
    59  		},
    60  	}
    61  }
    62  
    63  // Key returns the key for the {{.Contract.Type}} precompileconfig.
    64  // This should be the same key as used in the precompile module.
    65  func (*Config) Key() string { return ConfigKey }
    66  
    67  // Verify tries to verify Config and returns an error accordingly.
    68  func (c *Config) Verify() error {
    69  	{{- if .Contract.AllowList}}
    70  	// Verify AllowList first
    71  	if err := c.AllowListConfig.Verify(); err != nil {
    72  		return err
    73  	}
    74  	{{- end}}
    75  	// CUSTOM CODE STARTS HERE
    76  	// Add your own custom verify code for Config here
    77  	// and return an error accordingly
    78  	return nil
    79  }
    80  
    81  // Equal returns true if [s] is a [*Config] and it has been configured identical to [c].
    82  func (c *Config) Equal(s precompileconfig.Config) bool {
    83  	// typecast before comparison
    84  	other, ok := (s).(*Config)
    85  	if !ok {
    86  		return false
    87  	}
    88  	// CUSTOM CODE STARTS HERE
    89  	// modify this boolean accordingly with your custom Config, to check if [other] and the current [c] are equal
    90  	// if Config contains only Upgrade {{- if .Contract.AllowList}} and AllowListConfig {{end}} you can skip modifying it.
    91  	equals := c.Upgrade.Equal(&other.Upgrade) {{- if .Contract.AllowList}} && c.AllowListConfig.Equal(&other.AllowListConfig) {{end}}
    92  	return equals
    93  }
    94  `