Skip to content

Commit

Permalink
Use map for the whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
artemskriabin committed Aug 14, 2024
1 parent 4aa758b commit bdbc1d0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/config/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"crypto/ecdsa"
"math/big"
"slices"
"strings"
"sync"

Expand Down Expand Up @@ -34,7 +33,7 @@ type ethereum struct {
getter kv.Getter
}

type whitelist []string
type whitelist map[string]struct{}

type RelayerConfig struct {
RPC *ethclient.Client
Expand Down Expand Up @@ -89,14 +88,14 @@ func (e *ethereum) RelayerConfig() *RelayerConfig {
panic(errors.Wrap(err, "failed to get nonce"))
}

result.WhiteList = make(whitelist, 0, len(networkConfig.WhiteList))
result.WhiteList = make(whitelist, len(networkConfig.WhiteList))
for _, address := range networkConfig.WhiteList {
address = strings.ToLower(address)
if result.WhiteList.IsPresent(address) {
continue
}

result.WhiteList = append(result.WhiteList, address)
result.WhiteList[address] = struct{}{}
}

result.mut = &sync.Mutex{}
Expand Down Expand Up @@ -171,5 +170,6 @@ func extractPrivateKey(vaultAddress, vaultMountPath string) *ecdsa.PrivateKey {
}

func (w whitelist) IsPresent(address string) bool {
return slices.Contains(w, address)
_, ok := w[address]
return ok
}

0 comments on commit bdbc1d0

Please sign in to comment.