Skip to content

Commit

Permalink
refactor(mempool): call rpc_deploy_account_tx from StarknetAPI (#2136)
Browse files Browse the repository at this point in the history
  • Loading branch information
noam-starkware authored Nov 21, 2024
1 parent 74b80c4 commit 02a4d32
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
32 changes: 2 additions & 30 deletions crates/mempool_test_utils/src/starknet_api_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use starknet_api::block::GasPrice;
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::executable_transaction::AccountTransaction;
use starknet_api::execution_resources::GasAmount;
use starknet_api::rpc_transaction::{ContractClass, RpcDeployAccountTransactionV3, RpcTransaction};
use starknet_api::rpc_transaction::{ContractClass, RpcTransaction};
use starknet_api::test_utils::declare::rpc_declare_tx;
use starknet_api::test_utils::deploy_account::DeployAccountTxArgs;
use starknet_api::test_utils::deploy_account::rpc_deploy_account_tx;
use starknet_api::test_utils::invoke::{rpc_invoke_tx, InvokeTxArgs};
use starknet_api::test_utils::NonceManager;
use starknet_api::transaction::fields::{
Expand All @@ -28,7 +28,6 @@ use starknet_api::transaction::fields::{
TransactionSignature,
ValidResourceBounds,
};
use starknet_api::transaction::TransactionVersion;
use starknet_api::{declare_tx_args, deploy_account_tx_args, felt, invoke_tx_args, nonce};
use starknet_types_core::felt::Felt;

Expand Down Expand Up @@ -362,33 +361,6 @@ impl Contract {
}
}

pub fn rpc_deploy_account_tx(deploy_tx_args: DeployAccountTxArgs) -> RpcTransaction {
if deploy_tx_args.version != TransactionVersion::THREE {
panic!("Unsupported transaction version: {:?}.", deploy_tx_args.version);
}

let ValidResourceBounds::AllResources(resource_bounds) = deploy_tx_args.resource_bounds else {
panic!("Unsupported resource bounds type: {:?}.", deploy_tx_args.resource_bounds)
};

starknet_api::rpc_transaction::RpcTransaction::DeployAccount(
starknet_api::rpc_transaction::RpcDeployAccountTransaction::V3(
RpcDeployAccountTransactionV3 {
resource_bounds,
tip: deploy_tx_args.tip,
contract_address_salt: deploy_tx_args.contract_address_salt,
class_hash: deploy_tx_args.class_hash,
constructor_calldata: deploy_tx_args.constructor_calldata,
nonce: deploy_tx_args.nonce,
signature: deploy_tx_args.signature,
nonce_data_availability_mode: deploy_tx_args.nonce_data_availability_mode,
fee_data_availability_mode: deploy_tx_args.fee_data_availability_mode,
paymaster_data: deploy_tx_args.paymaster_data,
},
),
)
}

pub fn rpc_tx_to_json(tx: &RpcTransaction) -> String {
let mut tx_json = serde_json::to_value(tx)
.unwrap_or_else(|tx| panic!("Failed to serialize transaction: {tx:?}"));
Expand Down
28 changes: 28 additions & 0 deletions crates/starknet_api/src/test_utils/deploy_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ use super::NonceManager;
use crate::core::{calculate_contract_address, ClassHash, ContractAddress, Nonce};
use crate::data_availability::DataAvailabilityMode;
use crate::executable_transaction::DeployAccountTransaction as ExecutableDeployAccountTransaction;
use crate::rpc_transaction::{
RpcDeployAccountTransaction,
RpcDeployAccountTransactionV3,
RpcTransaction,
};
use crate::transaction::fields::{
Calldata,
ContractAddressSalt,
Expand Down Expand Up @@ -124,3 +129,26 @@ pub fn executable_deploy_account_tx(

ExecutableDeployAccountTransaction { tx, tx_hash, contract_address }
}

pub fn rpc_deploy_account_tx(deploy_tx_args: DeployAccountTxArgs) -> RpcTransaction {
if deploy_tx_args.version != TransactionVersion::THREE {
panic!("Unsupported transaction version: {:?}.", deploy_tx_args.version);
}

let ValidResourceBounds::AllResources(resource_bounds) = deploy_tx_args.resource_bounds else {
panic!("Unsupported resource bounds type: {:?}.", deploy_tx_args.resource_bounds)
};

RpcTransaction::DeployAccount(RpcDeployAccountTransaction::V3(RpcDeployAccountTransactionV3 {
resource_bounds,
tip: deploy_tx_args.tip,
contract_address_salt: deploy_tx_args.contract_address_salt,
class_hash: deploy_tx_args.class_hash,
constructor_calldata: deploy_tx_args.constructor_calldata,
nonce: deploy_tx_args.nonce,
signature: deploy_tx_args.signature,
nonce_data_availability_mode: deploy_tx_args.nonce_data_availability_mode,
fee_data_availability_mode: deploy_tx_args.fee_data_availability_mode,
paymaster_data: deploy_tx_args.paymaster_data,
}))
}
2 changes: 1 addition & 1 deletion crates/starknet_gateway/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use mempool_test_utils::starknet_api_test_utils::rpc_deploy_account_tx;
use starknet_api::block::GasPrice;
use starknet_api::core::ContractAddress;
use starknet_api::data_availability::DataAvailabilityMode;
use starknet_api::execution_resources::GasAmount;
use starknet_api::rpc_transaction::{ContractClass, RpcTransaction};
use starknet_api::test_utils::declare::{rpc_declare_tx, TEST_SENDER_ADDRESS};
use starknet_api::test_utils::deploy_account::rpc_deploy_account_tx;
use starknet_api::test_utils::invoke::rpc_invoke_tx;
use starknet_api::transaction::fields::{
AccountDeploymentData,
Expand Down

0 comments on commit 02a4d32

Please sign in to comment.