Skip to content

Commit

Permalink
feat(papyrus_rpc): add l1_data_gas to ResourceBoundsMapping according…
Browse files Browse the repository at this point in the history
… to V08
  • Loading branch information
ayeletstarkware committed Jan 28, 2025
1 parent 2adc141 commit a6a7823
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
6 changes: 4 additions & 2 deletions crates/papyrus_rpc/src/v0_8/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ fn user_deprecated_contract_class_to_sn_api(
})
}

// TODO(Ayelet): Change to From function.
impl TryFrom<DeployAccountTransaction> for starknet_api::transaction::DeployAccountTransaction {
type Error = ErrorObjectOwned;
fn try_from(tx: DeployAccountTransaction) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -565,7 +566,7 @@ impl TryFrom<DeployAccountTransaction> for starknet_api::transaction::DeployAcco
nonce_data_availability_mode,
fee_data_availability_mode,
}) => Self::V3(starknet_api::transaction::DeployAccountTransactionV3 {
resource_bounds: resource_bounds.try_into()?,
resource_bounds: resource_bounds.into(),
tip,
signature,
nonce,
Expand All @@ -580,6 +581,7 @@ impl TryFrom<DeployAccountTransaction> for starknet_api::transaction::DeployAcco
}
}

// TODO(Ayelet): Change to From function.
impl TryFrom<InvokeTransaction> for starknet_api::transaction::InvokeTransaction {
type Error = ErrorObjectOwned;
fn try_from(value: InvokeTransaction) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -625,7 +627,7 @@ impl TryFrom<InvokeTransaction> for starknet_api::transaction::InvokeTransaction
nonce_data_availability_mode,
fee_data_availability_mode,
}) => Self::V3(starknet_api::transaction::InvokeTransactionV3 {
resource_bounds: resource_bounds.try_into()?,
resource_bounds: resource_bounds.into(),
tip,
signature,
nonce,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ auto_impl_get_test_instance! {

pub struct ResourceBoundsMapping {
pub l1_gas: ResourceBounds,
pub l1_data_gas: ResourceBounds,
pub l2_gas: ResourceBounds,
}
}
Expand Down
41 changes: 26 additions & 15 deletions crates/papyrus_rpc/src/v0_8/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,22 @@ impl From<starknet_api::transaction::DeclareTransactionV2> for DeclareTransactio
#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
pub struct ResourceBoundsMapping {
pub l1_gas: ResourceBounds,
pub l1_data_gas: ResourceBounds,
pub l2_gas: ResourceBounds,
}

impl From<ResourceBoundsMapping>
for starknet_api::transaction::fields::DeprecatedResourceBoundsMapping
{
fn from(value: ResourceBoundsMapping) -> Self {
Self([(Resource::L1Gas, value.l1_gas), (Resource::L2Gas, value.l2_gas)].into())
Self(
[
(Resource::L1Gas, value.l1_gas),
(Resource::L1DataGas, value.l1_data_gas),
(Resource::L2Gas, value.l2_gas),
]
.into(),
)
}
}

Expand All @@ -171,31 +179,33 @@ impl From<starknet_api::transaction::fields::DeprecatedResourceBoundsMapping>
fn from(value: starknet_api::transaction::fields::DeprecatedResourceBoundsMapping) -> Self {
Self {
l1_gas: value.0.get(&Resource::L1Gas).cloned().unwrap_or_default(),
l1_data_gas: value.0.get(&Resource::L1DataGas).cloned().unwrap_or_default(),
l2_gas: value.0.get(&Resource::L2Gas).cloned().unwrap_or_default(),
}
}
}

impl TryFrom<ResourceBoundsMapping> for starknet_api::transaction::fields::ValidResourceBounds {
type Error = ErrorObjectOwned;
fn try_from(value: ResourceBoundsMapping) -> Result<Self, Self::Error> {
if !value.l2_gas.is_zero() {
Err(internal_server_error("Got a transaction with non zero l2 gas."))
} else {
Ok(Self::L1Gas(value.l1_gas))
}
impl From<ResourceBoundsMapping> for starknet_api::transaction::fields::ValidResourceBounds {
fn from(value: ResourceBoundsMapping) -> Self {
Self::AllResources(AllResourceBounds {
l1_gas: value.l1_gas,
l1_data_gas: value.l1_data_gas,
l2_gas: value.l2_gas,
})
}
}

impl From<starknet_api::transaction::fields::ValidResourceBounds> for ResourceBoundsMapping {
fn from(value: starknet_api::transaction::fields::ValidResourceBounds) -> Self {
match value {
starknet_api::transaction::fields::ValidResourceBounds::L1Gas(l1_gas) => {
Self { l1_gas, l2_gas: ResourceBounds::default() }
}
starknet_api::transaction::fields::ValidResourceBounds::L1Gas(l1_gas) => Self {
l1_gas,
l1_data_gas: ResourceBounds::default(),
l2_gas: ResourceBounds::default(),
},
starknet_api::transaction::fields::ValidResourceBounds::AllResources(
AllResourceBounds { l1_gas, l2_gas, .. },
) => Self { l1_gas, l2_gas },
AllResourceBounds { l1_gas, l1_data_gas, l2_gas },
) => Self { l1_gas, l1_data_gas, l2_gas },
}
}
}
Expand Down Expand Up @@ -845,7 +855,8 @@ pub struct L1HandlerTransactionOutput {
}

// Note: This is not the same as the Builtins in starknet_api, the serialization of SegmentArena is
// different. TODO(yair): remove this once a newer version of the API is published.
// different.
// TODO(yair): remove this once a newer version of the API is published.
#[derive(Debug, Clone, Eq, Hash, PartialEq, Deserialize, Serialize, PartialOrd, Ord)]
pub enum Builtin {
#[serde(rename = "range_check_builtin_applications")]
Expand Down

0 comments on commit a6a7823

Please sign in to comment.