Skip to content

Commit

Permalink
feat(transaction): implement executable transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadNassar1 committed Apr 24, 2024
1 parent 85ce3e0 commit a22c544
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/executable_transaction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use crate::core::{ContractAddress, Nonce};
use crate::state::ContractClass;
use crate::transaction::TransactionHash;

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

impl Transaction {
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(),
}
}

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(),
}
}
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DeclareTransaction {
pub tx: crate::transaction::DeclareTransaction,
pub tx_hash: TransactionHash,
pub class_info: ClassInfo,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DeployAccountTransaction {
pub tx: crate::transaction::DeployAccountTransaction,
pub tx_hash: TransactionHash,
pub contract_address: ContractAddress,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InvokeTransaction {
pub tx: crate::transaction::InvokeTransaction,
pub tx_hash: TransactionHash,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ClassInfo {
// TODO: Change to compoiled contract.
pub contract_class: ContractClass,
pub sierra_program_length: usize,
pub abi_length: usize,
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod core;
pub mod crypto;
pub mod data_availability;
pub mod deprecated_contract_class;
pub mod executable_transaction;
pub mod external_transaction;
pub mod hash;
pub mod internal_transaction;
Expand Down

0 comments on commit a22c544

Please sign in to comment.