Skip to content

Commit 56acf48

Browse files
authored
feat: PartialEq bounds (#53)
* feat: PartialEq impls * feat: Bundle PartialEq impl on hash
1 parent b0e1ba3 commit 56acf48

File tree

9 files changed

+27
-6
lines changed

9 files changed

+27
-6
lines changed

examples/custom-bundle-type.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use {
2525
std::sync::Arc,
2626
};
2727

28-
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
28+
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2929
struct CustomPlatform;
3030

3131
impl Platform for CustomPlatform {
@@ -280,6 +280,12 @@ fn transfer_tx(
280280
.with_signer(signer.address())
281281
}
282282

283+
impl PartialEq for CustomBundleType {
284+
fn eq(&self, other: &Self) -> bool {
285+
self.hash() == other.hash()
286+
}
287+
}
288+
283289
#[derive(Debug)]
284290
struct MinimumProfitNotMet {
285291
min: U256,

src/payload/block.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ impl<P: Platform> Clone for BlockContext<P> {
4545
}
4646
}
4747

48+
impl<P: Platform> PartialEq for BlockContext<P> {
49+
fn eq(&self, other: &Self) -> bool {
50+
Arc::ptr_eq(&self.inner, &other.inner)
51+
}
52+
}
53+
4854
/// Constructors
4955
impl<P: Platform> BlockContext<P> {
5056
/// To create a new [`BlockContext`], we need:

src/payload/checkpoint.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ impl<P: Platform> IntoIterator for &Checkpoint<P> {
294294

295295
/// Describes the type of state mutation that was applied to the previous
296296
/// checkpoint to create this checkpoint.
297+
#[derive(Debug, PartialEq)]
297298
enum Mutation<P: Platform> {
298299
/// A checkpoint that indicates that any prior checkpoints are immutable and
299300
/// should not be discarded or reordered. An example of this would be placing

src/payload/exec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub enum ExecutionError<P: Platform> {
5353

5454
/// Describes an atomic unit of execution that can be used to create a state
5555
/// transition checkpoint.
56-
#[derive(Debug, Clone)]
56+
#[derive(Debug, Clone, PartialEq)]
5757
pub enum Executable<P: Platform> {
5858
// Individual transaction
5959
Transaction(Recovered<types::Transaction<P>>),
@@ -372,7 +372,7 @@ impl<P: PlatformWithRpcTypes> IntoExecutable<P, Variant<7>>
372372
///
373373
/// Types implementing this trait provide access to the individual results of
374374
/// transaction executions that make up this overall result.
375-
#[derive(Debug, Clone)]
375+
#[derive(Debug, Clone, PartialEq)]
376376
pub struct ExecutionResult<P: Platform> {
377377
/// The executable used to produce this result.
378378
source: Executable<P>,

src/platform/bundle/flashbots.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ impl<P: Platform> FlashbotsBundle<P> {
238238
}
239239
}
240240

241+
/// `PartialEq` by bundle hash
242+
impl<P: Platform> PartialEq for FlashbotsBundle<P> {
243+
fn eq(&self, other: &Self) -> bool {
244+
self.hash() == other.hash()
245+
}
246+
}
247+
241248
impl<P: Platform> Serialize for FlashbotsBundle<P> {
242249
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
243250
where

src/platform/bundle/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub use ext::BundleExt;
2929
///
3030
/// [`eth_sendBundle`]: https://docs.flashbots.net/flashbots-auction/searchers/advanced/rpc-endpoint#eth_sendbundle
3131
pub trait Bundle<P: Platform>:
32-
Serialize + DeserializeOwned + Clone + Debug + Send + Sync + 'static
32+
Serialize + DeserializeOwned + Clone + PartialEq + Debug + Send + Sync + 'static
3333
{
3434
type PostExecutionError: core::error::Error + Send + Sync + 'static;
3535

src/platform/ethereum/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ mod limits;
6262
mod pool;
6363

6464
/// Platform definition for ethereum mainnet.
65-
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
65+
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
6666
pub struct Ethereum;
6767

6868
impl Platform for Ethereum {

src/platform/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub trait Platform:
4444
Sized
4545
+ Default
4646
+ Clone
47+
+ PartialEq
4748
+ Serialize
4849
+ DeserializeOwned
4950
+ core::fmt::Debug

src/platform/optimism/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mod limits;
2424
pub use limits::OptimismDefaultLimits;
2525

2626
/// Platform definition for Optimism Rollup chains.
27-
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
27+
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2828
pub struct Optimism;
2929

3030
impl Platform for Optimism {

0 commit comments

Comments
 (0)