@@ -5,6 +5,7 @@ use sqlite::{Connection, Value};
5
5
use async_trait:: async_trait;
6
6
7
7
use mithril_common:: {
8
+ certificate_chain:: { CertificateRetriever , CertificateRetrieverError } ,
8
9
entities:: {
9
10
Beacon , Certificate , CertificateMetadata , Epoch , HexEncodedAgregateVerificationKey ,
10
11
HexEncodedKey , ProtocolMessage , ProtocolParameters , ProtocolVersion , SignerWithStake ,
@@ -405,9 +406,10 @@ impl<'conn> MasterCertificateProvider<'conn> {
405
406
WhereCondition :: new ( "parent_certificate.epoch != certificate.epoch" , Vec :: new ( ) ) ,
406
407
) ;
407
408
409
+ let epoch_i64: i64 = epoch. 0 . try_into ( ) . unwrap ( ) ;
408
410
WhereCondition :: new (
409
- "certificate.epoch = ?*" ,
410
- vec ! [ Value :: Integer ( epoch . 0 . try_into ( ) . unwrap ( ) ) ] ,
411
+ "certificate.epoch between ?* and ?*" ,
412
+ vec ! [ Value :: Integer ( epoch_i64 - 1 ) , Value :: Integer ( epoch_i64 ) ] ,
411
413
)
412
414
. and_where ( condition)
413
415
}
@@ -488,6 +490,21 @@ impl CertificateRepository {
488
490
}
489
491
}
490
492
493
+ #[ async_trait]
494
+ impl CertificateRetriever for CertificateRepository {
495
+ async fn get_certificate_details (
496
+ & self ,
497
+ certificate_hash : & str ,
498
+ ) -> Result < Certificate , CertificateRetrieverError > {
499
+ self . get_certificate ( certificate_hash)
500
+ . await
501
+ . map_err ( |e| CertificateRetrieverError :: General ( e. to_string ( ) ) ) ?
502
+ . ok_or ( CertificateRetrieverError :: General (
503
+ "certificate does not exist" . to_string ( ) ,
504
+ ) )
505
+ }
506
+ }
507
+
491
508
/// Service to deal with certificate (read & write).
492
509
pub struct CertificateStoreAdapter {
493
510
connection : Arc < Mutex < Connection > > ,
@@ -855,8 +872,8 @@ mod tests {
855
872
let condition = provider. get_master_certificate_condition ( Epoch ( 10 ) ) ;
856
873
let ( condition_str, parameters) = condition. expand ( ) ;
857
874
858
- assert_eq ! ( "certificate.epoch = ?1 and (certificate.parent_certificate_id is null or parent_certificate.epoch != certificate.epoch)" . to_string( ) , condition_str) ;
859
- assert_eq ! ( Value :: Integer ( 10 ) , parameters[ 0 ] ) ;
875
+ assert_eq ! ( "certificate.epoch between ?1 and ?2 and (certificate.parent_certificate_id is null or parent_certificate.epoch != certificate.epoch)" . to_string( ) , condition_str) ;
876
+ assert_eq ! ( vec! [ Value :: Integer ( 9 ) , Value :: Integer ( 10 ) ] , parameters) ;
860
877
}
861
878
862
879
#[ tokio:: test]
@@ -889,7 +906,7 @@ mod tests {
889
906
890
907
#[ tokio:: test]
891
908
async fn get_master_certificate_for_epoch ( ) {
892
- let ( certificates, _) = setup_certificate_chain ( 5 , 3 ) ;
909
+ let ( certificates, _) = setup_certificate_chain ( 14 , 3 ) ;
893
910
let expected_certificate_id = & certificates[ 2 ] . hash ;
894
911
let epoch = & certificates[ 2 ] . beacon . epoch ;
895
912
let mut deps = DependenciesBuilder :: new ( Configuration :: new_sample ( ) ) ;
0 commit comments