-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03ce42f
commit a3b6b1e
Showing
3 changed files
with
56 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod mempool; | ||
pub(crate) mod priority_queue; | ||
pub mod staging_area; | ||
pub mod transaction_store; |
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
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,51 @@ | ||
use std::cmp::Ordering; | ||
use std::collections::HashMap; | ||
|
||
use starknet_api::core::{ContractAddress, Nonce}; | ||
use starknet_api::transaction::TransactionHash; | ||
use starknet_mempool_types::mempool_types::ThinTransaction; | ||
|
||
#[derive(Clone, Debug, Default)] | ||
pub struct StagingTransaction { | ||
pub tx_hash: TransactionHash, | ||
pub address: ContractAddress, | ||
pub nonce: Nonce, | ||
} | ||
|
||
impl PartialEq for StagingTransaction { | ||
fn eq(&self, other: &StagingTransaction) -> bool { | ||
self.address == other.address && self.nonce == other.nonce | ||
} | ||
} | ||
|
||
impl Eq for StagingTransaction {} | ||
|
||
impl Ord for StagingTransaction { | ||
fn cmp(&self, other: &Self) -> Ordering { | ||
self.address.cmp(&other.address).then_with(|| self.nonce.cmp(&other.nonce)) | ||
} | ||
} | ||
|
||
impl PartialOrd for StagingTransaction { | ||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
Some(self.cmp(other)) | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, Default, derive_more::Deref, derive_more::DerefMut)] | ||
pub struct StagingQueue(HashMap<TransactionHash, StagingTransaction>); | ||
impl StagingQueue { | ||
pub fn insert(&mut self, tx: StagingTransaction) { | ||
self.0.insert(tx.tx_hash, tx); | ||
} | ||
|
||
pub fn remove(&mut self, tx_hash: &TransactionHash) -> Option<StagingTransaction> { | ||
self.0.remove(tx_hash) | ||
} | ||
} | ||
|
||
impl From<ThinTransaction> for StagingTransaction { | ||
fn from(tx: ThinTransaction) -> Self { | ||
StagingTransaction { address: tx.sender_address, nonce: tx.nonce, tx_hash: tx.tx_hash } | ||
} | ||
} |