diff --git a/accounts/abi/bind/precompilebind/precompile_config_template.go b/accounts/abi/bind/precompilebind/precompile_config_template.go index 4d8f9252de..9b42725302 100644 --- a/accounts/abi/bind/precompilebind/precompile_config_template.go +++ b/accounts/abi/bind/precompilebind/precompile_config_template.go @@ -24,8 +24,8 @@ import ( var _ precompileconfig.Config = &Config{} -// Config implements the StatefulPrecompileConfig -// interface while adding in the {{.Contract.Type}} specific precompile address. +// Config implements the precompileconfig.Config interface and +// adds specific configuration for {{.Contract.Type}}. type Config struct { {{- if .Contract.AllowList}} allowlist.AllowListConfig @@ -35,38 +35,15 @@ type Config struct { // Add your own custom fields for Config here } -{{$structs := .Structs}} -{{range $structs}} - // {{.Name}} is an auto generated low-level Go binding around an user-defined struct. - type {{.Name}} struct { - {{range $field := .Fields}} - {{$field.Name}} {{$field.Type}}{{end}} - } -{{- end}} - -{{- range .Contract.Funcs}} -{{ if len .Normalized.Inputs | lt 1}} -type {{capitalise .Normalized.Name}}Input struct{ -{{range .Normalized.Inputs}} {{capitalise .Name}} {{bindtype .Type $structs}}; {{end}} -} -{{- end}} -{{ if len .Normalized.Outputs | lt 1}} -type {{capitalise .Normalized.Name}}Output struct{ -{{range .Normalized.Outputs}} {{capitalise .Name}} {{bindtype .Type $structs}}; {{end}} -} -{{- end}} -{{- end}} - // NewConfig returns a config for a network upgrade at [blockTimestamp] that enables -// {{.Contract.Type}} with the given [admins] and [enableds] as members of the allowlist. -// {{.Contract.Type}} {{if .Contract.AllowList}} with the given [admins] as members of the allowlist {{end}}. +// {{.Contract.Type}} {{- if .Contract.AllowList}} with the given [admins] as members of the allowlist {{end}}. func NewConfig(blockTimestamp *big.Int{{if .Contract.AllowList}}, admins []common.Address, enableds []common.Address,{{end}}) *Config { return &Config{ {{- if .Contract.AllowList}} AllowListConfig: allowlist.AllowListConfig{ AdminAddresses: admins, EnabledAddresses: enableds, - }, + }, {{- end}} Upgrade: precompileconfig.Upgrade{BlockTimestamp: blockTimestamp}, } @@ -89,12 +66,12 @@ func (*Config) Key() string { return ConfigKey } // Verify tries to verify Config and returns an error accordingly. func (c *Config) Verify() error { - {{if .Contract.AllowList}} + {{- if .Contract.AllowList}} // Verify AllowList first if err := c.AllowListConfig.Verify(); err != nil { return err } - {{end}} + {{- end}} // CUSTOM CODE STARTS HERE // Add your own custom verify code for Config here // and return an error accordingly @@ -110,8 +87,8 @@ func (c *Config) Equal(s precompileconfig.Config) bool { } // CUSTOM CODE STARTS HERE // modify this boolean accordingly with your custom Config, to check if [other] and the current [c] are equal - // if Config contains only Upgrade {{if .Contract.AllowList}} and AllowListConfig {{end}} you can skip modifying it. - equals := c.Upgrade.Equal(&other.Upgrade) {{if .Contract.AllowList}} && c.AllowListConfig.Equal(&other.AllowListConfig) {{end}} + // if Config contains only Upgrade {{- if .Contract.AllowList}} and AllowListConfig {{end}} you can skip modifying it. + equals := c.Upgrade.Equal(&other.Upgrade) {{- if .Contract.AllowList}} && c.AllowListConfig.Equal(&other.AllowListConfig) {{end}} return equals } ` diff --git a/accounts/abi/bind/precompilebind/precompile_contract_template.go b/accounts/abi/bind/precompilebind/precompile_contract_template.go index 1c302d4b49..21476406bb 100644 --- a/accounts/abi/bind/precompilebind/precompile_contract_template.go +++ b/accounts/abi/bind/precompilebind/precompile_contract_template.go @@ -52,7 +52,7 @@ const ( {{- if .Contract.AllowList}} // This contract also uses AllowList precompile. // You should also increase gas costs of functions that read from AllowList storage. - {{- end}}} + {{- end}} {{- range .Contract.Funcs}} {{.Normalized.Name}}GasCost uint64 = 0 {{if not .Original.IsConstant | and $contract.AllowList}} + allowlist.ReadAllowListGasCost {{end}} // SET A GAS COST HERE {{- end}} @@ -136,7 +136,7 @@ func Set{{.Contract.Type}}AllowListStatus(stateDB contract.StateDB, address comm {{range .Contract.Funcs}} {{if len .Normalized.Inputs | lt 1}} -// Unpack{{capitalise .Normalized.Name}}Input attempts to unpack [input] into the arguments for the {{capitalise .Normalized.Name}}Input{} +// Unpack{{capitalise .Normalized.Name}}Input attempts to unpack [input] as {{capitalise .Normalized.Name}}Input // assumes that [input] does not include selector (omits first 4 func signature bytes) func Unpack{{capitalise .Normalized.Name}}Input(input []byte) ({{capitalise .Normalized.Name}}Input, error) { inputStruct := {{capitalise .Normalized.Name}}Input{} @@ -298,7 +298,7 @@ func {{decapitalise $contract.Type}}Fallback (accessibleState contract.Accessibl {{- end}} // create{{.Contract.Type}}Precompile returns a StatefulPrecompiledContract with getters and setters for the precompile. -{{if .Contract.AllowList}} // Access to the getters/setters is controlled by an allow list for ContractAddress.{{end}} +{{- if .Contract.AllowList}} // Access to the getters/setters is controlled by an allow list for ContractAddress.{{end}} func create{{.Contract.Type}}Precompile() contract.StatefulPrecompiledContract { var functions []*contract.StatefulPrecompileFunction {{- if .Contract.AllowList}} diff --git a/accounts/abi/bind/precompilebind/precompile_module_template.go b/accounts/abi/bind/precompilebind/precompile_module_template.go index db3950e3f5..6a7b27dc92 100644 --- a/accounts/abi/bind/precompilebind/precompile_module_template.go +++ b/accounts/abi/bind/precompilebind/precompile_module_template.go @@ -65,11 +65,11 @@ func (*configurator) Configure(chainConfig contract.ChainConfig, cfg precompilec return fmt.Errorf("incorrect config %T: %v", config, config) } // CUSTOM CODE STARTS HERE - {{if .Contract.AllowList}} + {{- if .Contract.AllowList}} // AllowList is activated for this precompile. Configuring allowlist addresses here. return config.AllowListConfig.Configure(state, ContractAddress) - {{else}} + {{- else}} return nil - {{end}} + {{- end}} } `