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 TokensByOwner for cw721-base #122

Merged
merged 12 commits into from
Oct 16, 2020
Merged

Conversation

ethanfrey
Copy link
Member

@ethanfrey ethanfrey commented Oct 13, 2020

Closes #81

Builds on #108 (merge that first)

Ports to use cw-storage-plus rather than cosmwasm-storage, then makes use of IndexedMap

  • Port to cw-storage-plus
  • Better support for &str Map keys
  • Use IndexedMap
  • Enable query by owner
  • Cover query by owner with tests
  • Allow setting bounds (pagination)
  • Raise issues for remaining TODOs

Copy link
Contributor

@maurolacy maurolacy left a comment

Choose a reason for hiding this comment

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

Looks good. I think the use of bounds is still a little bit confusing / needlessly complex.

Added some comments to try and help clarifying the design.

contracts/cw721-base/src/contract.rs Outdated Show resolved Hide resolved
contracts/cw721-base/src/contract.rs Outdated Show resolved Hide resolved
contracts/cw721-base/src/contract.rs Outdated Show resolved Hide resolved
@ethanfrey
Copy link
Member Author

My takeaways. Only use one type:

pub enum Bound {
  Inclusive(Vec<u8>),
  Exclusive(Vec<u8>)
}

and accept Option<Bound> in range.

This will lead to lines like:

`let start: Option = start_after.map(|human| Ok(Bound::Exclusive(deps.api.canonical_addr(&human)?)).transpose()?;

Which is not so legible or user-friendly. I guess having a function for handling the human_addr case is good. For a string/int, we could get:

let start: Option<Bound> = start_after.map(|s| Bound::Exclusive(s.into()))

or

let start: Option<Bound> = start_after.map(|i| Bound::Exclusive(i.to_be_bytes().into()))

both of which are simple enough, without all these helpers.


Does the above make sense to you? Other suggestion?

@maurolacy
Copy link
Contributor

Makes sense. Will review later again with the IDE, to see and try some variants.

Copy link
Contributor

@maurolacy maurolacy left a comment

Choose a reason for hiding this comment

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

I understand this is WIP, but what I see looks good to me.

Powerful stuff here, and in the storage-plus.

contracts/cw721-base/src/state.rs Outdated Show resolved Hide resolved
contracts/cw721-base/src/state.rs Outdated Show resolved Hide resolved
@ethanfrey ethanfrey mentioned this pull request Oct 16, 2020
@ethanfrey ethanfrey merged commit 234b937 into secondary-indexes Oct 16, 2020
@ethanfrey ethanfrey deleted the tokens-by-owner branch October 16, 2020 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants