-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Virtual view functions #2154
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Thanks for suggesting this @Arachnid! When considering how I now think though that it may make sense to have function balanceOf(address account) public view override returns (uint256) {
if (account == owner) {
return UINT256_MAX;
} else {
return ERC20.balanceOf();
}
} This would allow you to implement an override for 721's Meanwhile, could you share a bit on what you had in mind for programmatic generation of the URI? Is it related to #1745? |
The original reason why we decided to keep all I think we can lift this restriction for some getters case-by-case. In the case of |
@nventuro Yes, similar to #1745. I want to be able to define a contract similar to this:
I'd say that for the vast majority of tokens, all token URIs are procedurally generated, and so using a minimum of two storage slots to store their URI (or at least the suffix) is a huge waste. I'd like to be able to avoid it, at least for my own token. Doing this does make |
Another option here is for people like myself to implement |
Heh, this is what I get for replying to these on a Sunday evening. I totally forgout about this, thanks for pointing it out @frangio! Indeed, bundling #1745 seems like a good idea. |
This is more a strategy thing than a specific issue, but I'd humbly suggest that allowing implementers to override parts of the behaviour is key to making OZ contracts as useful as possible. Certainly where it's problematic, as in the case you make with allowances, it needs to be documented at a minimum, but my personal preference order would be something like:
There are bound to be many other use-cases where this is relevant, and by making it forbidden by the compiler, you make OZ useless in those use-cases. |
We've decided to review this decision in the next release cycle since it's a backwards compatible change and we want to focus on getting 3.0 released as soon as possible. It's looking likely that we will make view functions virtual in general. Some more discussion in this forum thread. |
I care about the extension functionality if its safe. |
@frangio what do you think about this? It would provide maximum flexibility at the cost of (likely) higher gas costs due to poor optimization, but it'd also open the door few a new kind of 'wrong' code. I believe there's enough advanced users that would benefit from this, and we wouldn't need to do much more than add the |
Yes I think we have to go ahead with this. |
After offline conversation with @nventuro we think we will only implement this for select variables on a case-by-case basis. Doing this for all If we allowed overriding of function _transfer(...) {
require(balanceOf(account) >= amount);
balance[account] -= amount; // can overflow if `balanceOf()` returns a larger value than is in storage
} |
OK, so I take it that I'll need to continue to do fully copies of OpenZeppelin code at times with just a |
There may definitely be use cases that are "too clever" to implement without copying the code and editing it. Please keep reporting these experiences anyway so we can analyze if there's anything we can do to support those changes natively. |
Here's a (maybe stupid) use-case: |
I'm strongly in favor of letting people shoot themselves in the foot here. Put appropriate warnings in documentation, sure, but not making these methods overridable just erects needless barriers for use. Forcing people to copy the code and modify it will result in out-of-date copies of the code that will not get important bugfixes and security updates, too. |
This would allow developers to implement a decentralized URI scheme using content addressing such as IPFS with a unique token URI per token ID. |
I see the ability to make |
tokenURI
in ERC721 virtual
I will use this issue to collect all functions people have requested be made virtual. We want to get around to this soon.
|
|
Hi there. I wanted to second the "making virtual" of Adding my real world usecase if it helps to understand why this is needed: I do not host the NFT's JSON, they are uploaded on IPFS by the users, so I am not able to have a "one uri that covers all NFTS by replacing with {id}". So I have in my contract a Right now I can't just extend OZ contract because |
I would love to see So for now I had to clone OpenZeppelin's contracts to implement this. I believe it's better to leave it up to developers to decide whether they really want to override certain parts of the code, rather than completely restrict it. |
Thank you all for the feedback. We're going to work on this feature for the next release. |
I want to add
so does the |
@frangio is there a plan to make the |
@sylar217 We plan to release virtual view functions during January. |
We're actively working on this issue. Our current plan is to make view functions virtual, except when that causes consistency issues with the rest of the contract that are not trivial to fix. The typical explample is: if |
Virtual view functions will be available in the next release. The release candidate is already available for testing on npm at Note that in many cases overriding a function will not imply that other functions in the contract will automatically adapt to the overridden definitions. For example, overriding |
Might be useful to include this observation you make @frangio on the comments in the contracts. Will these upgrades be available also on the upgradeable contracts? (Might just clone them for the time being) |
@santisiri These changes will be available on the upgradeable contracts tomorrow at the same time that we release the final 3.4 package. |
Please mark
tokenURI
in ERC721virtual
.As it's not
virtual
, it can't be overridden by inheriting contracts. Making this virtual would allow contracts to implement programmatic generation of token URIs without using storage slots unnecessarily.The text was updated successfully, but these errors were encountered: