Skip to content

Commit

Permalink
refactor StylusTargetConfig.Validate
Browse files Browse the repository at this point in the history
  • Loading branch information
magicxyyz committed Aug 28, 2024
1 parent bf735f4 commit 29327a8
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions execution/gethexec/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,24 @@ func (c *StylusTargetConfig) WasmTargets() []ethdb.WasmTarget {

func (c *StylusTargetConfig) Validate() error {
localTarget := rawdb.LocalTarget()
targets := make([]ethdb.WasmTarget, 0, len(c.ExtraArchs))
targetsSet := make(map[ethdb.WasmTarget]struct{}, len(c.ExtraArchs)+1)
targets := make([]ethdb.WasmTarget, 0, len(c.ExtraArchs)+1)
targetsSet := make(map[ethdb.WasmTarget]bool, len(c.ExtraArchs))
for _, arch := range c.ExtraArchs {
target := ethdb.WasmTarget(arch)
if targetsSet[target] {
// skip duplicate
continue
}
if !rawdb.IsSupportedWasmTarget(target) {
return fmt.Errorf("unsupported architecture: %v, possible values: %s, %s, %s, %s", arch, rawdb.TargetWavm, rawdb.TargetArm64, rawdb.TargetAmd64, rawdb.TargetHost)
}
if _, duplicate := targetsSet[target]; !duplicate {
targets = append(targets, target)
targetsSet[target] = struct{}{}
}
targets = append(targets, target)
targetsSet[target] = true
}
if _, has := targetsSet[rawdb.TargetWavm]; !has {
if !targetsSet[rawdb.TargetWavm] {
return fmt.Errorf("%s target not found in archs list, archs: %v", rawdb.TargetWavm, c.ExtraArchs)
}
if _, has := targetsSet[localTarget]; !has {
if !targetsSet[localTarget] {
targets = append(targets, localTarget)
}
c.wasmTargets = targets
Expand Down

0 comments on commit 29327a8

Please sign in to comment.