Skip to content

Commit

Permalink
refactor(fee): impl direct convertion from py resource bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
nimrod-starkware committed Aug 19, 2024
1 parent 691aab8 commit 2934c20
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
3 changes: 1 addition & 2 deletions crates/native_blockifier/src/py_declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use starknet_api::transaction::{
DeclareTransactionV3,
Fee,
PaymasterData,
DeprecatedResourceBoundsMapping,
Tip,
TransactionHash,
TransactionSignature,
Expand Down Expand Up @@ -88,7 +87,7 @@ impl TryFrom<PyDeclareTransactionV3> for DeclareTransactionV3 {
type Error = NativeBlockifierInputError;
fn try_from(tx: PyDeclareTransactionV3) -> Result<Self, Self::Error> {
Ok(Self {
resource_bounds: DeprecatedResourceBoundsMapping::try_from(tx.resource_bounds)?,
resource_bounds: tx.resource_bounds.try_into()?,
tip: Tip(tx.tip),
signature: TransactionSignature(from_py_felts(tx.signature)),
nonce: Nonce(tx.nonce.0),
Expand Down
3 changes: 1 addition & 2 deletions crates/native_blockifier/src/py_deploy_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use starknet_api::transaction::{
DeployAccountTransactionV3,
Fee,
PaymasterData,
DeprecatedResourceBoundsMapping,
Tip,
TransactionHash,
TransactionSignature,
Expand Down Expand Up @@ -64,7 +63,7 @@ impl TryFrom<PyDeployAccountTransactionV3> for DeployAccountTransactionV3 {
type Error = NativeBlockifierInputError;
fn try_from(tx: PyDeployAccountTransactionV3) -> Result<Self, Self::Error> {
Ok(Self {
resource_bounds: DeprecatedResourceBoundsMapping::try_from(tx.resource_bounds)?,
resource_bounds: tx.resource_bounds.try_into()?,
tip: Tip(tx.tip),
signature: TransactionSignature(from_py_felts(tx.signature)),
nonce: Nonce(tx.nonce.0),
Expand Down
3 changes: 1 addition & 2 deletions crates/native_blockifier/src/py_invoke_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use starknet_api::transaction::{
InvokeTransactionV1,
InvokeTransactionV3,
PaymasterData,
DeprecatedResourceBoundsMapping,
Tip,
TransactionHash,
TransactionSignature,
Expand Down Expand Up @@ -87,7 +86,7 @@ impl TryFrom<PyInvokeTransactionV3> for InvokeTransactionV3 {
type Error = NativeBlockifierInputError;
fn try_from(tx: PyInvokeTransactionV3) -> Result<Self, Self::Error> {
Ok(Self {
resource_bounds: DeprecatedResourceBoundsMapping::try_from(tx.resource_bounds)?,
resource_bounds: tx.resource_bounds.try_into()?,
tip: Tip(tx.tip),
signature: TransactionSignature(from_py_felts(tx.signature)),
nonce: Nonce(tx.nonce.0),
Expand Down
16 changes: 14 additions & 2 deletions crates/native_blockifier/src/py_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ use blockifier::transaction::transaction_execution::Transaction;
use blockifier::transaction::transaction_types::TransactionType;
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use starknet_api::transaction::{Resource, ResourceBounds};
use starknet_api::transaction::{
DeprecatedResourceBoundsMapping,
Resource,
ResourceBounds,
ValidResourceBounds,
};
use starknet_api::StarknetApiError;

use crate::errors::{NativeBlockifierInputError, NativeBlockifierResult};
Expand Down Expand Up @@ -68,7 +73,7 @@ impl From<PyResourceBounds> for starknet_api::transaction::ResourceBounds {
#[derive(Clone, FromPyObject)]
pub struct PyResourceBoundsMapping(pub BTreeMap<PyResource, PyResourceBounds>);

impl TryFrom<PyResourceBoundsMapping> for starknet_api::transaction::DeprecatedResourceBoundsMapping {
impl TryFrom<PyResourceBoundsMapping> for DeprecatedResourceBoundsMapping {
type Error = StarknetApiError;
fn try_from(py_resource_bounds_mapping: PyResourceBoundsMapping) -> Result<Self, Self::Error> {
let resource_bounds_vec: Vec<(Resource, ResourceBounds)> = py_resource_bounds_mapping
Expand All @@ -82,6 +87,13 @@ impl TryFrom<PyResourceBoundsMapping> for starknet_api::transaction::DeprecatedR
}
}

impl TryFrom<PyResourceBoundsMapping> for ValidResourceBounds {
type Error = StarknetApiError;
fn try_from(py_resource_bounds_mapping: PyResourceBoundsMapping) -> Result<Self, Self::Error> {
DeprecatedResourceBoundsMapping::try_from(py_resource_bounds_mapping)?.0.try_into()
}
}

#[derive(Clone)]
pub enum PyDataAvailabilityMode {
L1 = 0,
Expand Down

0 comments on commit 2934c20

Please sign in to comment.