-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: serialization to and from felts
- Loading branch information
1 parent
8f79bea
commit 55bfd2c
Showing
11 changed files
with
1,229 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../starknet-core-derive/README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use starknet::{ | ||
core::{ | ||
codec::{Decode, Encode}, | ||
types::Felt, | ||
}, | ||
macros::felt, | ||
}; | ||
|
||
#[derive(Debug, Eq, PartialEq, Encode, Decode)] | ||
struct CairoType { | ||
a: Felt, | ||
b: Option<u32>, | ||
c: bool, | ||
} | ||
|
||
fn main() { | ||
let instance = CairoType { | ||
a: felt!("123456789"), | ||
b: Some(100), | ||
c: false, | ||
}; | ||
|
||
let mut serialized = vec![]; | ||
instance.encode(&mut serialized).unwrap(); | ||
|
||
assert_eq!( | ||
serialized, | ||
[felt!("123456789"), felt!("0"), felt!("100"), felt!("0")] | ||
); | ||
|
||
let restored = CairoType::decode(&serialized).unwrap(); | ||
|
||
assert_eq!(instance, restored); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[package] | ||
name = "starknet-core-derive" | ||
version = "0.1.0" | ||
authors = ["Jonathan LEI <[email protected]>"] | ||
license = "MIT OR Apache-2.0" | ||
edition = "2021" | ||
readme = "README.md" | ||
repository = "https://github.com/xJonathanLEI/starknet-rs" | ||
homepage = "https://starknet.rs/" | ||
description = """ | ||
Procedural macros for `starknet-core` | ||
""" | ||
keywords = ["ethereum", "starknet", "web3"] | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
proc-macro2 = "1.0.88" | ||
quote = "1.0.37" | ||
syn = "2.0.15" | ||
|
||
[features] | ||
default = [] | ||
import_from_starknet = [] | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Procedural macros for `starknet-core` | ||
|
||
This crate provides procedural macros for deriving the `Encode` and `Decode` traits from `starknet-core`. This allows defining a type like: | ||
|
||
```rust | ||
#[derive(Debug, PartialEq, Eq, Decode, Encode)] | ||
struct CairoType { | ||
a: Felt, | ||
b: U256, | ||
c: bool, | ||
} | ||
``` | ||
|
||
and using the `::encode()` and `::decode()` methods, without manually implementing the corresponding traits. |
Oops, something went wrong.