Skip to content

Commit

Permalink
feat: update new sentry endpoints (#149)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vinhphuctadang committed Aug 29, 2023
1 parent 8049158 commit d4d5104
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
15 changes: 11 additions & 4 deletions client/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand All @@ -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:]
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 12 additions & 2 deletions client/common/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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)
Expand All @@ -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{})
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/exchange/accounts/2_SubaccountBalance/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/explorer/1_GetTxByHash/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d4d5104

Please sign in to comment.