-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transaction): implement executable transaction
- Loading branch information
1 parent
85ce3e0
commit a22c544
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters