Skip to content

Commit

Permalink
(fix) Remove restrictions in SDK to not use with mainnet or testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
aarmoa committed Jul 26, 2024
1 parent 3bc09db commit d45b89b
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 7 deletions.
7 changes: 0 additions & 7 deletions client/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down Expand Up @@ -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")
Expand Down
96 changes: 96 additions & 0 deletions client/common/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"context"
"crypto/tls"
"fmt"
"net"
"net/http"
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit d45b89b

Please sign in to comment.