我写了这个函数:
// Function to get an owned token's id by referencing the index of the user's owned tokens.
// ex: user has 5 tokens, tokenOfOwnerByIndex(owner,3) will give the id of the 4th token.
function tokenOfOwnerByIndex(address _owner, uint256 _index) public view returns (uint _tokenId) {
// TODO: Make sure this works. Does not appear to throw when _index<balanceOf(_owner), which violates
// ERC721 compatibility.
assert(_index<balanceOf(_owner)); // throw if outside range
return ownedTokenIds[_owner][_index];
}
当 _index 为 2 且 _owner 使 balanceOf(_owner) 为 0 时,该函数在 Remix IDE 中返回 0。我的假设是它不会返回任何东西。我的问题是:
A) 为什么在断言失败后它返回 0?
B)当我使用上述参数运行它时,如何让它不返回 0?
谢谢,沃恩