Skip to content

Commit

Permalink
fix(chain): remove network enum
Browse files Browse the repository at this point in the history
Per discussion, having to update the network enum in order to support new network type might be too strict in future

JIRA: https://smartcontract-it.atlassian.net/browse/DPA-1151
  • Loading branch information
graham-chainlink committed Oct 29, 2024
1 parent 75ac36a commit a58e3e5
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 33 deletions.
12 changes: 0 additions & 12 deletions core/services/relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ package relay
import (
"context"
"fmt"
"strings"

"github.com/smartcontractkit/chainlink-common/pkg/loop"
"github.com/smartcontractkit/chainlink-common/pkg/types"
)

type NetworkType string

const (
NetworkEVM = "evm"
NetworkCosmos = "cosmos"
Expand All @@ -31,15 +28,6 @@ var SupportedNetworks = map[string]struct{}{
NetworkDummy: {},
}

// From returns a NetworkType from a string.
func From(s string) (NetworkType, error) {
s = strings.ToLower(s)
if _, ok := SupportedNetworks[s]; !ok {
return "", fmt.Errorf("unknown network type: %s", s)
}
return NetworkType(s), nil
}

var _ loop.Relayer = (*ServerAdapter)(nil)

// ServerAdapter extends [loop.RelayerAdapter] by overriding NewPluginProvider to dispatches calls according to `RelayArgs.ProviderType`.
Expand Down
2 changes: 1 addition & 1 deletion core/web/loader/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type chainBatcher struct {
app chainlink.Application
}

// DEPRECATED: loadByChainIDs is deprecated and we should be using loadByRelayIDs.
// Deprecated: use loadByChainIDs is deprecated and we should be using loadByRelayIDs.
func (b *chainBatcher) loadByIDs(ctx context.Context, keys dataloader.Keys) []*dataloader.Result {
// Create a map for remembering the order of keys passed in
keyOrder := make(map[string]int, len(keys))
Expand Down
2 changes: 1 addition & 1 deletion core/web/loader/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
var ErrInvalidType = errors.New("invalid type")

// GetChainByID fetches the chain by it's id.
// DEPRECATED: use GetChainByRelayID.
// Deprecated: use GetChainByRelayID.
func GetChainByID(ctx context.Context, id string) (*commonTypes.ChainStatusWithID, error) {
ldr := For(ctx)

Expand Down
5 changes: 2 additions & 3 deletions core/web/resolver/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"
"testing"

gqlerrors "github.com/graph-gophers/graphql-go/errors"
Expand Down Expand Up @@ -162,7 +161,7 @@ func TestResolver_Chain(t *testing.T) {
}
`
queryWithNetwork = `
query GetChain($network: Network) {
query GetChain($network: String) {
chain(id: "1", network: $network) {
... on Chain {
id
Expand Down Expand Up @@ -312,7 +311,7 @@ ResendAfterThreshold = '1h0m0s'
name: "should return aptos chain if network is aptos",
authenticated: true,
variables: map[string]interface{}{
"network": strings.ToUpper(relay.NetworkAptos),
"network": relay.NetworkAptos,
},
before: func(ctx context.Context, f *gqlTestFramework) {
chainConf := evmtoml.EVMConfig{
Expand Down
8 changes: 1 addition & 7 deletions core/web/resolver/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/vrfkey"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"
evmrelay "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
"github.com/smartcontractkit/chainlink/v2/core/utils/stringutils"
"github.com/smartcontractkit/chainlink/v2/core/web/loader"
Expand Down Expand Up @@ -86,12 +85,7 @@ func (r *Resolver) Chain(ctx context.Context,
return NewChainPayload(*id, nil), nil
}

networkToUse, err := relay.From(*args.Network)
if err != nil {
return NewChainPayload(commonTypes.ChainStatusWithID{}, chains.ErrNotFound), nil
}

relayID := types.NewRelayID(string(networkToUse), string(args.ID))
relayID := types.NewRelayID(*args.Network, string(args.ID))
id, err := loader.GetChainByRelayID(ctx, relayID.Name())
if err != nil {
if errors.Is(err, chains.ErrNotFound) {
Expand Down
2 changes: 1 addition & 1 deletion core/web/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ schema {
type Query {
bridge(id: ID!): BridgePayload!
bridges(offset: Int, limit: Int): BridgesPayload!
chain(id: ID!, network: Network): ChainPayload!
chain(id: ID!, network: String): ChainPayload!
chains(offset: Int, limit: Int): ChainsPayload!
configv2: ConfigV2Payload!
csaKeys: CSAKeysPayload!
Expand Down
8 changes: 0 additions & 8 deletions core/web/schema/type/chain.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,3 @@ type ChainsPayload implements PaginatedPayload {
results: [Chain!]!
metadata: PaginationMetadata!
}

enum Network {
EVM
COSMOS
SOLANA
STARKNET
APTOS
}

0 comments on commit a58e3e5

Please sign in to comment.