-
-
Notifications
You must be signed in to change notification settings - Fork 791
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
feat: add uint2str builtin #2879
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2879 +/- ##
==========================================
+ Coverage 87.94% 87.96% +0.01%
==========================================
Files 94 95 +1
Lines 10257 10389 +132
Branches 2478 2502 +24
==========================================
+ Hits 9021 9139 +118
- Misses 783 794 +11
- Partials 453 456 +3
Continue to review full report at Codecov.
|
vyper/builtin_functions/functions.py
Outdated
@@ -1807,6 +1807,64 @@ class Max(_MinMax): | |||
_opcode = "gt" | |||
|
|||
|
|||
class UintToStr(_SimpleBuiltinFunction): | |||
_id = "uint2str" | |||
_inputs = [("x", Uint256Definition())] # should allow any uint? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to allow any integer value, yes (including signed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't know. in the interest of simplicity, i think we should leave it as is for now, and then maybe add more types if people complain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, plus can always do some combination of converting and using abs built in.
For signed:
return concat("-", str(abs(some_signed_int)))
vyper/builtin_functions/functions.py
Outdated
class UintToStr(_SimpleBuiltinFunction): | ||
_id = "uint2str" | ||
_inputs = [("x", Uint256Definition())] # should allow any uint? | ||
_return_type = StringDefinition(78) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Integer type would just affect this number somehow
_id = "uint2str" | ||
_inputs = [("x", Uint256Definition())] # should allow any uint? | ||
_return_type = StringDefinition(78) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also would be interesting to have kwargs to limit the total value if known beforehand (e.g. 10k pfp NFTs)
@@ -1807,6 +1807,64 @@ class Max(_MinMax): | |||
_opcode = "gt" | |||
|
|||
|
|||
class UintToStr(_SimpleBuiltinFunction): | |||
_id = "uint2str" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe num2str
is more general for other integer types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about str()
after python?
Can also add implementation to here: https://github.com/vyperlang/vyper/blob/master/examples/tokens/ERC721.vy baseURL: String[53] # ipfs://Qm....
@view
@external
def tokenURL(tokenId: uint256) -> String[132]:
return concat(self.baseURL, uint2str(tokenId)) |
I can already sense the usage of this with a constant ... Would adding an |
🤦 |
Co-authored-by: El De-dog-lo <3859395+fubuloubu@users.noreply.github.com>
never mind, it makes sense -- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My one misgivings with this PR is that I don't think it would be possible to signal when a type doesn't need the full string size for itself, like when converting tokenId
for a 10k token mint set
i changed the builtin to allow a uint of any width, this also gives fine-grained control over the output string length. |
switching back to |
What I did
implement #2703
How I did it
How to verify it
Commit message
Description for the changelog
Cute Animal Picture