-
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
Allow Counter increment by more than just 1 #3296
Comments
I propose adding overloaded increment and decrement functionswith the following signatures:
|
I was thinking the same. Here are examples of simple counters that take an amount value to increment by that I've used before: |
I need this too. I might try a pull request. |
Hello @tab00 I understand your request, but I'm not super comfortable with where this is heading. We already have:
You'd like to add
Then someone will ask for @frangio What do you think? Should we expand the Counters library further? Should we use UDVT instead of structs? Note: it's not "clean" but if you really want to do that now, you can always do |
You could ask the same with how I was thinking a value of
That's a possible workaround in the meantime and definitely more gas-efficient, though there is a comment that explicitly says
|
I agree with @tab00 on this, I think the proposed new functions to the Counters library would be good in terms of the added functionality mixed in with the safety checks. |
hi @Amxx I'd like to contribute to this issue. Are we thinking of changing increment, decrement and reset function to include a newValue or only the reset function? also, is there any resource I can study to understand the necessary safety checks for this op? thank you. |
A better solution would be to create a new library |
What would this new library provide over just using uint256? Adding code creates discoverability and maintainability issues. |
One important thing with the Counter is that by increasing by 1, we can very safely assume that increment will not overflow, and we can "uncheck" it. As soon as we increment by arbitrary values, we can no longer make this assumption, so we should re-add the overflow checks, which IMO defeats the whole point of having Counter. |
Yes, the intent of the Counter abstraction is to represent a value that is known to never overflow. Incrementing by arbitrary uint256 removes that benefit entirely. We could consider incrementing by small integer types like uint8 if that's seen as valuable, but I don't think it's really necessary. |
Counters are being removed in 5.0. |
After a batch mint of ERC1155 NFTs I want to be able to increment the total supply count like this:
However currently
increment()
can only increase the counter by 1:openzeppelin-contracts/contracts/utils/Counters.sol
Line 26 in 4a9cc8b
So I have to resort to using a loop:
or not use
Counters
and dosupply += ids.length;
Please allow
increment()
to increase the counter by more than just 1.The text was updated successfully, but these errors were encountered: