-
Notifications
You must be signed in to change notification settings - Fork 137
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
Simplify how to convert from ScVal types into BigInts/Numbers #722
Comments
Thanks for drafting this, @leighmcculloch. I do agree that the APIs are suboptimal, but they were a huge improvement over building the XDR values from scratch at the time. First, some rebuttals, and then alignment towards a solution:
Thanks for bringing this up, because it actually doesn't exist 😅 it's actually a documentation error (fixed in #723). So, on the brighter side, there are less ways.
This is the lowest-level way to create the value and was specifically requested in the original implementation. Their difference is noted in the documentation:
I'm not sure I follow the arguments about XDR types: namespacing makes this clear. Nothing outside of the
The whole point of these abstractions was to NOT do this, because it's super duper error-prone and gross. 99.9% of developers will do it wrong (we literally did it wrong ourselves several times in the VM). And if you really want to, this is what So, in summary, there really is only a single way to go from Now, for the proposed APIs:
I think this is a great idea: it was mentioned in the original PR, but you can see in that thread that it's not exactly trivial to extend generated XDR, unfortunately.
I strongly disagree with embracing the XDR more if we can avoid it. The Soroban XDR structures are gross and error-prone and this is exacerbated by So I agree that attaching it to the structures would be the neatest approach, and I want to look into this more, but it's not a trivial fix unfortunately :/ |
Is your feature request related to a problem? Please describe.
The APIs for working with XDR ScVal number types are reasonably confusing and non-obvious. There are also multiple ways to do the same thing.
For example there are three ways to get at / work with number values:
Use the
scValToBigInt
function:Use the
ScInt
type:Another problem with
ScInt
is that it looks like an XDR type, but it isn't.Use the
XdrLargeInt
type. This type should probably not be exported as it seems like an implementation detail?Another problem with
XdrLargeInt
is that there's another typeLargeInt
which serves another purpose.Describe the solution you'd like
Functions on
ScVal
. Close proximity toScVal
so that the functionality is discoverable, and less new concepts (XdrLargeInt
,ScInt
) are introduced).As a bonus, ScVal already contains functions for more advanced usage creating the values from parts:
Or the simpler variants can be added:
Describe alternatives you've considered
Another option would be to focus on using just one of these methods, such as combining
ScInt
andXdrLargeInt
so all conversions (simple and advanced) are in one type, and removingscValToBigInt
since it's superfluous.Additional context
Thinking about this after seeing the following question in Discord:
Historically we've tried to pull people away from the XDR, and hide the XDR where possible behind nicer APIs. With Soroban folks need to embrace the XDR more than they did with classic operations. Also, in this case the APIs we've pulled people from to are still relatively confusing, and we can introduce less concepts by pushing people back to the XDR type and adding functions to simplify interaction on the XDR type.
(I am more interested in solving the problem than with the solution I suggest above, and definitely defer to others more qualified for better solutions.)
The text was updated successfully, but these errors were encountered: