Skip to content

Commit

Permalink
Remove unused function
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianGCalderon committed Jul 11, 2024
1 parent 719b717 commit c82aea4
Showing 1 changed file with 19 additions and 102 deletions.
121 changes: 19 additions & 102 deletions rpc-state-reader/src/blockifier_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,41 +279,22 @@ fn calculate_class_info_for_testing(contract_class: ContractClass) -> ClassInfo
ClassInfo::new(&contract_class, sierra_program_length, 100).unwrap()
}

pub fn execute_tx_configurable_with_state(
tx_hash: &TransactionHash,
tx: SNTransaction,
block_info: BlockInfo,
_skip_validate: bool,
_skip_nonce_check: bool,
state: &mut CachedState<RpcStateReader>,
/// Executes a transaction with blockifier
///
/// Unlike `execute_tx_configurable`, it does not depend on our state reader
/// and can be used with any cached state. It already receives all context information
/// needed to execute the transaction.
pub fn execute_tx_with_blockifier(
state: &mut CachedState<impl StateReader>,
context: BlockContext,
transaction: SNTransaction,
transaction_hash: TransactionHash,
) -> TransactionExecutionResult<TransactionExecutionInfo> {
// let _fee_token_address = FeeTokenAddresses {
// strk_fee_token_address: ContractAddress::default(),
// eth_fee_token_address: ContractAddress(starknet_api::patricia_key!(
// "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
// )),
// };

// Get values for block context before giving ownership of the reader
let chain_id = state.state.0.get_chain_name();

let chain_info = ChainInfo {
chain_id,
fee_token_addresses: FeeTokenAddresses::default(),
};

let block_context = BlockContext::new_unchecked(
&block_info,
&chain_info,
&VersionedConstants::latest_constants_with_overrides(u32::MAX, usize::MAX),
);

// Get transaction before giving ownership of the reader
let blockifier_tx: AccountTransaction = match tx {
let account_transaction: AccountTransaction = match transaction {
SNTransaction::Invoke(tx) => {
let invoke = InvokeTransaction {
tx,
tx_hash: *tx_hash,
tx_hash: transaction_hash,
only_query: false,
};
AccountTransaction::Invoke(invoke)
Expand All @@ -329,7 +310,7 @@ pub fn execute_tx_configurable_with_state(
AccountTransaction::DeployAccount(DeployAccountTransaction {
only_query: false,
tx,
tx_hash: *tx_hash,
tx_hash: transaction_hash,
contract_address,
})
}
Expand All @@ -341,25 +322,23 @@ pub fn execute_tx_configurable_with_state(

let class_info = calculate_class_info_for_testing(contract_class);

let declare = DeclareTransaction::new(tx, *tx_hash, class_info).unwrap();
let declare = DeclareTransaction::new(tx, transaction_hash, class_info).unwrap();
AccountTransaction::Declare(declare)
}
SNTransaction::L1Handler(tx) => {
// As L1Hanlder is not an account transaction we execute it here and return the result
let blockifier_tx = L1HandlerTransaction {
let account_transaction = L1HandlerTransaction {
tx,
tx_hash: *tx_hash,
tx_hash: transaction_hash,
paid_fee_on_l1: starknet_api::transaction::Fee(u128::MAX),
};
return blockifier_tx.execute(state, &block_context, true, true);

return account_transaction.execute(state, &context, true, true);
}
_ => unimplemented!(),
};

#[cfg(not(feature = "cairo-native"))]
let blockifier_execution = blockifier_tx.execute(state, &block_context, false, true);

blockifier_execution
account_transaction.execute(state, &context, false, true)
}

pub fn execute_tx_configurable(
Expand All @@ -384,68 +363,6 @@ pub fn execute_tx_configurable(
Ok((blockifier_exec_info, trace, receipt))
}

/// Executes a transaction with blockifier
///
/// Unlike `execute_tx_configurable`, it does not depend on our state reader
/// and can be used with any cached state. It already receives all context information
/// needed to execute the transaction.
pub fn execute_tx_with_blockifier(
state: &mut CachedState<impl StateReader>,
context: BlockContext,
transaction: SNTransaction,
transaction_hash: TransactionHash,
) -> TransactionExecutionResult<TransactionExecutionInfo> {
let account_transaction: AccountTransaction = match transaction {
SNTransaction::Invoke(tx) => {
let invoke = InvokeTransaction {
tx,
tx_hash: transaction_hash,
only_query: false,
};
AccountTransaction::Invoke(invoke)
}
SNTransaction::DeployAccount(tx) => {
let contract_address = calculate_contract_address(
tx.contract_address_salt(),
tx.class_hash(),
&tx.constructor_calldata(),
ContractAddress::default(),
)
.unwrap();
AccountTransaction::DeployAccount(DeployAccountTransaction {
only_query: false,
tx,
tx_hash: transaction_hash,
contract_address,
})
}
SNTransaction::Declare(tx) => {
let contract_class = state
.state
.get_compiled_contract_class(tx.class_hash())
.unwrap();

let class_info = calculate_class_info_for_testing(contract_class);

let declare = DeclareTransaction::new(tx, transaction_hash, class_info).unwrap();
AccountTransaction::Declare(declare)
}
SNTransaction::L1Handler(tx) => {
// As L1Hanlder is not an account transaction we execute it here and return the result
let account_transaction = L1HandlerTransaction {
tx,
tx_hash: transaction_hash,
paid_fee_on_l1: starknet_api::transaction::Fee(u128::MAX),
};

return account_transaction.execute(state, &context, true, true);
}
_ => unimplemented!(),
};

account_transaction.execute(state, &context, false, true)
}

pub fn fetch_block_context(state: &RpcState, block_number: BlockNumber) -> BlockContext {
let rpc_block_info = state.get_block_info().unwrap();
let gas_price = state.get_gas_price(block_number.0).unwrap();
Expand Down

0 comments on commit c82aea4

Please sign in to comment.