github.com/cgcardona/r-subnet-evm@v0.1.5/accounts/abi/bind/precompilebind/precompile_module_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  // tmplSourcePrecompileModuleGo is the Go precompiled module source template.
     6  const tmplSourcePrecompileModuleGo = `
     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  	"fmt"
    15  
    16  	"github.com/cgcardona/r-subnet-evm/precompile/precompileconfig"
    17  	"github.com/cgcardona/r-subnet-evm/precompile/contract"
    18  	"github.com/cgcardona/r-subnet-evm/precompile/modules"
    19  
    20  	"github.com/ethereum/go-ethereum/common"
    21  )
    22  
    23  var _ contract.Configurator = &configurator{}
    24  
    25  // ConfigKey is the key used in json config files to specify this precompile precompileconfig.
    26  // must be unique across all precompiles.
    27  const ConfigKey = "{{decapitalise .Contract.Type}}Config"
    28  
    29  // ContractAddress is the defined address of the precompile contract.
    30  // This should be unique across all precompile contracts.
    31  // See precompile/registry/registry.go for registered precompile contracts and more information.
    32  var ContractAddress = common.HexToAddress("{ASUITABLEHEXADDRESS}") // SET A SUITABLE HEX ADDRESS HERE
    33  
    34  // Module is the precompile module. It is used to register the precompile contract.
    35  var Module = modules.Module{
    36  	ConfigKey:    ConfigKey,
    37  	Address:      ContractAddress,
    38  	Contract:     {{.Contract.Type}}Precompile,
    39  	Configurator: &configurator{},
    40  }
    41  
    42  type configurator struct{}
    43  
    44  func init() {
    45  	// Register the precompile module.
    46  	// Each precompile contract registers itself through [RegisterModule] function.
    47  	if err := modules.RegisterModule(Module); err != nil {
    48  		panic(err)
    49  	}
    50  }
    51  
    52  // MakeConfig returns a new precompile config instance.
    53  // This is required for Marshal/Unmarshal the precompile config.
    54  func (*configurator) MakeConfig() precompileconfig.Config {
    55  	return new(Config)
    56  }
    57  
    58  // Configure configures [state] with the given [cfg] precompileconfig.
    59  // This function is called by the EVM once per precompile contract activation.
    60  // You can use this function to set up your precompile contract's initial state,
    61  // by using the [cfg] config and [state] stateDB.
    62  func (*configurator) Configure(chainConfig contract.ChainConfig, cfg precompileconfig.Config, state contract.StateDB, _ contract.BlockContext) error {
    63  	config, ok := cfg.(*Config)
    64  	if !ok {
    65  		return fmt.Errorf("incorrect config %T: %v", config, config)
    66  	}
    67  	// CUSTOM CODE STARTS HERE
    68  	{{- if .Contract.AllowList}}
    69  	// AllowList is activated for this precompile. Configuring allowlist addresses here.
    70  	return config.AllowListConfig.Configure(state, ContractAddress)
    71  	{{- else}}
    72  	return nil
    73  	{{- end}}
    74  }
    75  `