-
Notifications
You must be signed in to change notification settings - Fork 195
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
[BUG] Handling Option and CustomEnum typescript bindings #2715
Comments
Having now tested a populated CairoOption enum, torii only provides |
@MartianGreed do you have an idea if this is happening on the bindgen layer or if it's coming from lower layers? |
Can definitely add support for those usecases. But for the torii returning "Some" I'm not familiar with that part of the codebase and I'm not sure how it's indexed |
@Larkooo Would you be able to advise on the torii side? |
@MartianGreed this is only bindgen side it seems right? Torii is correctly indexing the values. Happy to hop in a call to solve this asap. 👍 |
PR incoming |
Closed by #2773 please don't hesitate to reopen more specific issues if behavior is not as intended. 👍 |
Describe the bug
The typescript bindings generated by sozo do not handle Option and Enums with nested data structures. I am working with the
dojo.js sdk
and trying to plug in the types.To Reproduce
cd tournaments && cd contracts && sozo build --typescript
contracts/bindings/typescript/models.gen.ts
or find the file here: models.gen.ts
Option
Here is the model that I have defined in my contract:
The typescript binding generated:
Option is not a defined interface generated by the
models.gen.ts
. I recommend that we utilise the class and types provided bystarknet.js
, so the TournamentModel will looks like this:An instance of the cairo option is created like so:
CairoCustomEnum
Looking further into this GatedType, this is an enum with nested data structures. Here is the cairo interface:
The typescript binding generated is:
This is just a basic enum missing the data structures nested within it.
starknet.js
provides CairoCustomEnum that allows a variant object to be passed with any structure. For better type safety, I have also created an extension that allows generics:Therefore the full implementation could be:
An instance of the custom enum is created like so:
Would also require some playing with the torii graphql types, currently when I query a CairoOption I get a string
"None"
(if option is provided as variant none). This wouldn't work with the CairoOption type as it would expect{ Some: undefined, None: true }
.Please let me know thoughts, if we can get the bindings to work with these more advanced structures it would be greatly appreciated.
The text was updated successfully, but these errors were encountered: