Skip to content
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

feat: serialization to and from felts #669

Merged
merged 1 commit into from
Oct 21, 2024
Merged

Conversation

xJonathanLEI
Copy link
Owner

Adds initial support for serialization of Rust types into Felts as well as deserialization.

This PR adds two new traits as starknet_core::codec::Encode and starknet_core::codec::Decode. Common Rust primitive types such as u64 and Option<T> implement these traits, following the same rules as the Serde trait in Cairo.

These two traits are derivable. Users can simple write something like:

#[derive(Encode, Decode)]
struct CairoType {
    a: Felt,
    b: Option<u32>,
    c: bool,
}

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 Felts 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.

@xJonathanLEI xJonathanLEI merged commit 1fc8b91 into master Oct 21, 2024
28 checks passed
@xJonathanLEI xJonathanLEI deleted the dev/encode_decode branch October 21, 2024 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant