-
Notifications
You must be signed in to change notification settings - Fork 43
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As in the previous files, consider handling errors from - panic(err)
+ fmt.Println("Failed to create Tendermint HTTP client:", err)
+ return Committable suggestion
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace - panic(err)
+ fmt.Println("Error initializing Cosmos keyring:", err)
+ return Committable suggestion
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// initialize grpc client | ||||||||||||||||
clientCtx, err := chainclient.NewClientContext( | ||||||||||||||||
network.ChainId, | ||||||||||||||||
senderAddress.String(), | ||||||||||||||||
cosmosKeyring, | ||||||||||||||||
) | ||||||||||||||||
if err != nil { | ||||||||||||||||
panic(err) | ||||||||||||||||
} | ||||||||||||||||
Comment on lines
+45
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a more graceful error handling strategy instead of - panic(err)
+ fmt.Println("Error creating client context:", err)
+ return Committable suggestion
Suggested change
|
||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using - panic(err)
+ fmt.Println("Error creating chain client:", err)
+ return Committable suggestion
Suggested change
|
||||||||||||||||
|
||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error from if err != nil {
+ fmt.Println("Failed to broadcast IBC transfer message:", err)
+ return
- panic(err)
} Committable suggestion
Suggested change
|
||||||||||||||||
|
||||||||||||||||
str, _ := json.MarshalIndent(response, "", " ") | ||||||||||||||||
fmt.Print(string(str)) | ||||||||||||||||
} |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As in the previous files, consider handling errors from - panic(err)
+ fmt.Println("Failed to create Tendermint HTTP client:", err)
+ return Committable suggestion
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace - panic(err)
+ fmt.Println("Error initializing Cosmos keyring:", err)
+ return Committable suggestion
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
clientCtx, err := chainclient.NewClientContext( | ||||||||||||||||
network.ChainId, | ||||||||||||||||
senderAddress.String(), | ||||||||||||||||
cosmosKeyring, | ||||||||||||||||
) | ||||||||||||||||
|
||||||||||||||||
if err != nil { | ||||||||||||||||
panic(err) | ||||||||||||||||
Comment on lines
+45
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a more graceful error handling strategy instead of - panic(err)
+ fmt.Println("Error creating client context:", err)
+ return Committable suggestion
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using - panic(err)
+ fmt.Println("Error creating chain client:", err)
+ return Committable suggestion
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error from if err != nil {
+ fmt.Println("Failed to fetch denomination trace:", err)
+ return
- fmt.Println(err)
} Committable suggestion
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
str, _ := json.MarshalIndent(res, "", " ") | ||||||||||||||||
fmt.Print(string(str)) | ||||||||||||||||
|
||||||||||||||||
} |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As in the previous files, consider handling errors from - panic(err)
+ fmt.Println("Failed to create Tendermint HTTP client:", err)
+ return Committable suggestion
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace - panic(err)
+ fmt.Println("Error initializing Cosmos keyring:", err)
+ return Committable suggestion
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
clientCtx, err := chainclient.NewClientContext( | ||||||||||||||||
network.ChainId, | ||||||||||||||||
senderAddress.String(), | ||||||||||||||||
cosmosKeyring, | ||||||||||||||||
) | ||||||||||||||||
|
||||||||||||||||
if err != nil { | ||||||||||||||||
panic(err) | ||||||||||||||||
Comment on lines
+44
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a more graceful error handling strategy instead of - panic(err)
+ fmt.Println("Error creating client context:", err)
+ return Committable suggestion
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using - panic(err)
+ fmt.Println("Error creating chain client:", err)
+ return Committable suggestion
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error from if err != nil {
+ fmt.Println("Failed to fetch denomination traces:", err)
+ return
- fmt.Println(err)
} Committable suggestion
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
str, _ := json.MarshalIndent(res, "", " ") | ||||||||||||||||
fmt.Print(string(str)) | ||||||||||||||||
|
||||||||||||||||
} |
There was a problem hiding this comment.
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 usingcommon.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 useerrors.Wrap
orerrors.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 thechain.go
file, whereerrors.Wrap
anderrors.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
orerrors.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
anderrors.Wrapf
in thechain.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 useerrors.Wrap
orerrors.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
anderrors.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:
Length of output: 5524
Script:
Length of output: 3627