From 23037fa23ed1d71a39b7784a318b67810ff22c8b Mon Sep 17 00:00:00 2001 From: Nimrod Weiss Date: Mon, 19 Aug 2024 13:01:28 +0300 Subject: [PATCH] refactor(fee): impl direct convertion from py resource bounds --- crates/native_blockifier/src/py_declare.rs | 3 +-- .../native_blockifier/src/py_deploy_account.rs | 3 +-- .../native_blockifier/src/py_invoke_function.rs | 3 +-- crates/native_blockifier/src/py_transaction.rs | 16 ++++++++++++++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/crates/native_blockifier/src/py_declare.rs b/crates/native_blockifier/src/py_declare.rs index bfbd2894a66..b8d74535f08 100644 --- a/crates/native_blockifier/src/py_declare.rs +++ b/crates/native_blockifier/src/py_declare.rs @@ -12,7 +12,6 @@ use starknet_api::transaction::{ DeclareTransactionV3, Fee, PaymasterData, - DeprecatedResourceBoundsMapping, Tip, TransactionHash, TransactionSignature, @@ -88,7 +87,7 @@ impl TryFrom for DeclareTransactionV3 { type Error = NativeBlockifierInputError; fn try_from(tx: PyDeclareTransactionV3) -> Result { 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), diff --git a/crates/native_blockifier/src/py_deploy_account.rs b/crates/native_blockifier/src/py_deploy_account.rs index 749f19586ab..b25b464103d 100644 --- a/crates/native_blockifier/src/py_deploy_account.rs +++ b/crates/native_blockifier/src/py_deploy_account.rs @@ -12,7 +12,6 @@ use starknet_api::transaction::{ DeployAccountTransactionV3, Fee, PaymasterData, - DeprecatedResourceBoundsMapping, Tip, TransactionHash, TransactionSignature, @@ -64,7 +63,7 @@ impl TryFrom for DeployAccountTransactionV3 { type Error = NativeBlockifierInputError; fn try_from(tx: PyDeployAccountTransactionV3) -> Result { 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), diff --git a/crates/native_blockifier/src/py_invoke_function.rs b/crates/native_blockifier/src/py_invoke_function.rs index 111d53b0f18..974d0b9b1de 100644 --- a/crates/native_blockifier/src/py_invoke_function.rs +++ b/crates/native_blockifier/src/py_invoke_function.rs @@ -14,7 +14,6 @@ use starknet_api::transaction::{ InvokeTransactionV1, InvokeTransactionV3, PaymasterData, - DeprecatedResourceBoundsMapping, Tip, TransactionHash, TransactionSignature, @@ -87,7 +86,7 @@ impl TryFrom for InvokeTransactionV3 { type Error = NativeBlockifierInputError; fn try_from(tx: PyInvokeTransactionV3) -> Result { 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), diff --git a/crates/native_blockifier/src/py_transaction.rs b/crates/native_blockifier/src/py_transaction.rs index 15254e1181c..769a593305a 100644 --- a/crates/native_blockifier/src/py_transaction.rs +++ b/crates/native_blockifier/src/py_transaction.rs @@ -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}; @@ -68,7 +73,7 @@ impl From for starknet_api::transaction::ResourceBounds { #[derive(Clone, FromPyObject)] pub struct PyResourceBoundsMapping(pub BTreeMap); -impl TryFrom for starknet_api::transaction::DeprecatedResourceBoundsMapping { +impl TryFrom for DeprecatedResourceBoundsMapping { type Error = StarknetApiError; fn try_from(py_resource_bounds_mapping: PyResourceBoundsMapping) -> Result { let resource_bounds_vec: Vec<(Resource, ResourceBounds)> = py_resource_bounds_mapping @@ -82,6 +87,13 @@ impl TryFrom for starknet_api::transaction::DeprecatedR } } +impl TryFrom for ValidResourceBounds { + type Error = StarknetApiError; + fn try_from(py_resource_bounds_mapping: PyResourceBoundsMapping) -> Result { + DeprecatedResourceBoundsMapping::try_from(py_resource_bounds_mapping)?.0.try_into() + } +} + #[derive(Clone)] pub enum PyDataAvailabilityMode { L1 = 0,