Files
evm/accounts/abi/bind/precompilebind/precompile_module_template.go
zeekay 195a2fc12c deps: update to latest real-semver, drop local replaces, fix breaks
- luxfi/constants: pseudo-version v1.5.8-0.2026... -> real tag v1.5.8
- luxfi/upgrade: pseudo-version v1.0.1-0.2026... -> real tag v1.0.1
- precompilebind: emit MakeGenesisConfig in module template (Configurator
  interface gained MakeGenesisConfig; generator was stale)
- precompilebind test: use reserved-range address 0x0200..00ff (the 0x03..
  test address predates the tightened reserved ranges in modules/registerer.go)
2026-06-11 09:26:08 -07:00

89 lines
3.2 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package precompilebind
// tmplSourcePrecompileModuleGo is the Go precompiled module source template.
const tmplSourcePrecompileModuleGo = `
// Code generated
// This file is a generated precompile contract config with stubbed abstract functions.
// The file is generated by a template. Please inspect every code and comment in this file before use.
package {{.Package}}
import (
"fmt"
"github.com/luxfi/evm/precompile/precompileconfig"
"github.com/luxfi/evm/precompile/contract"
"github.com/luxfi/evm/precompile/modules"
"github.com/luxfi/geth/common"
)
var _ contract.Configurator = (*configurator)(nil)
// ConfigKey is the key used in json config files to specify this precompile config.
// must be unique across all precompiles.
const ConfigKey = "{{decapitalise .Contract.Type}}Config"
// ContractAddress is the defined address of the precompile contract.
// This should be unique across all precompile contracts.
// See precompile/registry/registry.go for registered precompile contracts and more information.
var ContractAddress = common.HexToAddress("{ASUITABLEHEXADDRESS}") // SET A SUITABLE HEX ADDRESS HERE
// Module is the precompile module. It is used to register the precompile contract.
var Module = modules.Module{
ConfigKey: ConfigKey,
Address: ContractAddress,
Contract: {{.Contract.Type}}Precompile,
Configurator: &configurator{},
}
type configurator struct{}
func init() {
// Register the precompile module.
// Each precompile contract registers itself through [RegisterModule] function.
if err := modules.RegisterModule(Module); err != nil {
panic(err)
}
}
// MakeConfig returns a new precompile config instance.
// This is required to Marshal/Unmarshal the precompile config.
func (*configurator) MakeConfig() precompileconfig.Config {
return new(Config)
}
// MakeGenesisConfig returns a precompile config for genesis activation (timestamp = 0).
// This is used by AllGenesisPrecompiles() to enumerate all precompiles with default configs.
func (*configurator) MakeGenesisConfig() precompileconfig.Config {
var zero uint64
return NewConfig(&zero{{if .Contract.AllowList}}, nil, nil, nil{{end}})
}
// Configure configures [state] with the given [cfg] precompileconfig.
// This function is called by the EVM once per precompile contract activation.
// You can use this function to set up your precompile contract's initial state,
// by using the [cfg] config and [state] stateDB.
func (*configurator) Configure(chainConfig precompileconfig.ChainConfig, cfg precompileconfig.Config, state contract.StateDB, blockContext contract.ConfigurationBlockContext) error {
// CUSTOM CODE STARTS HERE
{{- if .Contract.AllowList}}
config, ok := cfg.(*Config)
if !ok {
return fmt.Errorf("expected config type %T, got %T: %v", &Config{}, cfg, cfg)
}
// AllowList is activated for this precompile. Configuring allowlist addresses here.
return config.AllowListConfig.Configure(chainConfig, ContractAddress, state, blockContext)
{{- else}}
if _, ok := cfg.(*Config); !ok {
return fmt.Errorf("expected config type %T, got %T: %v", &Config{}, cfg, cfg)
}
return nil
{{- end}}
}
`