dojo icon indicating copy to clipboard operation
dojo copied to clipboard

`ByteArray` as standard type for strings

Open glihm opened this issue 7 months ago • 3 comments

Is your feature request related to a problem? Please describe. Nope, well. Currently strings are manipulated as array of felts. This is fine, however a new type popped in the 2.4.0 release: ByteArray. This type is much more flexible and defined as the new standard way in Cairo to deal with UTF-8 strings.

Describe the solution you'd like Planning how the use of this new type can be integrated to Dojo as the new standard for strings. This in fact impact all the stack (contracts, indexer mostly, SDKs, ...), but it can be a great value to support this standard. SDKs like starknet-js and starknet-rs will surely support it soon.

Describe alternatives you've considered We can definitely keep working with Array<felt252> for the moment.

Additional context I'm not sure of the priority of this issue (low I think), but wanted to know the your opinion guys. :+1:

glihm avatar Dec 11 '23 03:12 glihm

May I help you on this task ?

remybar avatar Mar 04 '24 05:03 remybar

Hey, @remybar is everywhere now. :P

I was planning to tackle this one in continuation of a previous work. It is coupled with an existing work on array that was already started, but it would be definitely great to have your feedback on the design!

The idea is that, dojo macro expansion is compile time only, and we want to avoid runtime overhead on that. Due to that, the maximum size of serialized felts for a type must be known at compile time.

For arrays (only containing primitive types for now), we added #[capacity(n)] attribute, where n is the size of the array. For ByteArray, the serialization is a bit different, and to have a better DevX, we were thinking to add #[strlen(n)] attribute, which feels more natural for strings.

And the end part of those changes, is ensuring that Torii understands the types to effectively index the data and create the associated record in the DB with correct types.

So the idea is to add first the ByteArray support into models (dojo core + torii), and later on exposing them everywhere we can once the SDKs are up to date with this.

If you think you've the bandwidth for that (we want to include this into the 0.6.0, before end of March), let's have a talk where I may give you some insights. :rocket:

glihm avatar Mar 05 '24 23:03 glihm

Hey @glihm !

Yes, if this is the continuation of a previous work, no problem, you can tackle it and I will work on something else ! As you have a quite short deadline and as I'm a newbie in Rust and for Dojo, this is probably better 😅

At first sight, this design looks good yes !

I plan to read the Dojo book and practice a little bit in the next days to have a better understanding of Dojo and what it offers.

If you see other issues for next versions where I can help, don't hesitate to tell me ;-)

remybar avatar Mar 06 '24 04:03 remybar