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

Add Bank.getAllHolders(denom) grpc/api #9393

Closed
4 tasks
ghost opened this issue May 25, 2021 · 11 comments · Fixed by #9533
Closed
4 tasks

Add Bank.getAllHolders(denom) grpc/api #9393

ghost opened this issue May 25, 2021 · 11 comments · Fixed by #9533

Comments

@ghost
Copy link

ghost commented May 25, 2021

Summary

It would be nice to retrieve a list of holders for a particular denom.

Problem Definition

We are currently doing this very specifically for our marker module, but it would be very helpful to have this available on a regular denom as well. Pass in a denom name, and spit out a paginated list of account holders with balances.

Proposal

Following this example:

func (k Keeper) GetAllMarkerHolders(ctx sdk.Context, denom string) []types.Balance {	
	var results []types.Balance	
        k.bankKeeper.IterateAllBalances(ctx, func(addr sdk.AccAddress, coin sdk.Coin) (stop bool) {
		if coin.Denom == denom && !coin.Amount.IsZero() {
			results = append(results,
				types.Balance{
					Address: addr.String(),
					Coins:   sdk.NewCoins(coin),
				})
		}
		return false // do not stop iterating
	})
	return results
}

add somethings similar within the bank module.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@aaronc
Copy link
Member

aaronc commented May 28, 2021

Would you be willing to open a PR for this? For performance it would need to be paginated

@ghost
Copy link
Author

ghost commented Jun 1, 2021

Would you be willing to open a PR for this? For performance it would need to be paginated

@aaronc I appreciate the confidence. Unfortunately I am just acting as a user of these APIs at this time. I don't feel comfortable enough to make this change.

@alexanderbez
Copy link
Contributor

@aaronc can you point me to docs or resources on how to actually add a gRPC query please?

@aaronc
Copy link
Member

aaronc commented Jun 16, 2021

@aaronc can you point me to docs or resources on how to actually add a gRPC query please?

This is what we've got: https://docs.cosmos.network/v0.42/building-modules/query-services.html#implementation-of-a-module-query-service. I think it could be improved for sure (cc @ryanchristo). You can see examples for other query methods in bank.

@aaronc
Copy link
Member

aaronc commented Jun 17, 2021

Is it worth creating a denom - address reverse index for this? (i.e. concat(denom, address) as the key). An on-chain use case could be distributing some coins proportionally to all owners of a denom (basically an on-chain air drop).

@alexanderbez
Copy link
Contributor

Yes, I think that idea makes sense. Then we could just prefix scan on denom instead of all denominations, right?

@aaronc
Copy link
Member

aaronc commented Jun 17, 2021

Yes, I think that idea makes sense. Then we could just prefix scan on denom instead of all denominations, right?

Exactly, it is extra storage and gas to make that work, but it would be kind of nice. We probably don't need to store the actually balance under that reverse key so it only needs to be set once per denom/address pair and then deleted when the balance goes to zero. If we do it, it will need a migration.

@alexanderbez
Copy link
Contributor

If we do it, it will need a migration.

Why would this need a migration and how would that look like? Is this worth the change?

@amaury1093
Copy link
Contributor

how would that look like?

See example here for 0.42->0.43 store migrations.

Is this worth the change?

For now #9533 is non-breaking, so let's merge that into 0.43. The denom++address index is a nice-to-have for me, we can create a separate issue for it, and include it in 0.44 (with a 0.43->0.44 store migration).

@aaronc
Copy link
Member

aaronc commented Jun 25, 2021

For now #9533 is non-breaking, so let's merge that into 0.43. The denom++address index is a nice-to-have for me, we can create a separate issue for it, and include it in 0.44 (with a 0.43->0.44 store migration).

Could you create an issue for that @AmauryM ? I'd like to put it on the roadmap for the next release. It's also desirable if bank is used for storing NFTs.

@amaury1093
Copy link
Contributor

#9590

@mergify mergify bot closed this as completed in #9533 Jun 28, 2021
mergify bot pushed a commit that referenced this issue Jun 28, 2021
# Description

Adds a new gRPC method, `DenomOwners`, to the `x/bank` module. This method queries for all account addresses that own a particular token denomination (paginated). _Naming subject to change based on reviews._

closes: #9393

---

### 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
- [ ] 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/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [x] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] 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...

- [x] 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
- [x] confirmed all author checklist items have been addressed 
- [x] reviewed state machine logic
- [x] reviewed API design and naming
- [x] reviewed documentation is accurate
- [x] reviewed tests and test coverage
- [ ] manually tested (if applicable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants