From d45b89b3673413b3a57a845aa1f6a5be1eaef7c8 Mon Sep 17 00:00:00 2001 From: Abel Armoa <30988000+aarmoa@users.noreply.github.com> Date: Fri, 26 Jul 2024 18:07:30 -0300 Subject: [PATCH] (fix) Remove restrictions in SDK to not use with mainnet or testnet --- client/chain/chain.go | 7 --- client/common/network.go | 96 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 7 deletions(-) diff --git a/client/chain/chain.go b/client/chain/chain.go index 4f6f8301..3f9f5a17 100644 --- a/client/chain/chain.go +++ b/client/chain/chain.go @@ -774,9 +774,6 @@ func (c *chainClient) BuildSignedTx(clientCtx client.Context, accNum, accSeq, in } func (c *chainClient) buildSignedTx(clientCtx client.Context, txf tx.Factory, msgs ...sdk.Msg) ([]byte, error) { - if c.network.ChainId != "injective-777" { - panic("This versions of Go SDK should only be used with Devnet environment") - } ctx := context.Background() if clientCtx.Simulate { simTxBytes, err := txf.BuildSimTx(msgs...) @@ -888,10 +885,6 @@ func (c *chainClient) broadcastTx( await bool, msgs ...sdk.Msg, ) (*txtypes.BroadcastTxResponse, error) { - if c.network.ChainId != "injective-777" { - panic("This versions of Go SDK should only be used with Devnet environment") - } - txBytes, err := c.buildSignedTx(clientCtx, txf, msgs...) if err != nil { err = errors.Wrap(err, "failed to build signed Tx") diff --git a/client/common/network.go b/client/common/network.go index e7b62672..4714f997 100644 --- a/client/common/network.go +++ b/client/common/network.go @@ -2,6 +2,7 @@ package common import ( "context" + "crypto/tls" "fmt" "net" "net/http" @@ -255,6 +256,101 @@ func LoadNetwork(name, node string) Network { ExplorerCookieAssistant: &DisabledCookieAssistant{}, OfficialTokensListURL: DevnetTokensListURL, } + case "testnet": + validNodes := []string{"lb", "sentry"} + if !contains(validNodes, node) { + panic(fmt.Sprintf("invalid node %s for %s", node, name)) + } + + var lcdEndpoint, tmEndpoint, chainGrpcEndpoint, chainStreamGrpcEndpoint, exchangeGrpcEndpoint, explorerGrpcEndpoint string + var chainTLSCert, exchangeTLSCert, explorerTLSCert credentials.TransportCredentials + var chainCookieAssistant, exchangeCookieAssistant, explorerCookieAssistant CookieAssistant + if node == "lb" { + lcdEndpoint = "https://testnet.sentry.lcd.injective.network:443" + tmEndpoint = "https://testnet.sentry.tm.injective.network:443" + chainGrpcEndpoint = "testnet.sentry.chain.grpc.injective.network:443" + chainStreamGrpcEndpoint = "testnet.sentry.chain.stream.injective.network:443" + exchangeGrpcEndpoint = "testnet.sentry.exchange.grpc.injective.network:443" + explorerGrpcEndpoint = "testnet.sentry.explorer.grpc.injective.network:443" + chainTLSCert = credentials.NewServerTLSFromCert(&tls.Certificate{}) + exchangeTLSCert = credentials.NewServerTLSFromCert(&tls.Certificate{}) + explorerTLSCert = credentials.NewServerTLSFromCert(&tls.Certificate{}) + chainCookieAssistant = &BareMetalLoadBalancedCookieAssistant{} + exchangeCookieAssistant = &BareMetalLoadBalancedCookieAssistant{} + explorerCookieAssistant = &BareMetalLoadBalancedCookieAssistant{} + } else if node == "sentry" { + lcdEndpoint = "https://testnet.lcd.injective.network:443" + tmEndpoint = "https://testnet.tm.injective.network:443" + chainGrpcEndpoint = "testnet.chain.grpc.injective.network:443" + chainStreamGrpcEndpoint = "testnet.chain.stream.injective.network:443" + exchangeGrpcEndpoint = "testnet.exchange.grpc.injective.network:443" + explorerGrpcEndpoint = "testnet.explorer.grpc.injective.network:443" + chainTLSCert = credentials.NewServerTLSFromCert(&tls.Certificate{}) + exchangeTLSCert = credentials.NewServerTLSFromCert(&tls.Certificate{}) + explorerTLSCert = credentials.NewServerTLSFromCert(&tls.Certificate{}) + chainCookieAssistant = &DisabledCookieAssistant{} + exchangeCookieAssistant = &DisabledCookieAssistant{} + explorerCookieAssistant = &DisabledCookieAssistant{} + } + + return Network{ + LcdEndpoint: lcdEndpoint, + TmEndpoint: tmEndpoint, + ChainGrpcEndpoint: chainGrpcEndpoint, + ChainStreamGrpcEndpoint: chainStreamGrpcEndpoint, + ChainTLSCert: chainTLSCert, + ExchangeGrpcEndpoint: exchangeGrpcEndpoint, + ExchangeTLSCert: exchangeTLSCert, + ExplorerGrpcEndpoint: explorerGrpcEndpoint, + ExplorerTLSCert: explorerTLSCert, + ChainId: "injective-888", + FeeDenom: "inj", + Name: "testnet", + ChainCookieAssistant: chainCookieAssistant, + ExchangeCookieAssistant: exchangeCookieAssistant, + ExplorerCookieAssistant: explorerCookieAssistant, + OfficialTokensListURL: TestnetTokensListURL, + } + case "mainnet": + validNodes := []string{"lb"} + if !contains(validNodes, node) { + panic(fmt.Sprintf("invalid node %s for %s", node, name)) + } + var lcdEndpoint, tmEndpoint, chainGrpcEndpoint, chainStreamGrpcEndpoint, exchangeGrpcEndpoint, explorerGrpcEndpoint string + var chainTLSCert, exchangeTLSCert, explorerTLSCert credentials.TransportCredentials + var chainCookieAssistant, exchangeCookieAssistant, explorerCookieAssistant CookieAssistant + + lcdEndpoint = "https://sentry.lcd.injective.network" + tmEndpoint = "https://sentry.tm.injective.network:443" + chainGrpcEndpoint = "sentry.chain.grpc.injective.network:443" + chainStreamGrpcEndpoint = "sentry.chain.stream.injective.network:443" + exchangeGrpcEndpoint = "sentry.exchange.grpc.injective.network:443" + explorerGrpcEndpoint = "sentry.explorer.grpc.injective.network:443" + chainTLSCert = credentials.NewServerTLSFromCert(&tls.Certificate{}) + exchangeTLSCert = credentials.NewServerTLSFromCert(&tls.Certificate{}) + explorerTLSCert = credentials.NewServerTLSFromCert(&tls.Certificate{}) + chainCookieAssistant = &BareMetalLoadBalancedCookieAssistant{} + exchangeCookieAssistant = &BareMetalLoadBalancedCookieAssistant{} + explorerCookieAssistant = &BareMetalLoadBalancedCookieAssistant{} + + return Network{ + LcdEndpoint: lcdEndpoint, + TmEndpoint: tmEndpoint, + ChainGrpcEndpoint: chainGrpcEndpoint, + ChainStreamGrpcEndpoint: chainStreamGrpcEndpoint, + ChainTLSCert: chainTLSCert, + ExchangeGrpcEndpoint: exchangeGrpcEndpoint, + ExchangeTLSCert: exchangeTLSCert, + ExplorerGrpcEndpoint: explorerGrpcEndpoint, + ExplorerTLSCert: explorerTLSCert, + ChainId: "injective-1", + FeeDenom: "inj", + Name: "mainnet", + ChainCookieAssistant: chainCookieAssistant, + ExchangeCookieAssistant: exchangeCookieAssistant, + ExplorerCookieAssistant: explorerCookieAssistant, + OfficialTokensListURL: MainnetTokensListURL, + } default: panic(fmt.Sprintf("invalid network %s", name))