Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/add_ibc_transfer_support #216

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 68 additions & 10 deletions client/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"sync/atomic"
"time"

ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"

"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"

distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
Expand Down Expand Up @@ -243,6 +245,13 @@ type ChainClient interface {
FetchValidatorSetByHeight(ctx context.Context, height int64, pagination *query.PageRequest) (*tmservice.GetValidatorSetByHeightResponse, error)
ABCIQuery(ctx context.Context, path string, data []byte, height int64, prove bool) (*tmservice.ABCIQueryResponse, error)

// IBC Transfer module
FetchDenomTrace(ctx context.Context, hash string) (*ibctransfertypes.QueryDenomTraceResponse, error)
FetchDenomTraces(ctx context.Context, pagination *query.PageRequest) (*ibctransfertypes.QueryDenomTracesResponse, error)
FetchDenomHash(ctx context.Context, trace string) (*ibctransfertypes.QueryDenomHashResponse, error)
FetchEscrowAddress(ctx context.Context, portId string, channelId string) (*ibctransfertypes.QueryEscrowAddressResponse, error)
FetchTotalEscrowForDenom(ctx context.Context, denom string) (*ibctransfertypes.QueryTotalEscrowForDenomResponse, error)
Comment on lines +248 to +253
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The output from the script provides the implementation details for the new IBC Transfer methods in the chain.go file. Each method constructs a request, executes it using common.ExecuteCall, and returns the response along with any error that might have occurred during the call. Notably, the error handling in these methods does not use errors.Wrap or errors.Wrapf to add additional context to the errors before returning them. This is a deviation from the error handling pattern observed in other parts of the chain.go file, where errors.Wrap and errors.Wrapf are frequently used to enhance error messages.

Given this information, it appears that the new IBC Transfer methods do not follow the established pattern of error handling seen in the rest of the file. This could potentially lead to less informative error messages, which might hinder debugging and maintenance efforts.

Based on the findings, the review comment about ensuring proper error handling and context propagation in the new IBC Transfer methods is justified. The methods should ideally incorporate errors.Wrap or errors.Wrapf to maintain consistency with the rest of the file and to improve the clarity and traceability of errors.

Analysis chain

Ensure proper error handling and context propagation in new IBC Transfer methods.


The output from the executed script shows several instances of error handling using errors.Wrap and errors.Wrapf in the chain.go file. These instances are used to add additional context to errors before they are returned, which is a common practice for improving error traceability and debugging in Go.

From the output, it's evident that the existing methods in chain.go consistently use errors.Wrap or errors.Wrapf for error handling. This pattern enriches the error messages with more context, which can be very helpful during debugging and logging.

However, the script output does not directly show the error handling within the newly added IBC Transfer methods. To fully verify the review comment regarding proper error handling and context propagation in these new methods, we would need to inspect the implementation of these methods specifically.

Since the script focused on general usage of errors.Wrap and errors.Wrapf in the file and did not isolate the new methods, I will need to run a more targeted script to examine the error handling within the new IBC Transfer methods specifically.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that error handling is consistent with other methods in the same file.
rg --type go --context 5 "errors.Wrap" client/chain/chain.go

Length of output: 5524



Script:

#!/bin/bash
# Extract the implementation of the new IBC Transfer methods to verify error handling
rg --type go --context 10 "FetchDenomTrace|FetchDenomTraces|FetchDenomHash|FetchEscrowAddress|FetchTotalEscrowForDenom" client/chain/chain.go

Length of output: 3627


Close()
}

Expand All @@ -269,16 +278,17 @@ type chainClient struct {

sessionEnabled bool

txClient txtypes.ServiceClient
authQueryClient authtypes.QueryClient
exchangeQueryClient exchangetypes.QueryClient
bankQueryClient banktypes.QueryClient
authzQueryClient authztypes.QueryClient
wasmQueryClient wasmtypes.QueryClient
bankQueryClient banktypes.QueryClient
chainStreamClient chainstreamtypes.StreamClient
tokenfactoryQueryClient tokenfactorytypes.QueryClient
distributionQueryClient distributiontypes.QueryClient
exchangeQueryClient exchangetypes.QueryClient
ibcTransferQueryClient ibctransfertypes.QueryClient
tendermintQueryClient tmservice.ServiceClient
tokenfactoryQueryClient tokenfactorytypes.QueryClient
txClient txtypes.ServiceClient
wasmQueryClient wasmtypes.QueryClient
subaccountToNonce map[ethcommon.Hash]uint32

closed int64
Expand Down Expand Up @@ -365,16 +375,17 @@ func NewChainClient(

sessionEnabled: stickySessionEnabled,

txClient: txtypes.NewServiceClient(conn),
authQueryClient: authtypes.NewQueryClient(conn),
exchangeQueryClient: exchangetypes.NewQueryClient(conn),
bankQueryClient: banktypes.NewQueryClient(conn),
authzQueryClient: authztypes.NewQueryClient(conn),
wasmQueryClient: wasmtypes.NewQueryClient(conn),
bankQueryClient: banktypes.NewQueryClient(conn),
chainStreamClient: chainstreamtypes.NewStreamClient(chainStreamConn),
tokenfactoryQueryClient: tokenfactorytypes.NewQueryClient(conn),
distributionQueryClient: distributiontypes.NewQueryClient(conn),
exchangeQueryClient: exchangetypes.NewQueryClient(conn),
ibcTransferQueryClient: ibctransfertypes.NewQueryClient(conn),
tendermintQueryClient: tmservice.NewServiceClient(conn),
tokenfactoryQueryClient: tokenfactorytypes.NewQueryClient(conn),
txClient: txtypes.NewServiceClient(conn),
wasmQueryClient: wasmtypes.NewQueryClient(conn),
subaccountToNonce: make(map[ethcommon.Hash]uint32),
}

Expand Down Expand Up @@ -2255,3 +2266,50 @@ func (c *chainClient) ABCIQuery(ctx context.Context, path string, data []byte, h

return res, err
}

// IBC Transfer module
func (c *chainClient) FetchDenomTrace(ctx context.Context, hash string) (*ibctransfertypes.QueryDenomTraceResponse, error) {
req := &ibctransfertypes.QueryDenomTraceRequest{
Hash: hash,
}
res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcTransferQueryClient.DenomTrace, req)

return res, err
}

func (c *chainClient) FetchDenomTraces(ctx context.Context, pagination *query.PageRequest) (*ibctransfertypes.QueryDenomTracesResponse, error) {
req := &ibctransfertypes.QueryDenomTracesRequest{
Pagination: pagination,
}
res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcTransferQueryClient.DenomTraces, req)

return res, err
}

func (c *chainClient) FetchDenomHash(ctx context.Context, trace string) (*ibctransfertypes.QueryDenomHashResponse, error) {
req := &ibctransfertypes.QueryDenomHashRequest{
Trace: trace,
}
res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcTransferQueryClient.DenomHash, req)

return res, err
}

func (c *chainClient) FetchEscrowAddress(ctx context.Context, portId string, channelId string) (*ibctransfertypes.QueryEscrowAddressResponse, error) {
req := &ibctransfertypes.QueryEscrowAddressRequest{
PortId: portId,
ChannelId: channelId,
}
res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcTransferQueryClient.EscrowAddress, req)

return res, err
}

func (c *chainClient) FetchTotalEscrowForDenom(ctx context.Context, denom string) (*ibctransfertypes.QueryTotalEscrowForDenomResponse, error) {
req := &ibctransfertypes.QueryTotalEscrowForDenomRequest{
Denom: denom,
}
res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcTransferQueryClient.TotalEscrowForDenom, req)

return res, err
}
23 changes: 23 additions & 0 deletions client/chain/chain_test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"errors"
"time"

ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"

"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"

distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
Expand Down Expand Up @@ -578,3 +580,24 @@ func (c *MockChainClient) FetchValidatorSetByHeight(ctx context.Context, height
func (c *MockChainClient) ABCIQuery(ctx context.Context, path string, data []byte, height int64, prove bool) (*tmservice.ABCIQueryResponse, error) {
return &tmservice.ABCIQueryResponse{}, nil
}

// IBC Transfer module
func (c *MockChainClient) FetchDenomTrace(ctx context.Context, hash string) (*ibctransfertypes.QueryDenomTraceResponse, error) {
return &ibctransfertypes.QueryDenomTraceResponse{}, nil
}

func (c *MockChainClient) FetchDenomTraces(ctx context.Context, pagination *query.PageRequest) (*ibctransfertypes.QueryDenomTracesResponse, error) {
return &ibctransfertypes.QueryDenomTracesResponse{}, nil
}

func (c *MockChainClient) FetchDenomHash(ctx context.Context, trace string) (*ibctransfertypes.QueryDenomHashResponse, error) {
return &ibctransfertypes.QueryDenomHashResponse{}, nil
}

func (c *MockChainClient) FetchEscrowAddress(ctx context.Context, portId string, channelId string) (*ibctransfertypes.QueryEscrowAddressResponse, error) {
return &ibctransfertypes.QueryEscrowAddressResponse{}, nil
}

func (c *MockChainClient) FetchTotalEscrowForDenom(ctx context.Context, denom string) (*ibctransfertypes.QueryTotalEscrowForDenomResponse, error) {
return &ibctransfertypes.QueryTotalEscrowForDenomResponse{}, nil
}
87 changes: 87 additions & 0 deletions examples/chain/ibc/transfer/1_MsgTransfer/example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package main

import (
"encoding/json"
"fmt"
"os"

"github.com/InjectiveLabs/sdk-go/client"
"github.com/InjectiveLabs/sdk-go/client/common"

chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
sdktypes "github.com/cosmos/cosmos-sdk/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibccoretypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
)

func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
Comment on lines +20 to +22
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in the previous files, consider handling errors from rpchttp.New more gracefully instead of using panic. This could improve the robustness of the example.

- panic(err)
+ fmt.Println("Failed to create Tendermint HTTP client:", err)
+ return

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
fmt.Println("Failed to create Tendermint HTTP client:", err)
return

}

senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
false,
)

if err != nil {
panic(err)
Comment on lines +34 to +36
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace panic with a more graceful error handling approach in the InitCosmosKeyring error check. This will make the example more robust and user-friendly.

- panic(err)
+ fmt.Println("Error initializing Cosmos keyring:", err)
+ return

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err != nil {
panic(err)
if err != nil {
fmt.Println("Error initializing Cosmos keyring:", err)
return

}

// initialize grpc client
clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)
if err != nil {
panic(err)
}
Comment on lines +45 to +47
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a more graceful error handling strategy instead of panic when an error occurs in NewClientContext. This enhances the example's usability and error reporting.

- panic(err)
+ fmt.Println("Error creating client context:", err)
+ return

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err != nil {
panic(err)
}
if err != nil {
fmt.Println("Error creating client context:", err)
return
}

clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)

chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)

if err != nil {
panic(err)
}
Comment on lines +56 to +58
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using panic for handling errors returned from NewChainClient. Consider logging the error and returning from the function to improve error management.

- panic(err)
+ fmt.Println("Error creating chain client:", err)
+ return

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err != nil {
panic(err)
}
if err != nil {
fmt.Println("Error creating chain client:", err)
return
}


sourcePort := "transfer"
sourceChannel := "channel-126"
coin := sdktypes.Coin{
Denom: "inj", Amount: sdktypes.NewInt(1000000000000000000), // 1 INJ
}
sender := senderAddress.String()
receiver := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
timeoutHeight := ibccoretypes.Height{RevisionNumber: 10, RevisionHeight: 10}

msg := &ibctransfertypes.MsgTransfer{
SourcePort: sourcePort,
SourceChannel: sourceChannel,
Token: coin,
Sender: sender,
Receiver: receiver,
TimeoutHeight: timeoutHeight,
}

//AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg
response, err := chainClient.AsyncBroadcastMsg(msg)

if err != nil {
panic(err)
}
Comment on lines +81 to +83
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error from AsyncBroadcastMsg is being printed but not handled further. Consider adding error handling logic, such as retrying the request or terminating the program if necessary.

if err != nil {
+   fmt.Println("Failed to broadcast IBC transfer message:", err)
+   return
-   panic(err)
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err != nil {
panic(err)
}
if err != nil {
fmt.Println("Failed to broadcast IBC transfer message:", err)
return
}


str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
}
76 changes: 76 additions & 0 deletions examples/chain/ibc/transfer/query/1_DenomTrace/example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package main

import (
"context"
"encoding/json"
"fmt"

"github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"

"github.com/InjectiveLabs/sdk-go/client"

chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"

"os"
)

func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
Comment on lines +21 to +23
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in the previous files, consider handling errors from rpchttp.New more gracefully instead of using panic. This could improve the robustness of the example.

- panic(err)
+ fmt.Println("Failed to create Tendermint HTTP client:", err)
+ return

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
fmt.Println("Failed to create Tendermint HTTP client:", err)
return

}

senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
false,
)

if err != nil {
panic(err)
Comment on lines +35 to +37
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace panic with a more graceful error handling approach in the InitCosmosKeyring error check. This will make the example more robust and user-friendly.

- panic(err)
+ fmt.Println("Error initializing Cosmos keyring:", err)
+ return

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err != nil {
panic(err)
if err != nil {
fmt.Println("Error initializing Cosmos keyring:", err)
return

}

clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)

if err != nil {
panic(err)
Comment on lines +45 to +47
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a more graceful error handling strategy instead of panic when an error occurs in NewClientContext. This enhances the example's usability and error reporting.

- panic(err)
+ fmt.Println("Error creating client context:", err)
+ return

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err != nil {
panic(err)
if err != nil {
fmt.Println("Error creating client context:", err)
return

}

clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)

chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)

if err != nil {
panic(err)
Comment on lines +57 to +59
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using panic for handling errors returned from NewChainClient. Consider logging the error and returning from the function to improve error management.

- panic(err)
+ fmt.Println("Error creating chain client:", err)
+ return

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err != nil {
panic(err)
if err != nil {
fmt.Println("Error creating chain client:", err)
return

}

denomTrace := types.DenomTrace{
Path: "transfer/channel-126",
BaseDenom: "uluna",
}
ctx := context.Background()

res, err := chainClient.FetchDenomTrace(ctx, denomTrace.Hash().String())
if err != nil {
fmt.Println(err)
Comment on lines +68 to +70
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error from FetchDenomTrace is being printed but not handled further. Consider adding error handling logic, such as retrying the request or terminating the program if necessary.

if err != nil {
+   fmt.Println("Failed to fetch denomination trace:", err)
+   return
-   fmt.Println(err)
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
res, err := chainClient.FetchDenomTrace(ctx, denomTrace.Hash().String())
if err != nil {
fmt.Println(err)
res, err := chainClient.FetchDenomTrace(ctx, denomTrace.Hash().String())
if err != nil {
fmt.Println("Failed to fetch denomination trace:", err)
return

}

str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))

}
72 changes: 72 additions & 0 deletions examples/chain/ibc/transfer/query/2_DenomTraces/example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package main

import (
"context"
"encoding/json"
"fmt"

"github.com/InjectiveLabs/sdk-go/client"
"github.com/cosmos/cosmos-sdk/types/query"

chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"

"os"
)

func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
Comment on lines +20 to +22
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in the previous files, consider handling errors from rpchttp.New more gracefully instead of using panic. This could improve the robustness of the example.

- panic(err)
+ fmt.Println("Failed to create Tendermint HTTP client:", err)
+ return

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
fmt.Println("Failed to create Tendermint HTTP client:", err)
return

}

senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
false,
)

if err != nil {
panic(err)
Comment on lines +34 to +36
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace panic with a more graceful error handling approach in the InitCosmosKeyring error check. This will make the example more robust and user-friendly.

- panic(err)
+ fmt.Println("Error initializing Cosmos keyring:", err)
+ return

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err != nil {
panic(err)
if err != nil {
fmt.Println("Error initializing Cosmos keyring:", err)
return

}

clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)

if err != nil {
panic(err)
Comment on lines +44 to +46
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a more graceful error handling strategy instead of panic when an error occurs in NewClientContext. This enhances the example's usability and error reporting.

- panic(err)
+ fmt.Println("Error creating client context:", err)
+ return

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err != nil {
panic(err)
if err != nil {
fmt.Println("Error creating client context:", err)
return

}

clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)

chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)

if err != nil {
panic(err)
Comment on lines +56 to +58
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using panic for handling errors returned from NewChainClient. Consider logging the error and returning from the function to improve error management.

- panic(err)
+ fmt.Println("Error creating chain client:", err)
+ return

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err != nil {
panic(err)
if err != nil {
fmt.Println("Error creating chain client:", err)
return

}

pagination := query.PageRequest{Offset: 2, Limit: 4}
ctx := context.Background()

res, err := chainClient.FetchDenomTraces(ctx, &pagination)
if err != nil {
fmt.Println(err)
Comment on lines +64 to +66
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error from FetchDenomTraces is being printed but not handled further. Consider adding error handling logic, such as retrying the request or terminating the program if necessary.

if err != nil {
+   fmt.Println("Failed to fetch denomination traces:", err)
+   return
-   fmt.Println(err)
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
res, err := chainClient.FetchDenomTraces(ctx, &pagination)
if err != nil {
fmt.Println(err)
res, err := chainClient.FetchDenomTraces(ctx, &pagination)
if err != nil {
fmt.Println("Failed to fetch denomination traces:", err)
return

}

str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))

}
Loading
Loading