-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat: implement multi-send transaction command #11738
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
cc3df15
feat: Implement multi-send transaction
julienrbrt 0a46ca2
add changelog
julienrbrt 9d3d8f5
improve quo
julienrbrt 398e92f
implement renaming feedback
julienrbrt 53cd623
implement feedback
julienrbrt 34e8d8b
implement part of feedback
julienrbrt 7236694
create new coin in loop
julienrbrt 51ed808
Update x/bank/client/cli/tx.go
alexanderbez da99dde
Merge branch 'main' into julien/7809-gaiad-tx-bank-multi-send-cli
anilcse 16bb41e
implement feedback
julienrbrt e55c7e8
improve description
julienrbrt 4c5511d
Merge branch 'main' into julien/7809-gaiad-tx-bank-multi-send-cli
alexanderbez 6e91344
Merge branch 'main' into julien/7809-gaiad-tx-bank-multi-send-cli
alexanderbez 2431edb
alias for consistency
julienrbrt 1f571da
add missing test
julienrbrt f29c132
Merge branch 'main' into julien/7809-gaiad-tx-bank-multi-send-cli
julienrbrt a9cbf7b
rebase fix
julienrbrt 22b2b07
remove sequence
julienrbrt 8818b86
fix sequence issue
julienrbrt 0d4a978
Merge branch 'main' into julien/7809-gaiad-tx-bank-multi-send-cli
alexanderbez 5e5260f
update changelog
julienrbrt f573ec9
Merge branch 'main' into julien/7809-gaiad-tx-bank-multi-send-cli
julienrbrt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -410,6 +410,71 @@ func (coins Coins) SafeSub(coinsB ...Coin) (Coins, bool) { | |
| return diff, diff.IsAnyNegative() | ||
| } | ||
|
|
||
| // MulInt performs the scalar multiplication of coins with a `multiplier` | ||
| // All coins are multipled by x | ||
| // e.g. | ||
| // {2A, 3B} * 2 = {4A, 6B} | ||
| // {2A} * 0 panics | ||
| // Note, if IsValid was true on Coins, IsValid stays true. | ||
| func (coins Coins) MulInt(x Int) Coins { | ||
| coins, ok := coins.SafeMulInt(x) | ||
| if !ok { | ||
| panic("multiplying by zero is an invalid operation on coins") | ||
| } | ||
|
|
||
| return coins | ||
| } | ||
|
|
||
| // SafeMulInt performs the same arithmetic as MulInt but returns false | ||
| // if the `multiplier` is zero because it makes IsValid return false. | ||
| func (coins Coins) SafeMulInt(x Int) (Coins, bool) { | ||
| if x.IsZero() { | ||
| return nil, false | ||
| } | ||
|
|
||
| res := make(Coins, len(coins)) | ||
| for i, coin := range coins { | ||
| coin := coin | ||
| res[i] = NewCoin(coin.Denom, coin.Amount.Mul(x)) | ||
| } | ||
|
|
||
| return res, true | ||
| } | ||
|
|
||
| // QuoInt performs the scalar division of coins with a `divisor` | ||
| // All coins are divided by x and trucated. | ||
| // e.g. | ||
| // {2A, 30B} / 2 = {1A, 15B} | ||
| // {2A} / 2 = {1A} | ||
| // {4A} / {8A} = {0A} | ||
| // {2A} / 0 = panics | ||
| // Note, if IsValid was true on Coins, IsValid stays true, | ||
| // unless the `divisor` is greater than the smallest coin amount. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am uncertain if we actually want this behavior, but I created these helpers function for avoiding having to do for every coin: sendCoins := coins
if split && !coins.IsZero() {
sendCoins[0].Amount = coins[0].Amount.Quo(totalAddr)
}If you find this better, then I can modify it and remove the changes in coins. |
||
| func (coins Coins) QuoInt(x Int) Coins { | ||
| coins, ok := coins.SafeQuoInt(x) | ||
| if !ok { | ||
| panic("dividing by zero is an invalid operation on coins") | ||
| } | ||
|
|
||
| return coins | ||
| } | ||
|
|
||
| // SafeQuoInt performs the same arithmetic as QuoInt but returns an error | ||
julienrbrt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // if the division cannot be done. | ||
| func (coins Coins) SafeQuoInt(x Int) (Coins, bool) { | ||
| if x.IsZero() { | ||
| return nil, false | ||
| } | ||
|
|
||
| var res Coins | ||
| for _, coin := range coins { | ||
| coin := coin | ||
| res = append(res, NewCoin(coin.Denom, coin.Amount.Quo(x))) | ||
| } | ||
|
|
||
| return res, true | ||
| } | ||
|
|
||
| // Max takes two valid Coins inputs and returns a valid Coins result | ||
| // where for every denom D, AmountOf(D) of the result is the maximum | ||
| // of AmountOf(D) of the inputs. Note that the result might be not | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| //go:build norace | ||
| // +build norace | ||
|
|
||
| package testutil | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.