Skip to content

Commit

Permalink
feat(starknet_api): add try_from transaction to executable tx in depl…
Browse files Browse the repository at this point in the history
…oy account (#3196)
  • Loading branch information
ArniStarkware authored Jan 9, 2025
1 parent a88666c commit 1a4ecd4
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions crates/starknet_api/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use starknet_types_core::felt::Felt;

use crate::block::{BlockHash, BlockNumber};
use crate::core::{
calculate_contract_address,
ChainId,
ClassHash,
CompiledClassHash,
Expand Down Expand Up @@ -141,6 +142,23 @@ impl TryFrom<(Transaction, &ChainId)> for executable_transaction::Transaction {
fn try_from((tx, chain_id): (Transaction, &ChainId)) -> Result<Self, Self::Error> {
let tx_hash = tx.calculate_transaction_hash(chain_id)?;
match tx {
Transaction::DeployAccount(tx) => {
let contract_address = calculate_contract_address(
tx.contract_address_salt(),
tx.class_hash(),
&tx.constructor_calldata(),
ContractAddress::default(),
)?;
Ok(executable_transaction::Transaction::Account(
executable_transaction::AccountTransaction::DeployAccount(
executable_transaction::DeployAccountTransaction {
tx,
tx_hash,
contract_address,
},
),
))
}
Transaction::Invoke(tx) => Ok(executable_transaction::Transaction::Account(
executable_transaction::AccountTransaction::Invoke(
executable_transaction::InvokeTransaction { tx, tx_hash },
Expand All @@ -156,8 +174,8 @@ impl TryFrom<(Transaction, &ChainId)> for executable_transaction::Transaction {
)),
_ => {
unimplemented!(
"Unsupported transaction type. Only Invoke and L1Handler are currently \
supported. tx: {:?}",
"Unsupported transaction type. Only DeployAccount, Invoke and L1Handler are \
currently supported. tx: {:?}",
tx
)
}
Expand Down

0 comments on commit 1a4ecd4

Please sign in to comment.