@@ -161,6 +161,21 @@ impl CardanoTransactionRepository {
161
161
)
162
162
}
163
163
164
+ /// Get the highest start [BlockNumber] of the block range roots stored in the database.
165
+ pub async fn get_highest_start_block_number_for_block_range_roots (
166
+ & self ,
167
+ ) -> StdResult < Option < BlockNumber > > {
168
+ let highest: Option < i64 > = self
169
+ . connection
170
+ . query_single_cell ( "select max(start) as highest from block_range_root;" , & [ ] ) ?;
171
+ highest
172
+ . map ( u64:: try_from)
173
+ . transpose ( )
174
+ . with_context ( ||
175
+ format ! ( "Integer field max(start) (value={highest:?}) is incompatible with u64 representation." )
176
+ )
177
+ }
178
+
164
179
/// Retrieve all the Block Range Roots in database up to the given end block number excluded.
165
180
pub async fn retrieve_block_range_roots_up_to (
166
181
& self ,
@@ -874,4 +889,37 @@ mod tests {
874
889
. unwrap ( ) ;
875
890
assert_eq ! ( Vec :: <CardanoTransactionRecord >:: new( ) , transaction_result) ;
876
891
}
892
+
893
+ #[ tokio:: test]
894
+ async fn get_highest_start_block_number_for_block_range_roots ( ) {
895
+ let connection = Arc :: new ( cardano_tx_db_connection ( ) . unwrap ( ) ) ;
896
+ let repository = CardanoTransactionRepository :: new ( connection) ;
897
+
898
+ let highest = repository
899
+ . get_highest_start_block_number_for_block_range_roots ( )
900
+ . await
901
+ . unwrap ( ) ;
902
+ assert_eq ! ( None , highest) ;
903
+
904
+ let block_range_roots = vec ! [
905
+ (
906
+ BlockRange :: from_block_number( 15 ) ,
907
+ MKTreeNode :: from_hex( "AAAA" ) . unwrap( ) ,
908
+ ) ,
909
+ (
910
+ BlockRange :: from_block_number( 30 ) ,
911
+ MKTreeNode :: from_hex( "BBBB" ) . unwrap( ) ,
912
+ ) ,
913
+ ] ;
914
+ repository
915
+ . create_block_range_roots ( block_range_roots. clone ( ) )
916
+ . await
917
+ . unwrap ( ) ;
918
+
919
+ let highest = repository
920
+ . get_highest_start_block_number_for_block_range_roots ( )
921
+ . await
922
+ . unwrap ( ) ;
923
+ assert_eq ! ( Some ( 30 ) , highest) ;
924
+ }
877
925
}
0 commit comments