-
Notifications
You must be signed in to change notification settings - Fork 70
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
Support type aliases as contracttypes #1063
Comments
Hey! Seems like even if the type is defined in the same file, it doesn't work so it looks like soroban requires that we do not use any type aliases for the contract API. Do you think this could be changed? |
So something like this does not work:
|
Transferred this issue from stellar/soroban-tools#870 to #1063 because the limitation preventing this from working is in the SDK. I believe the contract spec is extendable to address this problem. I've assigned the issue to myself and will investigate. |
From best I can tell with the experiment I ran, types can live in other libraries and be imported. See #1070 for an example of it working. I think the issue that's occurring in the example above is that a type alias is being used. Soroban contracttype's don't support a type alias. type DataType = soroban_sdk::String; We could add support for it, although it would be somewhat noisy in contract interfaces. Contract interfaces would have to store the original type, and the alias type. So the contract will be smaller and cheaper to execute if the alias was ommitted. If it's inefficient, folks will probably avoid it, so it's questionable if we should add logic and complexity to handle something that will be avoided. Thoughts anyone? @stellar/contract-committers? |
…ib (#1070) ### What Add test vector for workspace setups where contract types live in a lib. ### Why In #1063 it was mentioned that folks were having trouble with using types in other libs. Added this test vector to confirm if that was an issue or not. Appears to work fine, and this is a use case that is important, so committing the test vector.
I've looked into this a bit more and I think the effort to implement is significant. For user-defined-types I think this is possible. The For SDK types things get interesting because the The complexity this introduces to the SDK is significant, and effort is significant. There hasn't been much fan fare about the feature request. It could be that folks want it but haven't indicated so. At the moment I'm leaning towards closing the feature until we get more signal on utility. |
As a another data point for evaluating adding this feature, this feature was requested in Discord: |
This might not be as much of a problem as I first thought. |
What did you do?
I have a project that uses rust workspaces (each contract is a separate workspace member).
I want to share some code between them, mostly types.
repro: here is a repro https://github.com/karol-bisztyga/soroban-test
The problem is, it builds and deploys but when I invoke the contract I get
MissingEntry("DataType")
error. When I replace the type with justsoroban_sdk::String
, it works, but when I get the type from the shared crate, it breaks (it's still just a string just aliased). Looks like during the build or deployment the imported code's not attached to the contract.To reproduce (more or less):
What did you expect to see?
Working invoke.
What did you see instead?
MissingEntry("DataType")
error.Please let me know if it's the right place to post this, if not, pls point me to the right one.
The text was updated successfully, but these errors were encountered: