Skip to content

Commit

Permalink
add serde feature (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l authored Jan 25, 2024
1 parent 7c70e71 commit 982089b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 32 deletions.
59 changes: 30 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ required-features = ["build-cli"]
default = ["build-cli", "with-runtime"]
build-cli = ["clap", "tracing-subscriber"]
with-debug-utils = []
with-runtime = ["cairo-native-runtime"]
with-runtime = ["dep:cairo-native-runtime"]
with-serde = ["dep:serde"]

[dependencies]
bumpalo = "3.14"
Expand Down Expand Up @@ -63,6 +64,7 @@ libloading = "0.8.1"
tracing-subscriber = { version = "0.3", features = [
"env-filter",
], optional = true }
serde = { version = "1.0.195", features = ["derive"], optional = true }

[dev-dependencies]
cairo-felt = "0.8.5"
Expand Down
4 changes: 2 additions & 2 deletions src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ impl<'a> ArgumentMapper<'a> {
self.push_aligned(get_integer_layout(252).align(), &value.to_le_digits());
}
(CoreTypeConcrete::Felt252Dict(_), JitValue::Felt252Dict { .. }) => {
#[cfg(not(feature = "cairo-native-runtime"))]
unimplemented!("enable the `cairo-native-runtime` feature to use felt252 dicts");
#[cfg(not(feature = "with-runtime"))]
unimplemented!("enable the `with-runtime` feature to use felt252 dicts");

// TODO: Assert that `info.ty` matches all the values' types.

Expand Down
7 changes: 7 additions & 0 deletions src/starknet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ pub struct Felt252Abi(pub [u8; 32]);
/// Binary representation of a `u256` (in MLIR).
// TODO: This shouldn't need to be public.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(target_arch = "x86_64", repr(C, align(8)))]
#[cfg_attr(not(target_arch = "x86_64"), repr(C, align(16)))]
pub struct U256(pub [u8; 32]);

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExecutionInfo {
pub block_info: BlockInfo,
pub tx_info: TxInfo,
Expand All @@ -29,6 +31,7 @@ pub struct ExecutionInfo {
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExecutionInfoV2 {
pub block_info: BlockInfo,
pub tx_info: TxV2Info,
Expand All @@ -38,6 +41,7 @@ pub struct ExecutionInfoV2 {
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TxV2Info {
pub version: Felt,
pub account_contract_address: Felt,
Expand All @@ -55,20 +59,23 @@ pub struct TxV2Info {
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ResourceBounds {
pub resource: Felt,
pub max_amount: u64,
pub max_price_per_unit: u128,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BlockInfo {
pub block_number: u64,
pub block_timestamp: u64,
pub sequencer_address: Felt,
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TxInfo {
pub version: Felt,
pub account_contract_address: Felt,
Expand Down
1 change: 1 addition & 0 deletions src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use std::{alloc::Layout, collections::HashMap, ops::Neg, ptr::NonNull};
///
/// A Boxed value or a non-null Nullable value is returned with it's inner value.
#[derive(Clone, Educe)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
#[educe(Debug, Eq, PartialEq)]
pub enum JitValue {
Felt252(#[educe(Debug(method(std::fmt::Display::fmt)))] Felt),
Expand Down

0 comments on commit 982089b

Please sign in to comment.