Skip to content

Commit 1d7b284

Browse files
author
Darioush Jalali
authored
fix config template for precompilegen (#538)
* fix config template for precompilegen * nits * nit * nits
1 parent 4455733 commit 1d7b284

File tree

3 files changed

+14
-37
lines changed

3 files changed

+14
-37
lines changed

accounts/abi/bind/precompilebind/precompile_config_template.go

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
2525
var _ precompileconfig.Config = &Config{}
2626
27-
// Config implements the StatefulPrecompileConfig
28-
// interface while adding in the {{.Contract.Type}} specific precompile address.
27+
// Config implements the precompileconfig.Config interface and
28+
// adds specific configuration for {{.Contract.Type}}.
2929
type Config struct {
3030
{{- if .Contract.AllowList}}
3131
allowlist.AllowListConfig
@@ -35,38 +35,15 @@ type Config struct {
3535
// Add your own custom fields for Config here
3636
}
3737
38-
{{$structs := .Structs}}
39-
{{range $structs}}
40-
// {{.Name}} is an auto generated low-level Go binding around an user-defined struct.
41-
type {{.Name}} struct {
42-
{{range $field := .Fields}}
43-
{{$field.Name}} {{$field.Type}}{{end}}
44-
}
45-
{{- end}}
46-
47-
{{- range .Contract.Funcs}}
48-
{{ if len .Normalized.Inputs | lt 1}}
49-
type {{capitalise .Normalized.Name}}Input struct{
50-
{{range .Normalized.Inputs}} {{capitalise .Name}} {{bindtype .Type $structs}}; {{end}}
51-
}
52-
{{- end}}
53-
{{ if len .Normalized.Outputs | lt 1}}
54-
type {{capitalise .Normalized.Name}}Output struct{
55-
{{range .Normalized.Outputs}} {{capitalise .Name}} {{bindtype .Type $structs}}; {{end}}
56-
}
57-
{{- end}}
58-
{{- end}}
59-
6038
// NewConfig returns a config for a network upgrade at [blockTimestamp] that enables
61-
// {{.Contract.Type}} with the given [admins] and [enableds] as members of the allowlist.
62-
// {{.Contract.Type}} {{if .Contract.AllowList}} with the given [admins] as members of the allowlist {{end}}.
39+
// {{.Contract.Type}} {{- if .Contract.AllowList}} with the given [admins] as members of the allowlist {{end}}.
6340
func NewConfig(blockTimestamp *big.Int{{if .Contract.AllowList}}, admins []common.Address, enableds []common.Address,{{end}}) *Config {
6441
return &Config{
6542
{{- if .Contract.AllowList}}
6643
AllowListConfig: allowlist.AllowListConfig{
6744
AdminAddresses: admins,
6845
EnabledAddresses: enableds,
69-
},
46+
},
7047
{{- end}}
7148
Upgrade: precompileconfig.Upgrade{BlockTimestamp: blockTimestamp},
7249
}
@@ -89,12 +66,12 @@ func (*Config) Key() string { return ConfigKey }
8966
9067
// Verify tries to verify Config and returns an error accordingly.
9168
func (c *Config) Verify() error {
92-
{{if .Contract.AllowList}}
69+
{{- if .Contract.AllowList}}
9370
// Verify AllowList first
9471
if err := c.AllowListConfig.Verify(); err != nil {
9572
return err
9673
}
97-
{{end}}
74+
{{- end}}
9875
// CUSTOM CODE STARTS HERE
9976
// Add your own custom verify code for Config here
10077
// and return an error accordingly
@@ -110,8 +87,8 @@ func (c *Config) Equal(s precompileconfig.Config) bool {
11087
}
11188
// CUSTOM CODE STARTS HERE
11289
// modify this boolean accordingly with your custom Config, to check if [other] and the current [c] are equal
113-
// if Config contains only Upgrade {{if .Contract.AllowList}} and AllowListConfig {{end}} you can skip modifying it.
114-
equals := c.Upgrade.Equal(&other.Upgrade) {{if .Contract.AllowList}} && c.AllowListConfig.Equal(&other.AllowListConfig) {{end}}
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}}
11592
return equals
11693
}
11794
`

accounts/abi/bind/precompilebind/precompile_contract_template.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const (
5252
{{- if .Contract.AllowList}}
5353
// This contract also uses AllowList precompile.
5454
// You should also increase gas costs of functions that read from AllowList storage.
55-
{{- end}}}
55+
{{- end}}
5656
{{- range .Contract.Funcs}}
5757
{{.Normalized.Name}}GasCost uint64 = 0 {{if not .Original.IsConstant | and $contract.AllowList}} + allowlist.ReadAllowListGasCost {{end}} // SET A GAS COST HERE
5858
{{- end}}
@@ -136,7 +136,7 @@ func Set{{.Contract.Type}}AllowListStatus(stateDB contract.StateDB, address comm
136136
137137
{{range .Contract.Funcs}}
138138
{{if len .Normalized.Inputs | lt 1}}
139-
// Unpack{{capitalise .Normalized.Name}}Input attempts to unpack [input] into the arguments for the {{capitalise .Normalized.Name}}Input{}
139+
// Unpack{{capitalise .Normalized.Name}}Input attempts to unpack [input] as {{capitalise .Normalized.Name}}Input
140140
// assumes that [input] does not include selector (omits first 4 func signature bytes)
141141
func Unpack{{capitalise .Normalized.Name}}Input(input []byte) ({{capitalise .Normalized.Name}}Input, error) {
142142
inputStruct := {{capitalise .Normalized.Name}}Input{}
@@ -298,7 +298,7 @@ func {{decapitalise $contract.Type}}Fallback (accessibleState contract.Accessibl
298298
{{- end}}
299299
300300
// create{{.Contract.Type}}Precompile returns a StatefulPrecompiledContract with getters and setters for the precompile.
301-
{{if .Contract.AllowList}} // Access to the getters/setters is controlled by an allow list for ContractAddress.{{end}}
301+
{{- if .Contract.AllowList}} // Access to the getters/setters is controlled by an allow list for ContractAddress.{{end}}
302302
func create{{.Contract.Type}}Precompile() contract.StatefulPrecompiledContract {
303303
var functions []*contract.StatefulPrecompileFunction
304304
{{- if .Contract.AllowList}}

accounts/abi/bind/precompilebind/precompile_module_template.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ func (*configurator) Configure(chainConfig contract.ChainConfig, cfg precompilec
6565
return fmt.Errorf("incorrect config %T: %v", config, config)
6666
}
6767
// CUSTOM CODE STARTS HERE
68-
{{if .Contract.AllowList}}
68+
{{- if .Contract.AllowList}}
6969
// AllowList is activated for this precompile. Configuring allowlist addresses here.
7070
return config.AllowListConfig.Configure(state, ContractAddress)
71-
{{else}}
71+
{{- else}}
7272
return nil
73-
{{end}}
73+
{{- end}}
7474
}
7575
`

0 commit comments

Comments
 (0)