From d4d5104b394e6d95ff3ac85cec43b4542b102bd0 Mon Sep 17 00:00:00 2001 From: Phuc Ta <30641530+vinhphuctadang@users.noreply.github.com> Date: Tue, 29 Aug 2023 22:45:05 +0700 Subject: [PATCH] feat: update new sentry endpoints (#149) * feat: add sentry-related endpoints * chore: update some examples to use sentry endpoint * fix: update explorer endpoints * fix: revert some examples * fix: use https instead of dns:port --- client/chain/chain.go | 15 +++++++++++---- client/common/network.go | 14 ++++++++++++-- .../accounts/2_SubaccountBalance/example.go | 2 +- examples/explorer/1_GetTxByHash/example.go | 2 +- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/client/chain/chain.go b/client/chain/chain.go index e19298fa..0969c3e5 100644 --- a/client/chain/chain.go +++ b/client/chain/chain.go @@ -392,6 +392,7 @@ func (c *chainClient) fetchCookie(ctx context.Context) context.Context { c.txClient.GetTx(context.Background(), &txtypes.GetTxRequest{}, grpc.Header(&header)) c.setCookie(header) time.Sleep(defaultBlockTime) + return metadata.NewOutgoingContext(ctx, metadata.Pairs("cookie", c.sessionCookie)) } @@ -412,6 +413,10 @@ func (c *chainClient) getCookieExpirationTime(cookies []*http.Cookie) (time.Time expiresAt = strings.Replace(cookie.Value, "-", " ", -1) } else { cookie := cookieByName(cookies, "Expires") + if cookie == nil { + return time.Time{}, nil + } + expiresAt = strings.Replace(cookie.Value, "-", " ", -1) yyyy := fmt.Sprintf("20%s", expiresAt[12:14]) expiresAt = expiresAt[:12] + yyyy + expiresAt[14:] @@ -439,10 +444,12 @@ func (c *chainClient) getCookie(ctx context.Context) context.Context { panic(err) } - // renew session if timestamp diff < offset - timestampDiff := expiresTimestamp.Unix() - time.Now().Unix() - if timestampDiff < defaultSessionRenewalOffset { - return c.fetchCookie(ctx) + if !expiresTimestamp.IsZero() { + // renew session if timestamp diff < offset + timestampDiff := expiresTimestamp.Unix() - time.Now().Unix() + if timestampDiff < defaultSessionRenewalOffset { + return c.fetchCookie(ctx) + } } } else { return c.fetchCookie(ctx) diff --git a/client/common/network.go b/client/common/network.go index e9e0992e..2840d2a7 100644 --- a/client/common/network.go +++ b/client/common/network.go @@ -96,7 +96,7 @@ func LoadNetwork(name string, node string) Network { Name: "testnet", } case "mainnet": - validNodes := []string{"k8s", "lb", "sentry0", "sentry1", "sentry2", "sentry3"} + validNodes := []string{"k8s", "lb", "sentry", "sentry0", "sentry1", "sentry2", "sentry3"} if !contains(validNodes, node) { panic(fmt.Sprintf("invalid node %s for %s", node, name)) } @@ -122,6 +122,15 @@ func LoadNetwork(name string, node string) Network { explorerGrpcEndpoint = "tcp://k8s.mainnet.explorer.grpc.injective.network:443" exchangeTlsCert = credentials.NewServerTLSFromCert(&tls.Certificate{}) explorerTlsCert = LoadTlsCert(certPath, explorerGrpcEndpoint) + } else if node == "sentry" { + lcdEndpoint = "https://sentry.lcd.injective.network" + tmEndpoint = "http://sentry.tm.injective.network:26657" + chainGrpcEndpoint = "sentry.chain.grpc.injective.network:443" + exchangeGrpcEndpoint = "sentry.exchange.grpc.injective.network:443" + explorerGrpcEndpoint = "k8s.global.mainnet.explorer.grpc.injective.network:443" + chainTlsCert = credentials.NewTLS(&tls.Config{InsecureSkipVerify: false}) + exchangeTlsCert = credentials.NewTLS(&tls.Config{InsecureSkipVerify: false}) + explorerTlsCert = credentials.NewServerTLSFromCert(&tls.Certificate{}) } else { lcdEndpoint = fmt.Sprintf("http://%s.injective.network:10337", node) tmEndpoint = fmt.Sprintf("http://%s.injective.network:26657", node) @@ -131,7 +140,8 @@ func LoadNetwork(name string, node string) Network { if node == "sentry2" { explorerGrpcEndpoint = "tcp://sentry2.injective.network:9911" } else { - explorerGrpcEndpoint = "tcp://api.injective.network:9911" + explorerGrpcEndpoint = "k8s.global.mainnet.explorer.grpc.injective.network:443" + explorerTlsCert = credentials.NewServerTLSFromCert(&tls.Certificate{}) } } diff --git a/examples/exchange/accounts/2_SubaccountBalance/example.go b/examples/exchange/accounts/2_SubaccountBalance/example.go index 78ebac80..a81e96c2 100644 --- a/examples/exchange/accounts/2_SubaccountBalance/example.go +++ b/examples/exchange/accounts/2_SubaccountBalance/example.go @@ -11,7 +11,7 @@ import ( func main() { //network := common.LoadNetwork("mainnet", "k8s") - network := common.LoadNetwork("mainnet", "lb") + network := common.LoadNetwork("mainnet", "sentry") exchangeClient, err := exchangeclient.NewExchangeClient(network.ExchangeGrpcEndpoint, common.OptionTLSCert(network.ExchangeTlsCert)) if err != nil { panic(err) diff --git a/examples/explorer/1_GetTxByHash/example.go b/examples/explorer/1_GetTxByHash/example.go index eb03e0b4..833ca12e 100644 --- a/examples/explorer/1_GetTxByHash/example.go +++ b/examples/explorer/1_GetTxByHash/example.go @@ -10,7 +10,7 @@ import ( ) func main() { - network := common.LoadNetwork("testnet", "k8s") + network := common.LoadNetwork("mainnet", "sentry") explorerClient, err := explorerclient.NewExplorerClient(network.ExplorerGrpcEndpoint, common.OptionTLSCert(network.ExplorerTlsCert)) if err != nil { panic(err)