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

TODO: add ref wrapper #717

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/starknet-devnet-types/src/rpc/contract_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub fn convert_codegen_to_blockifier_compiled_class(
let json_value = serde_json::to_value(class).map_err(JsonError::SerdeJsonError)?;
let casm_json = usc::compile_contract(json_value)
.map_err(|err| Error::SierraCompilationError { reason: err.to_string() })?;

let casm = serde_json::from_value::<CasmContractClass>(casm_json)
.map_err(|err| Error::JsonError(JsonError::Custom { msg: err.to_string() }))?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ pub mod rpc_contract_class;

#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Cairo0ContractClass {
// TODO: remove once starknet_api raised
RawJson(Cairo0Json),
Rpc(DeprecatedContractClass),
}

#[derive(Serialize, Deserialize)]
#[serde(tag = "type", content = "contract_class")]
enum Cairo0ContractClassSerdeHelper {
RawJson(Cairo0Json),
Rpc(DeprecatedContractClass),
}
Expand All @@ -22,10 +28,11 @@ impl Serialize for Cairo0ContractClass {
where
S: Serializer,
{
match self {
Cairo0ContractClass::RawJson(contract_json) => contract_json.serialize(serializer),
Cairo0ContractClass::Rpc(contract) => contract.serialize(serializer),
}
let helper = match self {
Cairo0ContractClass::RawJson(c) => Cairo0ContractClassSerdeHelper::RawJson(c.clone()),
Cairo0ContractClass::Rpc(c) => Cairo0ContractClassSerdeHelper::Rpc(c.clone()),
};
helper.serialize(serializer)
}
}

Expand All @@ -34,7 +41,11 @@ impl<'de> Deserialize<'de> for Cairo0ContractClass {
where
D: Deserializer<'de>,
{
Ok(Cairo0ContractClass::Rpc(DeprecatedContractClass::deserialize(deserializer)?))
let helper = Cairo0ContractClassSerdeHelper::deserialize(deserializer)?;
Ok(match helper {
Cairo0ContractClassSerdeHelper::RawJson(c) => Cairo0ContractClass::RawJson(c),
Cairo0ContractClassSerdeHelper::Rpc(c) => Cairo0ContractClass::Rpc(c),
})
}
}

Expand All @@ -52,6 +63,7 @@ impl From<DeprecatedContractClass> for Cairo0ContractClass {

impl HashProducer for Cairo0ContractClass {
type Error = Error;

fn generate_hash(&self) -> DevnetResult<Felt> {
match self {
Cairo0ContractClass::RawJson(contract_json) => Ok(contract_json.generate_hash()?),
Expand All @@ -62,6 +74,7 @@ impl HashProducer for Cairo0ContractClass {

impl TryInto<CompressedLegacyContractClass> for Cairo0ContractClass {
type Error = Error;

fn try_into(self) -> Result<CompressedLegacyContractClass, Self::Error> {
match self {
Cairo0ContractClass::Rpc(contract_class) => contract_class.try_into(),
Expand All @@ -72,6 +85,7 @@ impl TryInto<CompressedLegacyContractClass> for Cairo0ContractClass {

impl TryFrom<Cairo0ContractClass> for blockifier::execution::contract_class::ContractClassV0 {
type Error = Error;

fn try_from(value: Cairo0ContractClass) -> Result<Self, Self::Error> {
match value {
Cairo0ContractClass::RawJson(contract_class) => contract_class.try_into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,16 @@ impl HashProducer for DeprecatedContractClass {

impl TryInto<CompressedLegacyContractClass> for DeprecatedContractClass {
type Error = Error;

fn try_into(self) -> Result<CompressedLegacyContractClass, Self::Error> {
// TODO: improve
// Convert the DeprecatedContractClass into Cairo0Json
let cairo0: Cairo0Json = self.try_into()?;
cairo0.try_into()

// Convert Cairo0Json into CompressedLegacyContractClass
let compressed_contract_class: CompressedLegacyContractClass = cairo0.try_into()?;

// Return the compressed contract class
Ok(compressed_contract_class)
}
}

Expand Down
11 changes: 9 additions & 2 deletions crates/starknet-devnet-types/src/rpc/estimate_message_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ impl EstimateMessageFeeRequestWrapper {
Self { inner: EstimateMessageFeeRequest { message: msg_from_l1, block_id } }
}

// TODO: add ref wrapper
pub fn get_from_address(&self) -> EthAddressWrapper {
EthAddressWrapper { inner: self.inner.message.from_address.clone() }
}

pub fn with_from_address<F, R>(&self, f: F) -> R
where
F: FnOnce(&EthAddressWrapper) -> R,
{
let wrapper = EthAddressWrapper { inner: self.inner.message.from_address.clone() };
f(&wrapper)
}

pub fn get_to_address(&self) -> Felt {
self.inner.message.to_address
}
Expand Down Expand Up @@ -80,4 +87,4 @@ impl EstimateMessageFeeRequestWrapper {
}

impl_wrapper_serialize!(EstimateMessageFeeRequestWrapper);
impl_wrapper_deserialize!(EstimateMessageFeeRequestWrapper, EstimateMessageFeeRequest);
impl_wrapper_deserialize!(EstimateMessageFeeRequestWrapper, EstimateMessageFeeRequest);
1 change: 1 addition & 0 deletions crates/starknet-devnet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const RESPONSE_LOG_ENV_VAR: &str = "response";
/// paths to some module like this one: `starknet-devnet::cli` nothing gets logged. For example:
/// `RUST_LOG=request` is translated to `request=TRACE`, which means that will log TRACE level for
/// request module.

fn configure_tracing() {
let log_env_var = std::env::var(EnvFilter::DEFAULT_ENV).unwrap_or_default().to_lowercase();

Expand Down