-
Notifications
You must be signed in to change notification settings - Fork 46
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/ibc_connection_module_queries #219
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,71 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"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) | ||
} | ||
|
||
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. Ensure proper error handling instead of using Similar to previous comments, replace |
||
|
||
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. Ensure proper error handling instead of using Again, replace |
||
|
||
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. Ensure proper error handling instead of using This is another instance where replacing |
||
|
||
connectionId := "connection-0" | ||
ctx := context.Background() | ||
|
||
res, err := chainClient.FetchIBCConnection(ctx, connectionId) | ||
if err != nil { | ||
fmt.Println(err) | ||
Comment on lines
+63
to
+65
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. Handle the error case more explicitly. The error from |
||
} | ||
|
||
str, _ := json.MarshalIndent(res, "", " ") | ||
fmt.Print(string(str)) | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/query" | ||
|
||
"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. Ensure proper error handling instead of using Replace |
||
} | ||
|
||
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
+36
to
+38
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. Ensure proper error handling instead of using Similar to previous comments, replace |
||
|
||
clientCtx, err := chainclient.NewClientContext( | ||
network.ChainId, | ||
senderAddress.String(), | ||
cosmosKeyring, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
Comment on lines
+46
to
+48
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. Ensure proper error handling instead of using Again, replace |
||
|
||
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
+58
to
+60
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. Ensure proper error handling instead of using This is another instance where replacing |
||
|
||
pagination := query.PageRequest{Offset: 2, Limit: 4} | ||
ctx := context.Background() | ||
|
||
res, err := chainClient.FetchIBCConnections(ctx, &pagination) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
Comment on lines
+66
to
+68
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. Handle the error case more explicitly. The error from |
||
|
||
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.
Ensure proper error handling instead of using
panic
.Replace
panic(err)
with more robust error handling. This could involve logging the error and exiting gracefully, which would be more suitable for production environments.