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 Coins.Find method #11959

Merged
merged 5 commits into from
May 18, 2022
Merged

feat: add Coins.Find method #11959

merged 5 commits into from
May 18, 2022

Conversation

robert-zaremba
Copy link
Collaborator

@robert-zaremba robert-zaremba commented May 13, 2022

Added a new helper method to find a coin in a set of sdk.Coins by denom.


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

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

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.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@robert-zaremba robert-zaremba added C:Types backport/0.46.x PR scheduled for inclusion in the v0.46's next stable release labels May 13, 2022
@robert-zaremba robert-zaremba requested a review from a team as a code owner May 13, 2022 20:17
@codecov
Copy link

codecov bot commented May 13, 2022

Codecov Report

Merging #11959 (2d30c29) into main (450cd7f) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11959      +/-   ##
==========================================
+ Coverage   65.94%   65.96%   +0.02%     
==========================================
  Files         677      677              
  Lines       71332    71336       +4     
==========================================
+ Hits        47039    47060      +21     
+ Misses      21609    21591      -18     
- Partials     2684     2685       +1     
Impacted Files Coverage Δ
types/coin.go 93.61% <100.00%> (+0.05%) ⬆️
crypto/keys/internal/ecdsa/privkey.go 82.45% <0.00%> (-1.76%) ⬇️
x/distribution/simulation/operations.go 90.27% <0.00%> (+9.72%) ⬆️

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

lgtm!

@robert-zaremba robert-zaremba added the A:automerge Automatically merge PR once all prerequisites pass. label May 16, 2022
types/coin.go Outdated
}
return ZeroInt()
return false, Coin{"", ZeroInt()}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just the empty Coin{} literal? The caller knows based of the bool that it's found or not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Coin{} has a nil amount. ok=false is not an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not following. You'd never use the coin if ok=false, so I don't think it matters if coin actually contains and we shouldn't allocate a ZeroInt() when we don't have to IMO

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

AmountOfNoDenomValidation and AmountOf uses it.
I agree, that it creates an allocation which is not always needed. If you really think it's better to avoid that allocation, then I will update. lmk

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I'd rather just return Coin{} IMO

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK, updated

Copy link
Contributor

@blushi blushi left a comment

Choose a reason for hiding this comment

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

LGTM

@mergify mergify bot merged commit 23baecf into main May 18, 2022
@mergify mergify bot deleted the robert/coins-find branch May 18, 2022 11:43
mergify bot pushed a commit that referenced this pull request May 18, 2022
Added a new helper method to find a coin in a set of `sdk.Coins` by denom.

---

### 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...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### 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.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)

(cherry picked from commit 23baecf)

# Conflicts:
#	CHANGELOG.md
@odeke-em odeke-em mentioned this pull request Dec 7, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. backport/0.46.x PR scheduled for inclusion in the v0.46's next stable release C:Types
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants