Add support to GetIntOrZero() #3372
Labels
compiler
Go smart contract compiler
enhancement
Improving existing functionality
I2
Regular impact
S4
Routine
U4
Nothing urgent
Milestone
Is your feature request related to a problem? Please describe.
The following code will throw an 'Invalid Cast Exception' in runtime:
This is because it returns
nil
when the key is not present.Describe the solution you'd like
I like how Neow3j solves this problem by exposing a GetIntOrZero method. As the name suggests, it will return
0
if the key is not present.Reference:
https://github.com/neow3j/neow3j/blob/f2b243a5a01f864a3ee9b98de52458ad534a2f88/devpack/src/main/java/io/neow3j/devpack/Storage.java#L165
Describe alternatives you've considered
I'm checking for
nil
before using it.Additional context
Casting will no longer be necessary with this improvement. Another change that could help, would be to allow
Get
calls without thecontext
parameter.Don't forget to add labels!
enhancement
The text was updated successfully, but these errors were encountered: