feat: serialization to and from felts #669
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds initial support for serialization of Rust types into
Felt
s as well as deserialization.This PR adds two new traits as
starknet_core::codec::Encode
andstarknet_core::codec::Decode
. Common Rust primitive types such asu64
andOption<T>
implement these traits, following the same rules as theSerde
trait in Cairo.These two traits are derivable. Users can simple write something like:
A new example
serde
has been added to demonstrate the usage of these new building blocks.This is useful for constructing contract calldata and interpreting contract call responses fetched from JSON-RPC. Previously, users would have to manually decode the raw
Felt
s into proper Rust types.For now, users still need to manually write the ABI types in Rust. The next step is to add support for generating such types from a contract ABI.