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 a getter for an array of tokens held by an owner #1512

Closed
chebykin opened this issue Nov 23, 2018 · 8 comments · Fixed by #1522
Closed

Add a getter for an array of tokens held by an owner #1512

chebykin opened this issue Nov 23, 2018 · 8 comments · Fixed by #1522
Labels
contracts Smart contract code. feature New contracts, functions, or helpers.

Comments

@chebykin
Copy link

Problem

I want to inherit ERC721Full.sol contract and add an extra getter for an array of tokens held by a given user.

Expected behaviour

In previous versions it was possible by adding an extra function and accessing an internal _ownedTokens mapping:

function tokensOfOwner(address _owner) external view returns (uint256[]) {
    return ownedTokens[_owner];
}

Current behaviour

In version 2.x it is impossible to access a private _ownedTokens mapping.

@frangio frangio added feature New contracts, functions, or helpers. contracts Smart contract code. labels Nov 23, 2018
@frangio
Copy link
Contributor

frangio commented Nov 23, 2018

I think we could add an internal function in ERC721Enumerable for this.

function _tokensOfOwner(address owner) internal view returns (uint256[] storage) {
    return _ownedTokens[owner];
}

@chebykin
Copy link
Author

Thank you! Will wait for this feature.

@nventuro
Copy link
Contributor

Isn't this a duplicate of #1102?

@frangio
Copy link
Contributor

frangio commented Nov 24, 2018

Hm, that issue is about an external interface, this one is about an internal one for extension purposes.

@Aniket-Engg
Copy link
Contributor

Aniket-Engg commented Nov 27, 2018

shouldn't uint256[] storage be uint256[] memory?
@frangio Clear it, i will take this one.

@frangio
Copy link
Contributor

frangio commented Nov 27, 2018

@Aniket-Engg I think it should be storage because the function would be returning a pointer to the array that is held in storage. Copying the array to memory would be very expensive unnecessarily IMO.

Aniket-Engg added a commit to Aniket-Engg/zeppelin-solidity that referenced this issue Nov 28, 2018
frangio pushed a commit that referenced this issue Dec 5, 2018
* signing prefix added

* Minor improvement

* Tests changed

* Successfully tested

* Minor improvements

* Minor improvements

* Revert "Dangling commas are now required. (#1359)"

This reverts commit a688977.

* updates

* fixes #1404

* approve failing test

* suggested changes done

* ISafeERC20 removed

* conflict fixes

* fixes #1512

* Update test/token/ERC721/ERC721Full.test.js

Co-Authored-By: Aniket-Engg <30843294+Aniket-Engg@users.noreply.github.com>
@imsys
Copy link

imsys commented Jan 12, 2022

For some reason this was removed on bd07784

@arzusa
Copy link

arzusa commented Jul 15, 2022

I think we could add an internal function in ERC721Enumerable for this.

function _tokensOfOwner(address owner) internal view returns (uint256[] storage) {
    return _ownedTokens[owner];
}

not work

TypeError: Return argument type mapping(uint256 => uint256) is not implicitly convertible to expected type (type of first return variable) uint256[] storage pointer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contracts Smart contract code. feature New contracts, functions, or helpers.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants