starknet-rs icon indicating copy to clipboard operation
starknet-rs copied to clipboard

feat: add byte array type and string conversions

Open glihm opened this issue 1 year ago • 3 comments

This PR aims at bringing support for ByteArray type.

glihm avatar Dec 10 '23 20:12 glihm

I think I've JSON rpc related errors, if you have the opportunity to manually trigger the workflow it could be great @xJonathanLEI. Thanks a lot!

glihm avatar Dec 10 '23 21:12 glihm

I'm thinking that we should introduce a Bytes31 type to ensure that the data is actually with the correct format. WDYT @xJonathanLEI?

EDIT: useless question sorry, will implement it in the PR. :+1:

glihm avatar Dec 18 '23 18:12 glihm

@xJonathanLEI here's the updated version of the PR. Few months of blank here, sorry for that.

I've added the Bytes31 type to be consistent with Cairo.

Happy to address any comment!

glihm avatar Jun 21 '24 05:06 glihm

@xJonathanLEI rebased on master, happy to dive in any update as necessary.

glihm avatar Dec 02 '24 16:12 glihm

Hey @glihm thanks for the PR. I see you're modelling the types here directly after their Cairo implementations, with the internals exposed.

It kinda makes me wonder though: do we really expect users to care about what a particular array's data, pending_word, and pending_word_len really are?

I'm not exactly convinced that it's the case. The exact composition should only matter when crossing the Rust <-> Cairo boundary (i.e. encoding/decoding), which should be mostly opaque to users. Users most likely just want to deal with bytes.

So IMO a better design would be a fully encapsulated ByteArray type that's internally backed by Vec<u8>. We could provide getters for viewing the components like data, pending_word, and pending_word_len, but I also don't think that's actually needed.

Then we should have this type implement Encode and Decode to make crossing the Cairo boundary seamless.

xJonathanLEI avatar Dec 16 '24 14:12 xJonathanLEI

Superseded by #682.

xJonathanLEI avatar Dec 17 '24 06:12 xJonathanLEI

No way! I was just looking for a ByteArray implementation and turns out it was implemented 5 days ago! Man, we really are on the bleeding edge haha 😅. Thanks for the new feature guys!

elton-cs avatar Dec 21 '24 19:12 elton-cs