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_chain_exchange_module_examples #209

Merged
merged 2 commits into from
Mar 8, 2024

Conversation

aarmoa
Copy link
Collaborator

@aarmoa aarmoa commented Mar 8, 2024

  • Added example scripts for all chain exchange module queries and messages.
  • Moved all chain example scripts to subfolders according to the modules they belong to

Summary by CodeRabbit

  • New Features
    • Introduced voting functionality for proposals in the blockchain network.
    • Enhanced ChainClient interface with new methods and data types for improved chain exchange interactions.
    • Added extensive support for fetching data from the chain exchange module, including market and trade information.
    • Launched new market types and updated functionalities within the Injective Protocol chain, including instant markets and querying capabilities for a wide range of data.

Copy link

coderabbitai bot commented Mar 8, 2024

Walkthrough

The recent updates focus on enhancing the blockchain network's voting mechanism and the Injective Protocol chain's functionality. These changes introduce a more robust voting process for blockchain proposals and significantly improve the chain's exchange module. They streamline market launching, reward management, and data querying across various market types and financial operations, making the system more efficient and user-friendly.

Changes

Files Summary
auth_vote/authz_vote.go Introduced voting functionality for blockchain proposals using InjectiveLabs and Cosmos SDK.
client/chain/chain.go
client/chain/chain_test_support.go
Updated ChainClient interface and chainClient struct, added new methods and functions for chain exchange data fetching.
examples/chain/exchange/* Enhanced Injective Protocol chain functionality, including market launching, opting out of rewards, and extensive data querying capabilities.

🐰✨
In a land of code and chain,
Where the bits and bytes do reign,
A rabbit hopped, with updates in tow,
Enhancing chains, making them glow.
Markets launch, rewards take flight,
In blockchain's dance, a splendid sight.
🌟🐾


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

codecov bot commented Mar 8, 2024

Codecov Report

Attention: Patch coverage is 0.49020% with 406 lines in your changes are missing coverage. Please review.

Project coverage is 25.01%. Comparing base (bb47a8f) to head (2701f15).

Files Patch % Lines
client/chain/chain.go 0.67% 296 Missing ⚠️
client/chain/chain_test_support.go 0.00% 110 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #209      +/-   ##
==========================================
- Coverage   29.01%   25.01%   -4.00%     
==========================================
  Files          17       17              
  Lines        2630     3022     +392     
==========================================
- Hits          763      756       -7     
- Misses       1831     2234     +403     
+ Partials       36       32       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aarmoa aarmoa merged commit 061635d into dev Mar 8, 2024
2 of 4 checks passed
@aarmoa aarmoa deleted the feat/add_chain_exchange_module_examples branch March 8, 2024 03:32
Comment on lines +64 to +67
res, err := chainClient.FetchChainSpotMarkets(ctx, status, marketIds)
if err != nil {
fmt.Println(err)
}
Copy link

Choose a reason for hiding this comment

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

The error handling in this example is minimal, only printing the error. Improving error handling would benefit users of this example.

Suggest adding more detailed error handling to provide better guidance on how to react to different error conditions.

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

Choose a reason for hiding this comment

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

Identical to the previous files, this script contains hardcoded sensitive information in the InitCosmosKeyring function. This is a security concern that needs addressing.

Recommend using environment variables or secure storage mechanisms for sensitive data like private keys and passwords.

Comment on lines +64 to +67
res, err := chainClient.FetchChainFullSpotMarket(ctx, marketId, withMidPriceAndTob)
if err != nil {
fmt.Println(err)
}
Copy link

Choose a reason for hiding this comment

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

The error handling after the FetchChainFullSpotMarket call is minimal, only printing the error. Enhancing error handling would make the example more robust and informative.

Consider adding error handling logic that could include logging the error or even retrying the operation depending on the error type.

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

Choose a reason for hiding this comment

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

Again, this example includes hardcoded sensitive information in the InitCosmosKeyring function, which is a consistent security issue across these examples.

Urging the use of environment variables or secure storage for managing sensitive data to avoid security risks.

Comment on lines +64 to +67
res, err := chainClient.FetchAggregateVolumes(ctx, accounts, marketIds)
if err != nil {
fmt.Println(err)
}
Copy link

Choose a reason for hiding this comment

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

The error handling in this example is minimal, only printing the error. This could be enhanced to provide a more robust and informative example.

Recommend adding more detailed error handling to improve the example's usefulness and guide users on how to handle different error scenarios.

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

Choose a reason for hiding this comment

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

Ensure proper error handling by not just panicking but also logging the error or providing a more user-friendly message. Panicking might not be the best approach for production code or examples meant for wider audiences.

- panic(err)
+ fmt.Printf("Error creating Tendermint HTTP client: %v\n", 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
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
fmt.Printf("Error creating Tendermint HTTP client: %v\n", err)
return
}

Comment on lines +3 to +13
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"
)
Copy link

Choose a reason for hiding this comment

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

Consider organizing imports by grouping standard library imports separately from third-party packages for better readability.

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"
)

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
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"
)
import (
"context"
"encoding/json"
"fmt"
"os"
)
import (
"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"
)

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

Choose a reason for hiding this comment

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

The use of a hardcoded private key (5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e) and password (12345678) in the InitCosmosKeyring function call raises security concerns. For example scripts, it's better to prompt the user for sensitive information or read from environment variables or configuration files.

Consider removing sensitive information and prompting the user or reading from a secure source.

Comment on lines +60 to +66
res, err := chainClient.FetchFeeDiscountAccountInfo(ctx, senderAddress.String())
if err != nil {
fmt.Println(err)
}

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

Choose a reason for hiding this comment

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

Ensure error handling is comprehensive. Currently, if an error occurs when fetching fee discount account information (FetchFeeDiscountAccountInfo), the error is printed, but the program continues to attempt marshalling potentially nil or incomplete data, which could lead to a runtime panic.

if err != nil {
	fmt.Println(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
res, err := chainClient.FetchFeeDiscountAccountInfo(ctx, senderAddress.String())
if err != nil {
fmt.Println(err)
}
str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))
res, err := chainClient.FetchFeeDiscountAccountInfo(ctx, senderAddress.String())
if err != nil {
fmt.Println(err)
return
}
str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))

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

Choose a reason for hiding this comment

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

Storing sensitive information such as the keyring passphrase ("12345678") and the private key directly in the source code is a security risk. Consider using environment variables or a secure vault service for handling sensitive data.

Comment on lines +60 to +63
res, err := chainClient.FetchMitoVaultInfos(ctx)
if err != nil {
fmt.Println(err)
}
Copy link

Choose a reason for hiding this comment

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

When handling errors, it's good practice to provide more context about the error. Simply printing the error might not be enough for debugging purposes. Consider logging the specific operation that failed along with the error message.

- fmt.Println(err)
+ fmt.Printf("Error fetching MitoVault information: %v\n", 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.FetchMitoVaultInfos(ctx)
if err != nil {
fmt.Println(err)
}
res, err := chainClient.FetchMitoVaultInfos(ctx)
if err != nil {
fmt.Printf("Error fetching MitoVault information: %v\n", err)
}

Comment on lines +3 to +13
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"
Copy link

Choose a reason for hiding this comment

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

As with the previous file, consider organizing imports by grouping standard library imports separately from third-party packages for better readability.

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"
)

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
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"
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"
)

Comment on lines +65 to +66
str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))
Copy link

Choose a reason for hiding this comment

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

While ignoring errors from json.MarshalIndent might be acceptable in simple examples, it's generally a good practice to handle every error. This can prevent silent failures and make debugging easier.

- str, _ := json.MarshalIndent(res, "", " ")
+ str, err := json.MarshalIndent(res, "", " ")
+ if err != nil {
+     fmt.Printf("Error marshalling response: %v\n", 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
str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))
str, err := json.MarshalIndent(res, "", " ")
if err != nil {
fmt.Printf("Error marshalling response: %v\n", err)
return
}
fmt.Print(string(str))

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

Choose a reason for hiding this comment

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

The use of hardcoded sensitive information is a security risk. Consider prompting the user for this information or reading it from a secure source.

Consider removing sensitive information and prompting the user or reading from a secure source.

Comment on lines +61 to +67
res, err := chainClient.FetchIsOptedOutOfRewards(ctx, senderAddress.String())
if err != nil {
fmt.Println(err)
}

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

Choose a reason for hiding this comment

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

Ensure comprehensive error handling. If an error occurs, the program should not attempt to marshal and print potentially nil or incomplete data.

if err != nil {
	fmt.Println(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
res, err := chainClient.FetchIsOptedOutOfRewards(ctx, senderAddress.String())
if err != nil {
fmt.Println(err)
}
str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))
res, err := chainClient.FetchIsOptedOutOfRewards(ctx, senderAddress.String())
if err != nil {
fmt.Println(err)
return
}
str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))

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

Choose a reason for hiding this comment

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

As mentioned previously, consider improving error handling by providing more context or using a more graceful exit strategy than panicking.

- panic(err)
+ fmt.Printf("Error creating Tendermint HTTP client: %v\n", 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
func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
fmt.Printf("Error creating Tendermint HTTP client: %v\n", err)
return

Comment on lines +22 to +30

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

Choose a reason for hiding this comment

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

Avoid hardcoding sensitive information in the source code. Use environment variables or secure storage solutions for managing sensitive data like passphrases and private keys.

Comment on lines +61 to +63
res, err := chainClient.FetchChainPositions(ctx)
if err != nil {
fmt.Println(err)
Copy link

Choose a reason for hiding this comment

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

Provide more context when logging errors to aid in debugging. Simply printing the error may not be sufficient.

- fmt.Println(err)
+ fmt.Printf("Error fetching chain positions: %v\n", 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.FetchChainPositions(ctx)
if err != nil {
fmt.Println(err)
res, err := chainClient.FetchChainPositions(ctx)
if err != nil {
fmt.Printf("Error fetching chain positions: %v\n", err)

Comment on lines +3 to +13
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"
Copy link

Choose a reason for hiding this comment

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

Group standard library imports separately from third-party packages for improved readability.

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"
)

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
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"
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"
)

Comment on lines +65 to +66

str, _ := json.MarshalIndent(res, "", " ")
Copy link

Choose a reason for hiding this comment

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

Handle all errors, including those from json.MarshalIndent, to avoid silent failures.

- str, _ := json.MarshalIndent(res, "", " ")
+ str, err := json.MarshalIndent(res, "", " ")
+ if err != nil {
+     fmt.Printf("Error marshalling response: %v\n", 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
str, _ := json.MarshalIndent(res, "", " ")
str, err := json.MarshalIndent(res, "", " ")
if err != nil {
fmt.Printf("Error marshalling response: %v\n", err)
return
}

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

Choose a reason for hiding this comment

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

Avoid using hardcoded sensitive information. Instead, prompt the user or read from a secure source.

Consider removing sensitive information and prompting the user or reading from a secure source.

Comment on lines +63 to +69
res, err := chainClient.FetchChainBinaryOptionsMarkets(ctx, status)
if err != nil {
fmt.Println(err)
}

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

Choose a reason for hiding this comment

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

Ensure error handling is comprehensive to avoid attempting to marshal and print nil or incomplete data on error.

if err != nil {
	fmt.Println(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
res, err := chainClient.FetchChainBinaryOptionsMarkets(ctx, status)
if err != nil {
fmt.Println(err)
}
str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))
res, err := chainClient.FetchChainBinaryOptionsMarkets(ctx, status)
if err != nil {
fmt.Println(err)
return
}
str, _ := json.MarshalIndent(res, "", " ")
fmt.Print(string(str))

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

Choose a reason for hiding this comment

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

Improve error handling by avoiding panics and providing more informative error messages.

- panic(err)
+ fmt.Printf("Error creating Tendermint HTTP client: %v\n", 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
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
fmt.Printf("Error creating Tendermint HTTP client: %v\n", err)
return
}

Comment on lines +17 to +20
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}
Copy link

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. Consider logging the error and gracefully shutting down or retrying the operation.

- panic(err)
+ fmt.Println("Error creating 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("Error creating Tendermint HTTP client:", err)
return
}

Comment on lines +63 to +66
res, err := chainClient.FetchChainSubaccountPositions(ctx, subaccountId.Hex())
if err != nil {
fmt.Println(err)
}
Copy link

Choose a reason for hiding this comment

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

Add proper error handling after the main query to handle potential errors gracefully.

if err != nil {
	fmt.Println("Error fetching subaccount positions:", 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
res, err := chainClient.FetchChainSubaccountPositions(ctx, subaccountId.Hex())
if err != nil {
fmt.Println(err)
}
res, err := chainClient.FetchChainSubaccountPositions(ctx, subaccountId.Hex())
if err != nil {
fmt.Println("Error fetching subaccount positions:", err)
return
}

Comment on lines +17 to +20
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}
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 more appropriate error handling to enhance the script's robustness and user experience.

- panic(err)
+ fmt.Println("Error creating 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("Error creating Tendermint HTTP client:", err)
return
}

Comment on lines +3 to +13
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"
)
Copy link

Choose a reason for hiding this comment

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

Organize imports by grouping standard library imports separately from third-party packages for improved readability.

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"
)

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
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"
)
import (
"context"
"encoding/json"
"fmt"
"os"
)
import (
"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"
)

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

Choose a reason for hiding this comment

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

Improve error handling by avoiding panics and providing more informative error messages.

- panic(err)
+ fmt.Printf("Error creating Tendermint HTTP client: %v\n", 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
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
fmt.Println(err)
return
panic(err)
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
fmt.Printf("Error creating Tendermint HTTP client: %v\n", err)
return

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

Choose a reason for hiding this comment

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

Hardcoded sensitive information poses a security risk. Use environment variables or secure vaults to store such information.

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

Choose a reason for hiding this comment

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

Adopt a more graceful approach to error handling instead of using panic.

- 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
}

Comment on lines +42 to +44
if err != nil {
panic(err)
}
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 proper error handling to improve the example script's usability and safety.

- 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
}

@@ -45,11 +41,10 @@ func main() {
)

if err != nil {
fmt.Println(err)
return
panic(err)
Copy link

Choose a reason for hiding this comment

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

As with previous files, consider handling errors more gracefully than panicking.

- panic(err)
+ fmt.Printf("Error initializing client context: %v\n", 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
panic(err)
fmt.Printf("Error initializing client context: %v\n", err)
return

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

Choose a reason for hiding this comment

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

Consistent with previous comments, avoid using panic for error handling.

- 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
}

Comment on lines +17 to +20
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}
Copy link

Choose a reason for hiding this comment

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

Adopt a more graceful error handling strategy instead of using panic, to enhance the user experience by providing more context about the error.

- panic(err)
+ fmt.Printf("Error creating Tendermint HTTP client: %v\n", 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.Printf("Error creating Tendermint HTTP client: %v\n", err)
return
}

}

//AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg
err = chainClient.QueueBroadcastMsg(&liqMsg)
err = chainClient.QueueBroadcastMsg(msg)
Copy link

Choose a reason for hiding this comment

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

When broadcasting messages, it's important to handle errors properly. Consider adding a more descriptive error message to help with debugging.

- fmt.Println(err)
+ fmt.Printf("Error broadcasting MsgRewardsOptOut: %v\n", 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
err = chainClient.QueueBroadcastMsg(msg)
fmt.Printf("Error broadcasting MsgRewardsOptOut: %v\n", err)

Comment on lines +64 to +66
if err != nil {
fmt.Println(err)
}
Copy link

Choose a reason for hiding this comment

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

Handle errors more gracefully, potentially logging them for further investigation or retrying the operation as needed.

- fmt.Println(err)
+ fmt.Println("Error fetching trader derivative transient orders:", 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 {
fmt.Println(err)
}
if err != nil {
fmt.Println("Error fetching trader derivative transient orders:", err)
return
}

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

Choose a reason for hiding this comment

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

Remove hard-coded values for the keyring setup and use environment variables or a configuration file for better security and flexibility.

Comment on lines +62 to +65
res, err := chainClient.FetchSpotMidPriceAndTOB(ctx, marketId)
if err != nil {
fmt.Println(err)
}
Copy link

Choose a reason for hiding this comment

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

Ensure proper error handling after the main query to gracefully handle potential errors.

if err != nil {
	fmt.Println("Error fetching spot mid price and TOB:", 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
res, err := chainClient.FetchSpotMidPriceAndTOB(ctx, marketId)
if err != nil {
fmt.Println(err)
}
res, err := chainClient.FetchSpotMidPriceAndTOB(ctx, marketId)
if err != nil {
fmt.Println("Error fetching spot mid price and TOB:", err)
return
}

Comment on lines +17 to +20
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
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 more appropriate error handling to enhance the script's robustness and user experience.

- panic(err)
+ fmt.Println("Error creating 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
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
fmt.Println("Error creating Tendermint HTTP client:", err)
return

Comment on lines +3 to +14
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"
)
Copy link

Choose a reason for hiding this comment

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

Group imports by separating standard library imports from third-party packages to improve code readability.

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"
)

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
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"
)
import (
"context"
"encoding/json"
"fmt"
"os"
)
import (
"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"
)

Comment on lines +22 to +30

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

Choose a reason for hiding this comment

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

Hardcoded sensitive information poses a security risk. Use environment variables or secure vaults to store such information.

Comment on lines +32 to +34

if err != nil {
panic(err)
Copy link

Choose a reason for hiding this comment

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

Adopt a more graceful approach to error handling instead of using panic.

- 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

Comment on lines +42 to +44

if err != nil {
panic(err)
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 proper error handling to improve the example script's usability and safety.

- 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

Comment on lines +17 to +20
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
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 to improve user experience and provide more context about the error.

- panic(err)
+ fmt.Printf("Error creating Tendermint HTTP client: %v\n", 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
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
fmt.Printf("Error creating Tendermint HTTP client: %v\n", err)
return

Comment on lines +54 to +56

if err != nil {
panic(err)
Copy link

Choose a reason for hiding this comment

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

Consistent with previous comments, avoid using panic for error handling.

- 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

Comment on lines +22 to +30

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

Choose a reason for hiding this comment

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

Avoid using hard-coded values for keyring setup. Use environment variables or a configuration file for better security and flexibility.

Comment on lines +63 to +65
res, err := chainClient.FetchChainSpotMarket(ctx, marketId)
if err != nil {
fmt.Println(err)
Copy link

Choose a reason for hiding this comment

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

Add proper error handling after the main query to handle potential errors gracefully.

if err != nil {
	fmt.Println("Error fetching spot market information:", 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
res, err := chainClient.FetchChainSpotMarket(ctx, marketId)
if err != nil {
fmt.Println(err)
res, err := chainClient.FetchChainSpotMarket(ctx, marketId)
if err != nil {
fmt.Println("Error fetching spot market information:", err)
return

Comment on lines +64 to +66
res, err := chainClient.FetchChainSubaccountPositionInMarket(ctx, subaccountId.Hex(), marketId)
if err != nil {
fmt.Println(err)
Copy link

Choose a reason for hiding this comment

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

Handle errors more gracefully, potentially logging them for further investigation or retrying the operation as needed.

- fmt.Println(err)
+ fmt.Println("Error fetching subaccount position in market:", 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
res, err := chainClient.FetchChainSubaccountPositionInMarket(ctx, subaccountId.Hex(), marketId)
if err != nil {
fmt.Println(err)
res, err := chainClient.FetchChainSubaccountPositionInMarket(ctx, subaccountId.Hex(), marketId)
if err != nil {
fmt.Println("Error fetching subaccount position in market:", err)
return

Comment on lines +3 to +13
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"
)
Copy link

Choose a reason for hiding this comment

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

Organize imports by grouping standard library imports separately from third-party packages for better readability.

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"
)

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
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"
)
import (
"context"
"encoding/json"
"fmt"
"os"
)

Comment on lines +17 to +20
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
}
Copy link

Choose a reason for hiding this comment

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

Adopt a more graceful error handling strategy instead of using panic, to enhance user experience by providing more context about the error.

- panic(err)
+ fmt.Printf("Error creating Tendermint HTTP client: %v\n", 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.Printf("Error creating Tendermint HTTP client: %v\n", err)
return
}

Comment on lines +17 to +20
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
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 more appropriate error handling to enhance the script's robustness and user experience.

- panic(err)
+ fmt.Println("Error creating 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
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
panic(err)
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
fmt.Println("Error creating Tendermint HTTP client:", err)
return

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

Choose a reason for hiding this comment

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

Remove hard-coded values for the keyring setup and use environment variables or a configuration file for better security and flexibility.

Comment on lines +62 to +65
res, err := chainClient.FetchDerivativeMidPriceAndTOB(ctx, marketId)
if err != nil {
fmt.Println(err)
}
Copy link

Choose a reason for hiding this comment

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

Ensure proper error handling after the main query to gracefully handle potential errors.

if err != nil {
	fmt.Println("Error fetching derivative mid price and TOB:", 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
res, err := chainClient.FetchDerivativeMidPriceAndTOB(ctx, marketId)
if err != nil {
fmt.Println(err)
}
res, err := chainClient.FetchDerivativeMidPriceAndTOB(ctx, marketId)
if err != nil {
fmt.Println("Error fetching derivative mid price and TOB:", err)
return
}

Comment on lines +22 to +30

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

Choose a reason for hiding this comment

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

Hardcoded sensitive information poses a security risk. Use environment variables or secure vaults to store such information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant