From b14a78b3dae8c81b4faad0e04bf9e69c5ee8aaad Mon Sep 17 00:00:00 2001 From: Mohammad Nassar Date: Tue, 13 Aug 2024 13:46:27 +0300 Subject: [PATCH] feat(starknet-api): derive serialize for executable transaction --- crates/starknet_api/src/contract_class.rs | 7 ++++--- crates/starknet_api/src/executable_transaction.rs | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/starknet_api/src/contract_class.rs b/crates/starknet_api/src/contract_class.rs index 8d9d1be4ec1..4ea87879591 100644 --- a/crates/starknet_api/src/contract_class.rs +++ b/crates/starknet_api/src/contract_class.rs @@ -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, diff --git a/crates/starknet_api/src/executable_transaction.rs b/crates/starknet_api/src/executable_transaction.rs index b7ebff021a3..3b65f39a9f6 100644 --- a/crates/starknet_api/src/executable_transaction.rs +++ b/crates/starknet_api/src/executable_transaction.rs @@ -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), @@ -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,