@@ -10,6 +10,10 @@ use uuid::Uuid;
1010/// Block time in microseconds
1111pub const BLOCK_TIME : u128 = 2_000_000 ;
1212
13+ pub trait BundleProperties {
14+ fn bundle_hash ( & self ) -> B256 ;
15+ }
16+
1317#[ derive( Default , Debug , Serialize , Deserialize , Clone , PartialEq , Eq ) ]
1418#[ serde( rename_all = "camelCase" ) ]
1519pub struct Bundle {
@@ -56,6 +60,26 @@ pub struct Bundle {
5660 pub dropping_tx_hashes : Vec < TxHash > ,
5761}
5862
63+ impl BundleProperties for Bundle {
64+ fn bundle_hash ( & self ) -> B256 {
65+ let transactions: Vec < OpTxEnvelope > = self
66+ . txs
67+ . iter ( )
68+ . map ( |b| {
69+ OpTxEnvelope :: decode_2718_exact ( b)
70+ . map_err ( |e| format ! ( "failed to decode transaction: {e}" ) )
71+ } )
72+ . collect :: < Result < Vec < _ > , _ > > ( )
73+ . expect ( "failed to decode transactions" ) ;
74+
75+ let mut concatenated = Vec :: new ( ) ;
76+ for tx in transactions {
77+ concatenated. extend_from_slice ( tx. tx_hash ( ) . as_slice ( ) ) ;
78+ }
79+ keccak256 ( & concatenated)
80+ }
81+ }
82+
5983#[ derive( Debug , Clone , Serialize , Deserialize ) ]
6084#[ serde( rename_all = "camelCase" ) ]
6185pub struct BundleHash {
@@ -115,14 +139,6 @@ impl BundleWithMetadata {
115139 & self . uuid
116140 }
117141
118- pub fn bundle_hash ( & self ) -> B256 {
119- let mut concatenated = Vec :: new ( ) ;
120- for tx in self . transactions ( ) {
121- concatenated. extend_from_slice ( tx. tx_hash ( ) . as_slice ( ) ) ;
122- }
123- keccak256 ( & concatenated)
124- }
125-
126142 pub fn txn_hashes ( & self ) -> Vec < TxHash > {
127143 self . transactions ( ) . iter ( ) . map ( |t| t. tx_hash ( ) ) . collect ( )
128144 }
@@ -150,6 +166,12 @@ impl BundleWithMetadata {
150166 }
151167}
152168
169+ impl BundleProperties for BundleWithMetadata {
170+ fn bundle_hash ( & self ) -> B256 {
171+ self . bundle . bundle_hash ( )
172+ }
173+ }
174+
153175#[ derive( Debug , Clone , Serialize , Deserialize ) ]
154176#[ serde( rename_all = "camelCase" ) ]
155177pub struct TransactionResult {
0 commit comments