-
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/tendermint_module_queries #212
Conversation
WalkthroughThe update enhances the Changes
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #212 +/- ##
==========================================
- Coverage 25.01% 24.73% -0.28%
==========================================
Files 17 17
Lines 3022 3068 +46
==========================================
+ Hits 756 759 +3
- Misses 2234 2277 +43
Partials 32 32 ☔ View full report in Codecov by Sentry. |
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.
Review Status
Actionable comments generated: 8
Configuration used: .coderabbit.yaml
Files selected for processing (8)
- client/chain/chain.go (5 hunks)
- client/chain/chain_test_support.go (2 hunks)
- examples/chain/tendermint/query/1_GetNodeInfo/example.go (1 hunks)
- examples/chain/tendermint/query/2_GetSyncing/example.go (1 hunks)
- examples/chain/tendermint/query/3_GetLatestBlock/example.go (1 hunks)
- examples/chain/tendermint/query/4_GetBlockByHeight/example.go (1 hunks)
- examples/chain/tendermint/query/5_GetLatestValidatorSet/example.go (1 hunks)
- examples/chain/tendermint/query/6_GetValidatorSetByHeight/example.go (1 hunks)
Check Runs (1)
codecov/patch failure (14)
- client/chain/chain.go: 2036-2038: Added lines #L2036 - L2038 were not covered by tests
- client/chain/chain.go: 2041-2043: Added lines #L2041 - L2043 were not covered by tests
- client/chain/chain.go: 2046-2048: Added lines #L2046 - L2048 were not covered by tests
- client/chain/chain.go: 2051-2055: Added lines #L2051 - L2055 were not covered by tests
- client/chain/chain.go: 2058-2060: Added lines #L2058 - L2060 were not covered by tests
- client/chain/chain.go: 2063-2068: Added lines #L2063 - L2068 were not covered by tests
- client/chain/chain.go: 2071-2078: Added lines #L2071 - L2078 were not covered by tests
- client/chain/chain_test_support.go: 554-555: Added lines #L554 - L555 were not covered by tests
- client/chain/chain_test_support.go: 558-559: Added lines #L558 - L559 were not covered by tests
- client/chain/chain_test_support.go: 562-563: Added lines #L562 - L563 were not covered by tests
- client/chain/chain_test_support.go: 566-567: Added lines #L566 - L567 were not covered by tests
- client/chain/chain_test_support.go: 570-571: Added lines #L570 - L571 were not covered by tests
- client/chain/chain_test_support.go: 574-575: Added lines #L574 - L575 were not covered by tests
- client/chain/chain_test_support.go: 578-579: Added lines #L578 - L579 were not covered by tests
func (c *chainClient) FetchNodeInfo(ctx context.Context) (*tmservice.GetNodeInfoResponse, error) { | ||
req := &tmservice.GetNodeInfoRequest{} | ||
return c.tendermintQueryClient.GetNodeInfo(ctx, req) | ||
} | ||
|
||
func (c *chainClient) FetchSyncing(ctx context.Context) (*tmservice.GetSyncingResponse, error) { | ||
req := &tmservice.GetSyncingRequest{} | ||
return c.tendermintQueryClient.GetSyncing(ctx, req) | ||
} | ||
|
||
func (c *chainClient) FetchLatestBlock(ctx context.Context) (*tmservice.GetLatestBlockResponse, error) { | ||
req := &tmservice.GetLatestBlockRequest{} | ||
return c.tendermintQueryClient.GetLatestBlock(ctx, req) | ||
} | ||
|
||
func (c *chainClient) FetchBlockByHeight(ctx context.Context, height int64) (*tmservice.GetBlockByHeightResponse, error) { | ||
req := &tmservice.GetBlockByHeightRequest{ | ||
Height: height, | ||
} | ||
return c.tendermintQueryClient.GetBlockByHeight(ctx, req) | ||
} | ||
|
||
func (c *chainClient) FetchLatestValidatorSet(ctx context.Context) (*tmservice.GetLatestValidatorSetResponse, error) { | ||
req := &tmservice.GetLatestValidatorSetRequest{} | ||
return c.tendermintQueryClient.GetLatestValidatorSet(ctx, req) | ||
} | ||
|
||
func (c *chainClient) FetchValidatorSetByHeight(ctx context.Context, height int64, pagination *query.PageRequest) (*tmservice.GetValidatorSetByHeightResponse, error) { | ||
req := &tmservice.GetValidatorSetByHeightRequest{ | ||
Height: height, | ||
Pagination: pagination, | ||
} | ||
return c.tendermintQueryClient.GetValidatorSetByHeight(ctx, req) | ||
} | ||
|
||
func (c *chainClient) ABCIQuery(ctx context.Context, path string, data []byte, height int64, prove bool) (*tmservice.ABCIQueryResponse, error) { | ||
req := &tmservice.ABCIQueryRequest{ | ||
Path: path, | ||
Data: data, | ||
Height: height, | ||
Prove: prove, | ||
} | ||
return c.tendermintQueryClient.ABCIQuery(ctx, req) |
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.
The addition of methods FetchNodeInfo
, FetchSyncing
, FetchLatestBlock
, FetchBlockByHeight
, FetchLatestValidatorSet
, FetchValidatorSetByHeight
, and ABCIQuery
to interact with the Tendermint service are crucial for expanding the querying capabilities of the ChainClient
interface. However, it's noted that these added lines were not covered by tests.
Would you like assistance in creating test cases for these new methods to ensure they function as expected and to maintain high code quality?
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"os" | ||
|
||
"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" | ||
) | ||
|
||
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) | ||
} | ||
|
||
clientCtx, err := chainclient.NewClientContext( | ||
network.ChainId, | ||
senderAddress.String(), | ||
cosmosKeyring, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | ||
|
||
chainClient, err := chainclient.NewChainClient( | ||
clientCtx, | ||
network, | ||
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
res, err := chainClient.FetchLatestValidatorSet(ctx) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
fmt.Print(res.String()) | ||
|
||
} |
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.
The example code for fetching the latest validator set is well-structured and follows Go conventions. However, consider adding error handling after printing the result in line 65 to ensure that any issues during the fetch operation are appropriately managed. This could include logging the error or handling it in a way that's consistent with the rest of your application.
- fmt.Print(res.String())
+ fmt.Println(res.String())
+ if err != nil {
+ // Handle the error appropriately
+ fmt.Println("Error fetching the latest validator set:", 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.
package main | |
import ( | |
"context" | |
"fmt" | |
"os" | |
"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" | |
) | |
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) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
ctx := context.Background() | |
res, err := chainClient.FetchLatestValidatorSet(ctx) | |
if err != nil { | |
fmt.Println(err) | |
} | |
fmt.Print(res.String()) | |
} | |
fmt.Println(res.String()) | |
if err != nil { | |
// Handle the error appropriately | |
fmt.Println("Error fetching the latest validator set:", err) | |
} |
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"os" | ||
|
||
"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" | ||
) | ||
|
||
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) | ||
} | ||
|
||
clientCtx, err := chainclient.NewClientContext( | ||
network.ChainId, | ||
senderAddress.String(), | ||
cosmosKeyring, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | ||
|
||
chainClient, err := chainclient.NewChainClient( | ||
clientCtx, | ||
network, | ||
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
res, err := chainClient.FetchSyncing(ctx) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
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.
The example code for checking the syncing status of a Tendermint blockchain is clear and follows Go conventions. However, similar to the previous file, consider adding error handling after printing the result in line 67 to ensure that any issues during the operation are appropriately managed.
- fmt.Print(string(str))
+ fmt.Println(string(str))
+ if err != nil {
+ // Handle the error appropriately
+ fmt.Println("Error fetching the syncing status:", 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.
package main | |
import ( | |
"context" | |
"encoding/json" | |
"fmt" | |
"os" | |
"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" | |
) | |
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) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
ctx := context.Background() | |
res, err := chainClient.FetchSyncing(ctx) | |
if err != nil { | |
fmt.Println(err) | |
} | |
str, _ := json.MarshalIndent(res, "", " ") | |
fmt.Print(string(str)) | |
} | |
package main | |
import ( | |
"context" | |
"encoding/json" | |
"fmt" | |
"os" | |
"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" | |
) | |
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) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
ctx := context.Background() | |
res, err := chainClient.FetchSyncing(ctx) | |
if err != nil { | |
fmt.Println(err) | |
} | |
str, _ := json.MarshalIndent(res, "", " ") | |
fmt.Println(string(str)) | |
if err != nil { | |
// Handle the error appropriately | |
fmt.Println("Error fetching the syncing status:", err) | |
} | |
} |
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"os" | ||
|
||
"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" | ||
) | ||
|
||
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) | ||
} | ||
|
||
clientCtx, err := chainclient.NewClientContext( | ||
network.ChainId, | ||
senderAddress.String(), | ||
cosmosKeyring, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | ||
|
||
chainClient, err := chainclient.NewChainClient( | ||
clientCtx, | ||
network, | ||
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
res, err := chainClient.FetchNodeInfo(ctx) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
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.
The example code for fetching node information is well-structured and follows Go conventions. Similar to the previous examples, adding error handling after printing the result in line 67 would improve the robustness of the example.
- fmt.Print(string(str))
+ fmt.Println(string(str))
+ if err != nil {
+ // Handle the error appropriately
+ fmt.Println("Error fetching node information:", 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.
package main | |
import ( | |
"context" | |
"encoding/json" | |
"fmt" | |
"os" | |
"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" | |
) | |
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) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
ctx := context.Background() | |
res, err := chainClient.FetchNodeInfo(ctx) | |
if err != nil { | |
fmt.Println(err) | |
} | |
str, _ := json.MarshalIndent(res, "", " ") | |
fmt.Print(string(str)) | |
} | |
package main | |
import ( | |
"context" | |
"encoding/json" | |
"fmt" | |
"os" | |
"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" | |
) | |
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) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
ctx := context.Background() | |
res, err := chainClient.FetchNodeInfo(ctx) | |
if err != nil { | |
fmt.Println(err) | |
} | |
str, _ := json.MarshalIndent(res, "", " ") | |
fmt.Println(string(str)) | |
if err != nil { | |
// Handle the error appropriately | |
fmt.Println("Error fetching node information:", err) | |
} | |
} |
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"os" | ||
|
||
"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" | ||
) | ||
|
||
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) | ||
} | ||
|
||
clientCtx, err := chainclient.NewClientContext( | ||
network.ChainId, | ||
senderAddress.String(), | ||
cosmosKeyring, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | ||
|
||
chainClient, err := chainclient.NewChainClient( | ||
clientCtx, | ||
network, | ||
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
res, err := chainClient.FetchLatestBlock(ctx) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
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.
The example code for fetching the latest block is clear and follows Go conventions. As with the other examples, adding error handling after printing the result in line 67 would enhance the example's error management.
- fmt.Print(string(str))
+ fmt.Println(string(str))
+ if err != nil {
+ // Handle the error appropriately
+ fmt.Println("Error fetching the latest block:", 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.
package main | |
import ( | |
"context" | |
"encoding/json" | |
"fmt" | |
"os" | |
"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" | |
) | |
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) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
ctx := context.Background() | |
res, err := chainClient.FetchLatestBlock(ctx) | |
if err != nil { | |
fmt.Println(err) | |
} | |
str, _ := json.MarshalIndent(res, "", " ") | |
fmt.Print(string(str)) | |
} | |
package main | |
import ( | |
"context" | |
"encoding/json" | |
"fmt" | |
"os" | |
"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" | |
) | |
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) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
ctx := context.Background() | |
res, err := chainClient.FetchLatestBlock(ctx) | |
if err != nil { | |
fmt.Println(err) | |
} | |
str, _ := json.MarshalIndent(res, "", " ") | |
fmt.Println(string(str)) | |
if err != nil { | |
// Handle the error appropriately | |
fmt.Println("Error fetching the latest block:", err) | |
} | |
} |
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"os" | ||
|
||
"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" | ||
) | ||
|
||
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) | ||
} | ||
|
||
clientCtx, err := chainclient.NewClientContext( | ||
network.ChainId, | ||
senderAddress.String(), | ||
cosmosKeyring, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | ||
|
||
chainClient, err := chainclient.NewChainClient( | ||
clientCtx, | ||
network, | ||
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
height := int64(23040174) | ||
res, err := chainClient.FetchBlockByHeight(ctx, height) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
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.
The example code for fetching a block by height is well-structured and follows Go conventions. Adding error handling after printing the result in line 68 would improve the example's error management, similar to the previous examples.
- fmt.Print(string(str))
+ fmt.Println(string(str))
+ if err != nil {
+ // Handle the error appropriately
+ fmt.Println("Error fetching block by height:", 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.
package main | |
import ( | |
"context" | |
"encoding/json" | |
"fmt" | |
"os" | |
"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" | |
) | |
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) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
ctx := context.Background() | |
height := int64(23040174) | |
res, err := chainClient.FetchBlockByHeight(ctx, height) | |
if err != nil { | |
fmt.Println(err) | |
} | |
str, _ := json.MarshalIndent(res, "", " ") | |
fmt.Print(string(str)) | |
} | |
package main | |
import ( | |
"context" | |
"encoding/json" | |
"fmt" | |
"os" | |
"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" | |
) | |
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) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
ctx := context.Background() | |
height := int64(23040174) | |
res, err := chainClient.FetchBlockByHeight(ctx, height) | |
if err != nil { | |
fmt.Println(err) | |
} | |
str, _ := json.MarshalIndent(res, "", " ") | |
fmt.Println(string(str)) | |
if err != nil { | |
// Handle the error appropriately | |
fmt.Println("Error fetching block by height:", err) | |
} | |
} |
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/query" | ||
|
||
"os" | ||
|
||
"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" | ||
) | ||
|
||
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) | ||
} | ||
|
||
clientCtx, err := chainclient.NewClientContext( | ||
network.ChainId, | ||
senderAddress.String(), | ||
cosmosKeyring, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | ||
|
||
chainClient, err := chainclient.NewChainClient( | ||
clientCtx, | ||
network, | ||
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
height := int64(23040174) | ||
pagination := query.PageRequest{Offset: 2, Limit: 10} | ||
res, err := chainClient.FetchValidatorSetByHeight(ctx, height, &pagination) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
fmt.Print(res.String()) | ||
|
||
} |
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.
The example code for fetching the validator set by height is clear and follows Go conventions. Similar to the other examples, adding error handling after printing the result in line 69 would enhance the example's error management.
- fmt.Print(res.String())
+ fmt.Println(res.String())
+ if err != nil {
+ // Handle the error appropriately
+ fmt.Println("Error fetching validator set by height:", 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.
package main | |
import ( | |
"context" | |
"fmt" | |
"github.com/cosmos/cosmos-sdk/types/query" | |
"os" | |
"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" | |
) | |
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) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
ctx := context.Background() | |
height := int64(23040174) | |
pagination := query.PageRequest{Offset: 2, Limit: 10} | |
res, err := chainClient.FetchValidatorSetByHeight(ctx, height, &pagination) | |
if err != nil { | |
fmt.Println(err) | |
} | |
fmt.Print(res.String()) | |
} | |
package main | |
import ( | |
"context" | |
"fmt" | |
"github.com/cosmos/cosmos-sdk/types/query" | |
"os" | |
"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" | |
) | |
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) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
ctx := context.Background() | |
height := int64(23040174) | |
pagination := query.PageRequest{Offset: 2, Limit: 10} | |
res, err := chainClient.FetchValidatorSetByHeight(ctx, height, &pagination) | |
if err != nil { | |
fmt.Println(err) | |
} | |
fmt.Println(res.String()) | |
if err != nil { | |
// Handle the error appropriately | |
fmt.Println("Error fetching validator set by height:", err) | |
} | |
} |
func (c *MockChainClient) FetchNodeInfo(ctx context.Context) (*tmservice.GetNodeInfoResponse, error) { | ||
return &tmservice.GetNodeInfoResponse{}, nil | ||
} | ||
|
||
func (c *MockChainClient) FetchSyncing(ctx context.Context) (*tmservice.GetSyncingResponse, error) { | ||
return &tmservice.GetSyncingResponse{}, nil | ||
} | ||
|
||
func (c *MockChainClient) FetchLatestBlock(ctx context.Context) (*tmservice.GetLatestBlockResponse, error) { | ||
return &tmservice.GetLatestBlockResponse{}, nil | ||
} | ||
|
||
func (c *MockChainClient) FetchBlockByHeight(ctx context.Context, height int64) (*tmservice.GetBlockByHeightResponse, error) { | ||
return &tmservice.GetBlockByHeightResponse{}, nil | ||
} | ||
|
||
func (c *MockChainClient) FetchLatestValidatorSet(ctx context.Context) (*tmservice.GetLatestValidatorSetResponse, error) { | ||
return &tmservice.GetLatestValidatorSetResponse{}, nil | ||
} | ||
|
||
func (c *MockChainClient) FetchValidatorSetByHeight(ctx context.Context, height int64, pagination *query.PageRequest) (*tmservice.GetValidatorSetByHeightResponse, error) { | ||
return &tmservice.GetValidatorSetByHeightResponse{}, nil | ||
} | ||
|
||
func (c *MockChainClient) ABCIQuery(ctx context.Context, path string, data []byte, height int64, prove bool) (*tmservice.ABCIQueryResponse, error) { | ||
return &tmservice.ABCIQueryResponse{}, nil | ||
} |
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.
The added functions for interacting with the Tendermint module in the MockChainClient
struct are a good addition for testing purposes. However, it's important to ensure these functions are covered by unit tests to validate their behavior and integration with the rest of the SDK. Consider adding tests for these functions to improve the SDK's test coverage and reliability.
Would you like me to help generate unit tests for these new functions or open a GitHub issue to track this task?
Summary by CodeRabbit