Skip to content

Commit

Permalink
feat(starknet-api): derive serialize for executable transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadNassar1 committed Aug 15, 2024
1 parent 39ebf3c commit b14a78b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions crates/starknet_api/src/contract_class.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use serde::{Deserialize, Serialize};

/// Compiled contract class.
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum ContractClass {
V1(ContractClassV1),
}

/// Compiled contract class variant for Cairo 1 contracts.
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum ContractClassV1 {
Casm(CasmContractClass),
}

/// All relevant information about a declared contract class, including the compiled contract class
/// and other parameters derived from the original declare transaction required for billing.
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ClassInfo {
pub contract_class: ContractClass,
pub sierra_program_length: usize,
Expand Down
10 changes: 6 additions & 4 deletions crates/starknet_api/src/executable_transaction.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use serde::{Deserialize, Serialize};

use crate::contract_class::ClassInfo;
use crate::core::{ContractAddress, Nonce};
use crate::transaction::{Tip, TransactionHash};

/// Represents a paid Starknet transaction.
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum Transaction {
Declare(DeclareTransaction),
DeployAccount(DeployAccountTransaction),
Expand Down Expand Up @@ -54,21 +56,21 @@ impl Transaction {
}

// TODO(Mohammad): Add constructor for all the transaction's structs.
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct DeclareTransaction {
pub tx: crate::transaction::DeclareTransaction,
pub tx_hash: TransactionHash,
pub class_info: ClassInfo,
}

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

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

0 comments on commit b14a78b

Please sign in to comment.