-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
docs: Update transaction building using v2 #23257
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe pull request introduces a new section in the Cosmos SDK documentation focusing on building and broadcasting transactions using clientv2. The added content provides a comprehensive, step-by-step guide for developers, demonstrating how to create and send transactions through detailed code examples. The documentation update includes practical instructions for setting up imports, establishing gRPC connections, initializing keyrings, configuring transaction parameters, and broadcasting transactions. Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 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 using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 1
🧹 Nitpick comments (3)
docs/learn/advanced/01-transactions.md (3)
243-399
: Fix markdown formatting issuesThe ordered list numbering should be consistent (all items should start with
1.
), and the file should end with a single newline character.-2. Create a gRPC connection +1. Create a gRPC connection -3. Setup codec and interface registry +1. Setup codec and interface registry -4. Initialize keyring +1. Initialize keyring -5. Setup transaction parameters +1. Setup transaction parameters -6. Build the transaction +1. Build the transaction -7. Broadcast the transaction +1. Broadcast the transaction -8. Helpers +1. Helpers +🧰 Tools
🪛 Markdownlint (0.37.0)
243-243: Expected: 1; Actual: 2; Style: 1/1/1
Ordered list item prefix(MD029, ol-prefix)
252-252: Expected: 1; Actual: 3; Style: 1/1/1
Ordered list item prefix(MD029, ol-prefix)
266-266: Expected: 1; Actual: 4; Style: 1/1/1
Ordered list item prefix(MD029, ol-prefix)
282-282: Expected: 1; Actual: 5; Style: 1/1/1
Ordered list item prefix(MD029, ol-prefix)
331-331: Expected: 1; Actual: 6; Style: 1/1/1
Ordered list item prefix(MD029, ol-prefix)
360-360: Expected: 1; Actual: 7; Style: 1/1/1
Ordered list item prefix(MD029, ol-prefix)
377-377: Expected: 1; Actual: 8; Style: 1/1/1
Ordered list item prefix(MD029, ol-prefix)
399-399: null
Files should end with a single newline character(MD047, single-trailing-newline)
364-373
: Improve error handling and configuration in broadcasting
- The CometBFT endpoint should be configurable.
- Error messages should provide more context about the failure.
+const ( + defaultCometEndpoint = "http://127.0.0.1:26675" +) -c, err := comet.NewCometBFTBroadcaster("http://127.0.0.1:26675", comet.BroadcastSync, protoCodec) +endpoint := os.Getenv("COMET_ENDPOINT") +if endpoint == "" { + endpoint = defaultCometEndpoint +} +c, err := comet.NewCometBFTBroadcaster(endpoint, comet.BroadcastSync, protoCodec) if err != nil { - log.Fatal("error creating comet broadcaster", err) + log.Fatal("failed to create CometBFT broadcaster: ", err) } res, err := c.Broadcast(context.Background(), tx.Bytes()) if err != nil { - log.Fatal("error broadcasting tx", err) + log.Fatal("failed to broadcast transaction: ", err) }
212-399
: Add context and improve documentationThe example is comprehensive but could benefit from:
- A brief introduction explaining when to use clientv2.
- Comments explaining the purpose of each configuration option.
- Error handling best practices and recovery strategies.
- Examples of different transaction types beyond bank transfers.
🧰 Tools
🪛 Markdownlint (0.37.0)
243-243: Expected: 1; Actual: 2; Style: 1/1/1
Ordered list item prefix(MD029, ol-prefix)
252-252: Expected: 1; Actual: 3; Style: 1/1/1
Ordered list item prefix(MD029, ol-prefix)
266-266: Expected: 1; Actual: 4; Style: 1/1/1
Ordered list item prefix(MD029, ol-prefix)
282-282: Expected: 1; Actual: 5; Style: 1/1/1
Ordered list item prefix(MD029, ol-prefix)
331-331: Expected: 1; Actual: 6; Style: 1/1/1
Ordered list item prefix(MD029, ol-prefix)
360-360: Expected: 1; Actual: 7; Style: 1/1/1
Ordered list item prefix(MD029, ol-prefix)
377-377: Expected: 1; Actual: 8; Style: 1/1/1
Ordered list item prefix(MD029, ol-prefix)
399-399: null
Files should end with a single newline character(MD047, single-trailing-newline)
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
docs/learn/advanced/01-transactions.md
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
docs/learn/advanced/01-transactions.md (1)
Pattern **/*.md
: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"
🪛 Markdownlint (0.37.0)
docs/learn/advanced/01-transactions.md
243-243: Expected: 1; Actual: 2; Style: 1/1/1
Ordered list item prefix
(MD029, ol-prefix)
252-252: Expected: 1; Actual: 3; Style: 1/1/1
Ordered list item prefix
(MD029, ol-prefix)
266-266: Expected: 1; Actual: 4; Style: 1/1/1
Ordered list item prefix
(MD029, ol-prefix)
282-282: Expected: 1; Actual: 5; Style: 1/1/1
Ordered list item prefix
(MD029, ol-prefix)
331-331: Expected: 1; Actual: 6; Style: 1/1/1
Ordered list item prefix
(MD029, ol-prefix)
360-360: Expected: 1; Actual: 7; Style: 1/1/1
Ordered list item prefix
(MD029, ol-prefix)
377-377: Expected: 1; Actual: 8; Style: 1/1/1
Ordered list item prefix
(MD029, ol-prefix)
399-399: null
Files should end with a single newline character
(MD047, single-trailing-newline)
⏰ Context from checks skipped due to timeout of 90000ms (7)
- GitHub Check: repo-analysis
- GitHub Check: test-x-nft
- GitHub Check: build (arm64)
- GitHub Check: build (amd64)
- GitHub Check: markdown-link-check
- GitHub Check: dependency-review
- GitHub Check: Summary
clientConn, err := grpc.NewClient("127.0.0.1:9090", grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
``` |
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.
🛠️ Refactor suggestion
Improve security and configuration handling
- Using insecure credentials is not recommended for production environments.
- The gRPC endpoint should be configurable rather than hardcoded.
+// Define configuration variables
+const (
+ defaultGRPCEndpoint = "127.0.0.1:9090"
+)
-clientConn, err := grpc.NewClient("127.0.0.1:9090", grpc.WithTransportCredentials(insecure.NewCredentials()))
+// TODO: In production, use secure credentials
+endpoint := os.Getenv("GRPC_ENDPOINT")
+if endpoint == "" {
+ endpoint = defaultGRPCEndpoint
+}
+clientConn, err := grpc.NewClient(endpoint, grpc.WithTransportCredentials(insecure.NewCredentials()))
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.
clientConn, err := grpc.NewClient("127.0.0.1:9090", grpc.WithTransportCredentials(insecure.NewCredentials())) | |
if err != nil { | |
log.Fatal(err) | |
} | |
``` | |
// Define configuration variables | |
const ( | |
defaultGRPCEndpoint = "127.0.0.1:9090" | |
) | |
// TODO: In production, use secure credentials | |
endpoint := os.Getenv("GRPC_ENDPOINT") | |
if endpoint == "" { | |
endpoint = defaultGRPCEndpoint | |
} | |
clientConn, err := grpc.NewClient(endpoint, grpc.WithTransportCredentials(insecure.NewCredentials())) | |
if err != nil { | |
log.Fatal(err) | |
} |
@@ -207,3 +207,193 @@ An example can be seen [here](https://docs.cosmos.network/main/user/run-node/txs | |||
#### CometBFT RPC | |||
|
|||
The three methods presented above are actually higher abstractions over the CometBFT RPC `/broadcast_tx_{async,sync,commit}` endpoints, documented [here](https://docs.cometbft.com/v1.0/explanation/core/rpc). This means that you can use the CometBFT RPC endpoints directly to broadcast the transaction, if you wish so. | |||
|
|||
|
|||
#### Complete Example Building and Broadcasting a Transaction using clientv2 |
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.
IMHO, this should be moved under https://docs.cosmos.network/v0.52/tutorials and not here.
This page is about the general concepts of transactions
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.
Not sure what other think, but adding it here: https://github.com/cosmos/cosmos-sdk-docs/tree/main/docs/tutorials and maybe linking it in this page, makes more sense to me.
Description
Closes: #11652
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit