@@ -531,18 +531,34 @@ pub trait DatabaseReadOperations: ReadConnectionProvider + Sync {
531531 /// `start` point.
532532 async fn get_l1_messages < ' a > (
533533 & ' a self ,
534- start : Option < L1MessageStart > ,
534+ start : Option < L1MessageKey > ,
535535 ) -> Result < impl Stream < Item = Result < L1MessageEnvelope , DatabaseError > > + ' a , DatabaseError >
536536 {
537537 let queue_index = match start {
538- Some ( L1MessageStart :: Index ( i) ) => i,
539- Some ( L1MessageStart :: Hash ( ref h) ) => {
538+ Some ( L1MessageKey :: QueueIndex ( i) ) => i,
539+ Some ( L1MessageKey :: TransactionHash ( ref h) ) => {
540540 // Lookup message by hash
541541 let record = models:: l1_message:: Entity :: find ( )
542542 . filter ( models:: l1_message:: Column :: Hash . eq ( h. to_vec ( ) ) )
543543 . one ( self . get_connection ( ) )
544544 . await ?
545- . ok_or_else ( || DatabaseError :: L1MessageNotFound ( L1MessageStart :: Hash ( * h) ) ) ?;
545+ . ok_or_else ( || {
546+ DatabaseError :: L1MessageNotFound ( L1MessageKey :: TransactionHash ( * h) )
547+ } ) ?;
548+
549+ record. queue_index as u64
550+ }
551+ Some ( L1MessageKey :: QueueHash ( ref h) ) => {
552+ // Lookup message by queue hash
553+ let record = models:: l1_message:: Entity :: find ( )
554+ . filter (
555+ Condition :: all ( )
556+ . add ( models:: l1_message:: Column :: QueueHash . is_not_null ( ) )
557+ . add ( models:: l1_message:: Column :: QueueHash . eq ( h. to_vec ( ) ) ) ,
558+ )
559+ . one ( self . get_connection ( ) )
560+ . await ?
561+ . ok_or_else ( || DatabaseError :: L1MessageNotFound ( L1MessageKey :: QueueHash ( * h) ) ) ?;
546562
547563 record. queue_index as u64
548564 }
@@ -691,36 +707,43 @@ pub trait DatabaseReadOperations: ReadConnectionProvider + Sync {
691707 }
692708}
693709
694- /// This type defines the start of an L1 message stream .
710+ /// A key for an L1 message stored in the database .
695711///
696- /// It can either be an index, which is the queue index of the first message to return, or a hash,
697- /// which is the hash of the first message to return.
712+ /// It can either be the queue index, queue hash or the transaction hash.
698713#[ derive( Debug , Clone , PartialEq , Eq ) ]
699- pub enum L1MessageStart {
700- /// Start from the provided queue index.
701- Index ( u64 ) ,
702- /// Start from the provided queue hash.
703- Hash ( B256 ) ,
714+ pub enum L1MessageKey {
715+ /// The queue index of the message.
716+ QueueIndex ( u64 ) ,
717+ /// The queue hash of the message.
718+ QueueHash ( B256 ) ,
719+ /// The transaction hash of the message.
720+ TransactionHash ( B256 ) ,
704721}
705722
706- impl fmt:: Display for L1MessageStart {
707- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
708- match self {
709- Self :: Index ( index) => write ! ( f, "Index({index})" ) ,
710- Self :: Hash ( hash) => write ! ( f, "Hash({hash:#x})" ) ,
711- }
723+ impl L1MessageKey {
724+ /// Create a new [`L1MessageKey`] from a queue index.
725+ pub const fn from_queue_index ( index : u64 ) -> Self {
726+ Self :: QueueIndex ( index)
727+ }
728+
729+ /// Create a new [`L1MessageKey`] from a queue hash.
730+ pub const fn from_queue_hash ( hash : B256 ) -> Self {
731+ Self :: QueueHash ( hash)
712732 }
713- }
714733
715- impl From < u64 > for L1MessageStart {
716- fn from ( value : u64 ) -> Self {
717- Self :: Index ( value )
734+ /// Create a new [`L1MessageKey`] from a transaction hash.
735+ pub const fn from_transaction_hash ( hash : B256 ) -> Self {
736+ Self :: TransactionHash ( hash )
718737 }
719738}
720739
721- impl From < B256 > for L1MessageStart {
722- fn from ( value : B256 ) -> Self {
723- Self :: Hash ( value)
740+ impl fmt:: Display for L1MessageKey {
741+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
742+ match self {
743+ Self :: QueueIndex ( index) => write ! ( f, "QueueIndex({index})" ) ,
744+ Self :: QueueHash ( hash) => write ! ( f, "QueueHash({hash:#x})" ) ,
745+ Self :: TransactionHash ( hash) => write ! ( f, "TransactionHash({hash:#x})" ) ,
746+ }
724747 }
725748}
726749
0 commit comments