diff --git a/cmd/interchaincmd/relayercmd/logs.go b/cmd/interchaincmd/relayercmd/logs.go index bf8833dbb..1be5bcb46 100644 --- a/cmd/interchaincmd/relayercmd/logs.go +++ b/cmd/interchaincmd/relayercmd/logs.go @@ -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" @@ -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, diff --git a/cmd/keycmd/list.go b/cmd/keycmd/list.go index b7a0d41be..b8b166805 100644 --- a/cmd/keycmd/list.go +++ b/cmd/keycmd/list.go @@ -14,6 +14,7 @@ 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" @@ -21,6 +22,7 @@ import ( "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" @@ -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 @@ -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") @@ -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 { diff --git a/pkg/contract/contract.go b/pkg/contract/contract.go index 5a2608159..56a36009b 100644 --- a/pkg/contract/contract.go +++ b/pkg/contract/contract.go @@ -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" @@ -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 } } diff --git a/pkg/node/helper.go b/pkg/node/helper.go index 47b96819f..8d749d3c7 100644 --- a/pkg/node/helper.go +++ b/pkg/node/helper.go @@ -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" @@ -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) diff --git a/pkg/utils/common.go b/pkg/utils/common.go index 008ba5e94..8996a13a1 100644 --- a/pkg/utils/common.go +++ b/pkg/utils/common.go @@ -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 { diff --git a/pkg/vm/allowlist.go b/pkg/vm/allowlist.go index 53851a1bb..fa1404734 100644 --- a/pkg/vm/allowlist.go +++ b/pkg/vm/allowlist.go @@ -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" @@ -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) diff --git a/pkg/vm/precompiles.go b/pkg/vm/precompiles.go index fbd79bdab..6360f698a 100644 --- a/pkg/vm/precompiles.go +++ b/pkg/vm/precompiles.go @@ -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" @@ -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" ) @@ -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, ) { diff --git a/sdk/utils/utils.go b/sdk/utils/utils.go index 470705a01..35c4e0542 100644 --- a/sdk/utils/utils.go +++ b/sdk/utils/utils.go @@ -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] }) } diff --git a/sdk/validatormanager/helpers.go b/sdk/validatormanager/helpers.go index 75d6fadb7..db02a1e9c 100644 --- a/sdk/validatormanager/helpers.go +++ b/sdk/validatormanager/helpers.go @@ -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"