-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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(x/bank/cli)!: Allow MultiSendTx to Support Transactions with a Single Recipient #21920
Conversation
This PR modifies the existing MultiSendTx functionality to support sending funds to a single recipient without returning an error. Previously, the MultiSendTx command required at least two recipient addresses, and attempting to send tokens to only one account would result in an error. The changes in this PR adjust the cobra.MinimumNArgs from 4 to 3, allowing the multi-send command to handle a single recipient as well as multiple recipients. Additionally, when the --split flag is used, the specified amount will be split evenly among recipients. If only one recipient is provided, the entire amount will be sent to that recipient, making the functionality more flexible and user-friendly. Signed-off-by: Hwangjae Lee <meetrick@gmail.com>
📝 Walkthrough📝 Walkthrough📝 Walkthrough📝 Walkthrough📝 Walkthrough📝 Walkthrough📝 WalkthroughWalkthroughThe pull request introduces a modification to the Changes
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
|
Signed-off-by: Hwangjae Lee <meetrick@gmail.com>
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: 0
🧹 Outside diff range and nitpick comments (3)
x/bank/client/cli/tx.go (3)
44-50
: LGTM: Detailed description updated with clear explanationsThe
Long
description has been comprehensively updated to reflect the new functionality, including clear explanations of the--split
flag behavior and a note about the--from
flag. This provides valuable guidance to users.Consider adding an example of using the
--split
flag in theLong
description to further clarify its usage.
50-51
: LGTM: Updated argument count, but example could be improvedThe minimum argument count has been correctly updated to 3, aligning with the new functionality.
Consider updating the
Example
to showcase both single-recipient and multi-recipient usage, as well as the--split
flag. For instance:Example: fmt.Sprintf(` %[1]s tx bank multi-send cosmos1... cosmos1... 10stake %[1]s tx bank multi-send cosmos1... cosmos1... cosmos1... 30stake --split `, version.AppName),This would provide a more comprehensive illustration of the command's capabilities.
76-84
: LGTM: Recipient processing and amount splitting logic implemented correctlyThe changes accurately implement the functionality for single or multiple recipients, including the correct calculation of recipient count and amount splitting. The loop for processing recipients is also implemented correctly.
Consider adding a check to ensure that
totalAddrs
is not zero before performing the division in thesplit
case. Although this scenario is unlikely due to thecobra.MinimumNArgs(3)
check, it would add an extra layer of safety:if split { if totalAddrs.IsZero() { return errors.New("no recipients specified") } sendCoins = coins.QuoInt(totalAddrs) }
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
📒 Files selected for processing (2)
- x/bank/client/cli/tx.go (4 hunks)
- x/bank/client/cli/tx_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
x/bank/client/cli/tx.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.x/bank/client/cli/tx_test.go (2)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"
🔇 Additional comments (9)
x/bank/client/cli/tx.go (4)
39-40
: LGTM: Updated function comment accurately reflects new functionalityThe comment has been appropriately updated to reflect the new capability of sending funds to one or more accounts, which aligns with the PR objectives.
42-44
: LGTM: Command usage and description updated correctlyThe
Use
field andShort
description have been appropriately updated to reflect the new functionality of sending funds to one or more accounts. This change aligns with the PR objectives and provides clear guidance to users.
Line range hint
53-62
: LGTM: Sender address and amount parsing logic updated correctlyThe changes accurately implement the new argument structure, with the first argument set as the sender and the last argument parsed as the amount. The added comment enhances code readability.
93-98
: LGTM: Total amount calculation logic updated correctlyThe changes accurately implement the calculation of the total amount to be sent by the sender, handling both split and non-split cases correctly. This logic aligns well with the PR objectives and the previous changes.
x/bank/client/cli/tx_test.go (5)
54-72
: LGTM: Setup for single recipient test cases looks good.The setup for the TestMultiSendTxCmd_SingleRecipient function is well-structured. It correctly creates two accounts (one sender and one recipient) and sets up the necessary command and arguments.
74-143
: Comprehensive test cases for single recipient scenarios.The test cases cover various scenarios including:
- Valid transaction with a single recipient
- Invalid sender address
- Invalid recipient address
- Invalid amount
This comprehensive set of test cases ensures robust testing of the single recipient functionality.
146-171
: LGTM: Test execution logic is sound.The test execution logic is well-implemented. It correctly sets up the context, builds the command arguments, and checks for expected errors or successful responses.
174-174
: LGTM: Multi-recipient test function placement is appropriate.The TestMultiSendTxCmd_MultiRecipient function is correctly placed after the new single recipient test function. This arrangement provides a logical flow from testing single recipient scenarios to multi-recipient scenarios, enhancing the overall test coverage for the MultiSendTxCmd functionality.
54-174
: Changes align well with PR objectives.The addition of the TestMultiSendTxCmd_SingleRecipient function directly addresses the PR objective of allowing MultiSendTx to support transactions with a single recipient. The new test cases thoroughly cover various scenarios for single recipient transactions, complementing the existing multi-recipient tests.
These changes enhance the test coverage and ensure that the new functionality works as expected without breaking existing features.
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.
If you send to one recipient, then you should just use bank send
.
Why would you use multi send for that??
@julienrbrt , You’re absolutely right that for a single recipient, the bank send command is typically the most straightforward approach. However, the reason for allowing MultiSendTx to support a single recipient is to enhance flexibility and consistency across use cases where users may want to programmatically or operationally use the same command, regardless of whether they are sending to one or multiple recipients. For example:
In short, this change is about offering flexibility and making the multi-send command more adaptable without forcing users to switch between commands based on recipient count. Of course, users can still use bank send if they prefer, but this change provides a more consistent and versatile option. Would love to hear your thoughts on this! |
I think it makes the concept of multi-send CLI unclear if it can take one recipient. Your script could just have an While |
@julienrbrt ,Thank you for sharing your perspective! I understand the concern about maintaining clarity in the multi-send CLI and the potential confusion between Key Reasons for Supporting Single Recipient in
|
To be honest, the reply contents from @meetrick are indeed look like generated from AI :) |
Hi, discussed with the codeowners of bank, and we came to the same conclusion. |
This PR modifies the existing MultiSendTx functionality to support sending funds to a single recipient without returning an error. Previously, the MultiSendTx command required at least two recipient addresses, and attempting to send tokens to only one account would result in an error.
The changes in this PR adjust the cobra.MinimumNArgs from 4 to 3, allowing the multi-send command to handle a single recipient as well as multiple recipients. Additionally, when the --split flag is used, the specified amount will be split evenly among recipients. If only one recipient is provided, the entire amount will be sent to that recipient, making the functionality more flexible and user-friendly.
Description
Closes: #XXXX
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
New Features
Bug Fixes
Tests