-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
14 changed files
with
2,131 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use starknet::core::types::{ContractClass, Felt}; | ||
|
||
use super::data_transformer::transformer::transform; | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
#[serde(untagged)] | ||
pub enum Calldata { | ||
Serialized(Vec<Felt>), | ||
Expressions(Vec<String>), | ||
} | ||
|
||
impl From<Vec<String>> for Calldata { | ||
fn from(calldata: Vec<String>) -> Self { | ||
let maybe_serialized = calldata | ||
.iter() | ||
.map(|arg| { | ||
Felt::from_dec_str(arg) | ||
.or_else(|_| Felt::from_hex(arg)) | ||
.ok() | ||
}) | ||
.collect::<Option<Vec<_>>>(); | ||
|
||
if let Some(serialized) = maybe_serialized { | ||
Self::Serialized(serialized) | ||
} else { | ||
Self::Expressions(calldata) | ||
} | ||
} | ||
} | ||
|
||
impl Calldata { | ||
/// Serialize Calldata is it's given as a list of Cairo-like expressions (Strings), | ||
/// return it as already serialized otherwise | ||
pub fn serialize_if_needed( | ||
self, | ||
class_definition: ContractClass, | ||
function_selector: &Felt, | ||
) -> anyhow::Result<Vec<Felt>> { | ||
match self { | ||
Calldata::Serialized(serialized) => Ok(serialized), | ||
Calldata::Expressions(ref expressions) => { | ||
transform(expressions, class_definition, function_selector) | ||
} | ||
} | ||
} | ||
} |
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,2 @@ | ||
pub mod sierra_abi; | ||
pub mod transformer; |
Oops, something went wrong.