Skip to content

Commit

Permalink
reduce dep on pkg from sdk helper
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero committed Jan 10, 2025
1 parent 2e6f76f commit 9e30764
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 27 deletions.
3 changes: 2 additions & 1 deletion cmd/interchaincmd/relayercmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ava-labs/avalanche-cli/pkg/models"
"github.com/ava-labs/avalanche-cli/pkg/networkoptions"
"github.com/ava-labs/avalanche-cli/pkg/utils"
sdkUtils "github.com/ava-labs/avalanche-cli/sdk/utils"
"github.com/ava-labs/avalanchego/utils/logging"

"github.com/jedib0t/go-pretty/v6/table"
Expand Down Expand Up @@ -131,7 +132,7 @@ func logs(_ *cobra.Command, _ []string) error {
keys := maps.Keys(logMap)
sort.Strings(keys)
for _, k := range keys {
if !utils.Belongs([]string{"logger", "caller", "level", "timestamp", "msg"}, k) {
if !sdkUtils.Belongs([]string{"logger", "caller", "level", "timestamp", "msg"}, k) {
logMsg = addAditionalInfo(
logMsg,
logMap,
Expand Down
12 changes: 7 additions & 5 deletions cmd/keycmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import (
"github.com/ava-labs/avalanche-cli/pkg/networkoptions"
"github.com/ava-labs/avalanche-cli/pkg/utils"
"github.com/ava-labs/avalanche-cli/pkg/ux"
sdkUtils "github.com/ava-labs/avalanche-cli/sdk/utils"
"github.com/ava-labs/avalanchego/ids"
ledger "github.com/ava-labs/avalanchego/utils/crypto/ledger"
"github.com/ava-labs/avalanchego/utils/formatting/address"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/avm"
"github.com/ava-labs/avalanchego/vms/platformvm"
"github.com/ava-labs/coreth/ethclient"

"github.com/ethereum/go-ethereum/common"
goethereumethclient "github.com/ethereum/go-ethereum/ethclient"
"github.com/liyue201/erc20-go/erc20"
Expand Down Expand Up @@ -296,13 +298,13 @@ func listKeys(*cobra.Command, []string) error {
if len(subnets) == 0 {
subnets = []string{"p", "x", "c"}
}
if !utils.Belongs(subnets, "p") {
if !sdkUtils.Belongs(subnets, "p") {
pchain = false
}
if !utils.Belongs(subnets, "x") {
if !sdkUtils.Belongs(subnets, "x") {
xchain = false
}
if !utils.Belongs(subnets, "c") {
if !sdkUtils.Belongs(subnets, "c") {
cchain = false
}
queryLedger := len(ledgerIndices) > 0
Expand All @@ -311,7 +313,7 @@ func listKeys(*cobra.Command, []string) error {
cchain = false
xchain = false
}
if utils.Belongs(tokenAddresses, "Native") || utils.Belongs(tokenAddresses, "native") {
if sdkUtils.Belongs(tokenAddresses, "Native") || sdkUtils.Belongs(tokenAddresses, "native") {
showNativeToken = true
}
tokenAddresses = utils.RemoveFromSlice(tokenAddresses, "Native")
Expand Down Expand Up @@ -347,7 +349,7 @@ func getStoredKeysInfo(
return nil, err
}
if len(keys) != 0 {
keyNames = utils.Filter(keyNames, func(keyName string) bool { return utils.Belongs(keys, keyName) })
keyNames = utils.Filter(keyNames, func(keyName string) bool { return sdkUtils.Belongs(keys, keyName) })
}
addrInfos := []addressInfo{}
for _, keyName := range keyNames {
Expand Down
4 changes: 2 additions & 2 deletions pkg/contract/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"strings"

"github.com/ava-labs/avalanche-cli/pkg/evm"
"github.com/ava-labs/avalanche-cli/pkg/utils"
"github.com/ava-labs/avalanche-cli/pkg/ux"
sdkUtils "github.com/ava-labs/avalanche-cli/sdk/utils"
avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp"
"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/subnet-evm/core/types"
Expand Down Expand Up @@ -252,7 +252,7 @@ func ParseSpec(
}
if event {
for i := range inputsMaps {
if utils.Belongs(indexedFields, i) {
if sdkUtils.Belongs(indexedFields, i) {
inputsMaps[i]["indexed"] = true
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/node/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/ava-labs/avalanche-cli/pkg/vm"
"github.com/ava-labs/avalanche-cli/sdk/network"
"github.com/ava-labs/avalanche-cli/sdk/publicarchive"
sdkUtils "github.com/ava-labs/avalanche-cli/sdk/utils"
"github.com/ava-labs/avalanche-network-runner/rpcpb"
"github.com/ava-labs/avalanchego/api/info"
"github.com/ava-labs/avalanchego/utils/logging"
Expand Down Expand Up @@ -196,7 +197,7 @@ func getPublicEndpoints(
publicNodes = clusterConfig.Nodes
}
publicTrackers := utils.Filter(trackers, func(tracker *models.Host) bool {
return utils.Belongs(publicNodes, tracker.GetCloudID())
return sdkUtils.Belongs(publicNodes, tracker.GetCloudID())
})
endpoints := utils.Map(publicTrackers, func(tracker *models.Host) string {
return GetAvalancheGoEndpoint(tracker.IP)
Expand Down
9 changes: 0 additions & 9 deletions pkg/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,6 @@ func Find[T any](input []T, f func(T) bool) *T {
return nil
}

func Belongs[T comparable](input []T, elem T) bool {
for _, e := range input {
if e == elem {
return true
}
}
return false
}

func RemoveFromSlice[T comparable](input []T, toRemove T) []T {
output := make([]T, 0, len(input))
for _, e := range input {
Expand Down
9 changes: 5 additions & 4 deletions pkg/vm/allowlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (

"github.com/ava-labs/avalanche-cli/pkg/application"
"github.com/ava-labs/avalanche-cli/pkg/utils"

sdkUtils "github.com/ava-labs/avalanche-cli/sdk/utils"
"github.com/ava-labs/avalanchego/utils/logging"

"github.com/ethereum/go-ethereum/common"
"github.com/olekukonko/tablewriter"
"golang.org/x/mod/semver"
Expand Down Expand Up @@ -58,11 +59,11 @@ func getNewAddresses(
}
for _, address := range addresses {
switch {
case utils.Belongs(allowList.AdminAddresses, address):
case sdkUtils.Belongs(allowList.AdminAddresses, address):
fmt.Println(address.Hex() + " is already allowed as admin role")
case utils.Belongs(allowList.ManagerAddresses, address):
case sdkUtils.Belongs(allowList.ManagerAddresses, address):
fmt.Println(address.Hex() + " is already allowed as manager role")
case utils.Belongs(allowList.EnabledAddresses, address):
case sdkUtils.Belongs(allowList.EnabledAddresses, address):
fmt.Println(address.Hex() + " is already allowed as enabled role")
default:
newAddresses = append(newAddresses, address)
Expand Down
9 changes: 5 additions & 4 deletions pkg/vm/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package vm

import (
"github.com/ava-labs/avalanche-cli/pkg/utils"
sdkUtils "github.com/ava-labs/avalanche-cli/sdk/utils"
"github.com/ava-labs/subnet-evm/params"
"github.com/ava-labs/subnet-evm/precompile/allowlist"
"github.com/ava-labs/subnet-evm/precompile/contracts/deployerallowlist"
Expand All @@ -14,6 +14,7 @@ import (
"github.com/ava-labs/subnet-evm/precompile/contracts/txallowlist"
"github.com/ava-labs/subnet-evm/precompile/contracts/warp"
"github.com/ava-labs/subnet-evm/precompile/precompileconfig"

"github.com/ethereum/go-ethereum/common"
)

Expand Down Expand Up @@ -151,19 +152,19 @@ func addAddressToAllowed(
) allowlist.AllowListConfig {
address := common.HexToAddress(addressStr)
allowed := false
if utils.Belongs(
if sdkUtils.Belongs(
allowListConfig.AdminAddresses,
address,
) {
allowed = true
}
if utils.Belongs(
if sdkUtils.Belongs(
allowListConfig.ManagerAddresses,
address,
) {
allowed = true
}
if utils.Belongs(
if sdkUtils.Belongs(
allowListConfig.EnabledAddresses,
address,
) {
Expand Down
9 changes: 9 additions & 0 deletions sdk/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ func Unique[T comparable](arr []T) []T {
return unique
}

func Belongs[T comparable](input []T, elem T) bool {
for _, e := range input {
if e == elem {
return true
}
}
return false
}

func Uint32Sort(arr []uint32) {
sort.Slice(arr, func(i, j int) bool { return arr[i] < arr[j] })
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/validatormanager/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"fmt"

"github.com/ava-labs/avalanche-cli/pkg/contract"
"github.com/ava-labs/avalanche-cli/pkg/utils"
"github.com/ava-labs/avalanche-cli/sdk/network"
"github.com/ava-labs/avalanche-cli/sdk/utils"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/vms/platformvm"
"github.com/ava-labs/avalanchego/vms/platformvm/api"
Expand Down

0 comments on commit 9e30764

Please sign in to comment.