Skip to content

Commit

Permalink
refactor(starknet_api): rename executable tx to account tx
Browse files Browse the repository at this point in the history
  • Loading branch information
yair-starkware committed Nov 4, 2024
1 parent 6d7572e commit dd144cb
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions crates/starknet_api/src/executable_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,23 @@ macro_rules! implement_getter_calls {
};
}

// TODO: Remove after introducing new transaction type.
pub type Transaction = AccountTransaction;

/// Represents a paid Starknet transaction.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum Transaction {
pub enum AccountTransaction {
Declare(DeclareTransaction),
DeployAccount(DeployAccountTransaction),
Invoke(InvokeTransaction),
}

impl Transaction {
impl AccountTransaction {
pub fn contract_address(&self) -> ContractAddress {
match self {
Transaction::Declare(tx_data) => tx_data.tx.sender_address(),
Transaction::DeployAccount(tx_data) => tx_data.contract_address,
Transaction::Invoke(tx_data) => tx_data.tx.sender_address(),
AccountTransaction::Declare(tx_data) => tx_data.tx.sender_address(),
AccountTransaction::DeployAccount(tx_data) => tx_data.contract_address,
AccountTransaction::Invoke(tx_data) => tx_data.tx.sender_address(),
}
}

Expand All @@ -65,32 +68,32 @@ impl Transaction {

pub fn nonce(&self) -> Nonce {
match self {
Transaction::Declare(tx_data) => tx_data.tx.nonce(),
Transaction::DeployAccount(tx_data) => tx_data.tx.nonce(),
Transaction::Invoke(tx_data) => tx_data.tx.nonce(),
AccountTransaction::Declare(tx_data) => tx_data.tx.nonce(),
AccountTransaction::DeployAccount(tx_data) => tx_data.tx.nonce(),
AccountTransaction::Invoke(tx_data) => tx_data.tx.nonce(),
}
}

pub fn tx_hash(&self) -> TransactionHash {
match self {
Transaction::Declare(tx_data) => tx_data.tx_hash,
Transaction::DeployAccount(tx_data) => tx_data.tx_hash,
Transaction::Invoke(tx_data) => tx_data.tx_hash,
AccountTransaction::Declare(tx_data) => tx_data.tx_hash,
AccountTransaction::DeployAccount(tx_data) => tx_data.tx_hash,
AccountTransaction::Invoke(tx_data) => tx_data.tx_hash,
}
}

// TODO(Mohammad): add a getter macro.
pub fn tip(&self) -> Option<Tip> {
match self {
Transaction::Declare(declare_tx) => match &declare_tx.tx {
AccountTransaction::Declare(declare_tx) => match &declare_tx.tx {
crate::transaction::DeclareTransaction::V3(tx_v3) => Some(tx_v3.tip),
_ => None,
},
Transaction::DeployAccount(deploy_account_tx) => match &deploy_account_tx.tx {
AccountTransaction::DeployAccount(deploy_account_tx) => match &deploy_account_tx.tx {
crate::transaction::DeployAccountTransaction::V3(tx_v3) => Some(tx_v3.tip),
_ => None,
},
Transaction::Invoke(invoke_tx) => match &invoke_tx.tx {
AccountTransaction::Invoke(invoke_tx) => match &invoke_tx.tx {
crate::transaction::InvokeTransaction::V3(tx_v3) => Some(tx_v3.tip),
_ => None,
},
Expand All @@ -99,17 +102,17 @@ impl Transaction {

pub fn resource_bounds(&self) -> Option<&ValidResourceBounds> {
match self {
Transaction::Declare(declare_tx) => match &declare_tx.tx {
AccountTransaction::Declare(declare_tx) => match &declare_tx.tx {
crate::transaction::DeclareTransaction::V3(tx_v3) => Some(&tx_v3.resource_bounds),
_ => None,
},
Transaction::DeployAccount(deploy_account_tx) => match &deploy_account_tx.tx {
AccountTransaction::DeployAccount(deploy_account_tx) => match &deploy_account_tx.tx {
crate::transaction::DeployAccountTransaction::V3(tx_v3) => {
Some(&tx_v3.resource_bounds)
}
_ => None,
},
Transaction::Invoke(invoke_tx) => match &invoke_tx.tx {
AccountTransaction::Invoke(invoke_tx) => match &invoke_tx.tx {
crate::transaction::InvokeTransaction::V3(tx_v3) => Some(&tx_v3.resource_bounds),
_ => None,
},
Expand All @@ -121,8 +124,8 @@ impl Transaction {
rpc_tx: RpcTransaction,
tx_hash: TransactionHash,
sender_address: ContractAddress,
) -> Transaction {
Transaction::Invoke(crate::executable_transaction::InvokeTransaction {
) -> AccountTransaction {
AccountTransaction::Invoke(crate::executable_transaction::InvokeTransaction {
tx: crate::transaction::InvokeTransaction::V3(
crate::transaction::InvokeTransactionV3 {
sender_address,
Expand Down

0 comments on commit dd144cb

Please sign in to comment.