diff --git a/Cargo.lock b/Cargo.lock index 760fa984..4ab08a1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5593,6 +5593,7 @@ name = "starknet_mempool_types" version = "0.0.0" dependencies = [ "async-trait", + "serde", "starknet_api", "starknet_mempool_infra", "thiserror", diff --git a/crates/mempool_types/Cargo.toml b/crates/mempool_types/Cargo.toml index e4284586..198db6d1 100644 --- a/crates/mempool_types/Cargo.toml +++ b/crates/mempool_types/Cargo.toml @@ -10,6 +10,7 @@ workspace = true [dependencies] async-trait.workspace = true +serde.workspace = true starknet_api.workspace = true starknet_mempool_infra = { path = "../mempool_infra" } thiserror.workspace = true diff --git a/crates/mempool_types/src/communication.rs b/crates/mempool_types/src/communication.rs index d40096d5..e6253698 100644 --- a/crates/mempool_types/src/communication.rs +++ b/crates/mempool_types/src/communication.rs @@ -1,6 +1,7 @@ use std::sync::Arc; use async_trait::async_trait; +use serde::{Deserialize, Serialize}; use starknet_mempool_infra::component_client::{ClientError, ComponentClient}; use starknet_mempool_infra::component_definitions::ComponentRequestAndResponseSender; use thiserror::Error; @@ -23,13 +24,13 @@ pub trait MempoolClient: Send + Sync { async fn get_txs(&self, n_txs: usize) -> MempoolClientResult>; } -#[derive(Debug)] +#[derive(Debug, Serialize, Deserialize)] pub enum MempoolRequest { AddTransaction(MempoolInput), GetTransactions(usize), } -#[derive(Debug)] +#[derive(Debug, Serialize, Deserialize)] pub enum MempoolResponse { AddTransaction(MempoolResult<()>), GetTransactions(MempoolResult>), diff --git a/crates/mempool_types/src/errors.rs b/crates/mempool_types/src/errors.rs index d80281e7..a85115d5 100644 --- a/crates/mempool_types/src/errors.rs +++ b/crates/mempool_types/src/errors.rs @@ -1,7 +1,8 @@ +use serde::{Deserialize, Serialize}; use starknet_api::transaction::TransactionHash; use thiserror::Error; -#[derive(Clone, Debug, Error)] +#[derive(Clone, Debug, Error, Serialize, Deserialize)] pub enum MempoolError { #[error("Duplicate transaction, with hash: {tx_hash}")] DuplicateTransaction { tx_hash: TransactionHash }, diff --git a/crates/mempool_types/src/mempool_types.rs b/crates/mempool_types/src/mempool_types.rs index a8b6ed87..aad8d5bd 100644 --- a/crates/mempool_types/src/mempool_types.rs +++ b/crates/mempool_types/src/mempool_types.rs @@ -1,9 +1,10 @@ +use serde::{Deserialize, Serialize}; use starknet_api::core::{ContractAddress, Nonce}; use starknet_api::transaction::{Tip, TransactionHash}; use crate::errors::MempoolError; -#[derive(Clone, Debug, Default, Eq, PartialEq)] +#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] pub struct ThinTransaction { pub sender_address: ContractAddress, pub tx_hash: TransactionHash, @@ -11,20 +12,20 @@ pub struct ThinTransaction { pub nonce: Nonce, } -#[derive(Clone, Copy, Debug, Default)] +#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)] pub struct AccountState { pub nonce: Nonce, // TODO: add balance field when needed. } -#[derive(Clone, Copy, Debug, Default)] +#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)] pub struct Account { // TODO(Ayelet): Consider removing this field as it is duplicated in ThinTransaction. pub sender_address: ContractAddress, pub state: AccountState, } -#[derive(Debug, Default)] +#[derive(Debug, Default, Serialize, Deserialize)] pub struct MempoolInput { pub tx: ThinTransaction, pub account: Account,