@@ -182,19 +182,19 @@ impl SqLiteEntity for CertificateRecord {
182
182
where
183
183
Self : Sized ,
184
184
{
185
- let certificate_id = row. get :: < String , _ > ( 0 ) ;
186
- let parent_certificate_id = row. get :: < Option < String > , _ > ( 1 ) ;
187
- let message = row. get :: < String , _ > ( 2 ) ;
188
- let signature = row. get :: < String , _ > ( 3 ) ;
189
- let aggregate_verification_key = row. get :: < String , _ > ( 4 ) ;
190
- let epoch_int = row. get :: < i64 , _ > ( 5 ) ;
191
- let beacon_string = row. get :: < String , _ > ( 6 ) ;
192
- let protocol_version = row. get :: < String , _ > ( 7 ) ;
193
- let protocol_parameters_string = row. get :: < String , _ > ( 8 ) ;
194
- let protocol_message_string = row. get :: < String , _ > ( 9 ) ;
195
- let signers_string = row. get :: < String , _ > ( 10 ) ;
196
- let initiated_at = row. get :: < String , _ > ( 11 ) ;
197
- let sealed_at = row. get :: < String , _ > ( 12 ) ;
185
+ let certificate_id = row. read :: < & str , _ > ( 0 ) . to_string ( ) ;
186
+ let parent_certificate_id = row. read :: < Option < & str > , _ > ( 1 ) . map ( |s| s . to_owned ( ) ) ;
187
+ let message = row. read :: < & str , _ > ( 2 ) . to_string ( ) ;
188
+ let signature = row. read :: < & str , _ > ( 3 ) . to_string ( ) ;
189
+ let aggregate_verification_key = row. read :: < & str , _ > ( 4 ) . to_string ( ) ;
190
+ let epoch_int = row. read :: < i64 , _ > ( 5 ) ;
191
+ let beacon_string = row. read :: < & str , _ > ( 6 ) ;
192
+ let protocol_version = row. read :: < & str , _ > ( 7 ) . to_string ( ) ;
193
+ let protocol_parameters_string = row. read :: < & str , _ > ( 8 ) ;
194
+ let protocol_message_string = row. read :: < & str , _ > ( 9 ) ;
195
+ let signers_string = row. read :: < & str , _ > ( 10 ) ;
196
+ let initiated_at = row. read :: < & str , _ > ( 11 ) ;
197
+ let sealed_at = row. read :: < & str , _ > ( 12 ) ;
198
198
199
199
let certificate_record = Self {
200
200
certificate_id,
@@ -207,43 +207,43 @@ impl SqLiteEntity for CertificateRecord {
207
207
"Could not cast i64 ({epoch_int}) to u64. Error: '{e}'"
208
208
) )
209
209
} ) ?) ,
210
- beacon : serde_json:: from_str ( & beacon_string) . map_err (
210
+ beacon : serde_json:: from_str ( beacon_string) . map_err (
211
211
|e| {
212
212
HydrationError :: InvalidData ( format ! (
213
213
"Could not turn string '{beacon_string}' to Beacon. Error: {e}"
214
214
) )
215
215
} ,
216
216
) ?,
217
217
protocol_version,
218
- protocol_parameters : serde_json:: from_str ( & protocol_parameters_string) . map_err (
218
+ protocol_parameters : serde_json:: from_str ( protocol_parameters_string) . map_err (
219
219
|e| {
220
220
HydrationError :: InvalidData ( format ! (
221
221
"Could not turn string '{protocol_parameters_string}' to ProtocolParameters. Error: {e}"
222
222
) )
223
223
} ,
224
224
) ?,
225
- protocol_message : serde_json:: from_str ( & protocol_message_string) . map_err (
225
+ protocol_message : serde_json:: from_str ( protocol_message_string) . map_err (
226
226
|e| {
227
227
HydrationError :: InvalidData ( format ! (
228
228
"Could not turn string '{protocol_message_string}' to ProtocolMessage. Error: {e}"
229
229
) )
230
230
} ,
231
231
) ?,
232
- signers : serde_json:: from_str ( & signers_string) . map_err (
232
+ signers : serde_json:: from_str ( signers_string) . map_err (
233
233
|e| {
234
234
HydrationError :: InvalidData ( format ! (
235
235
"Could not turn string '{signers_string}' to Vec<SignerWithStake>. Error: {e}"
236
236
) )
237
237
} ,
238
238
) ?,
239
- initiated_at : DateTime :: parse_from_rfc3339 ( & initiated_at) . map_err (
239
+ initiated_at : DateTime :: parse_from_rfc3339 ( initiated_at) . map_err (
240
240
|e| {
241
241
HydrationError :: InvalidData ( format ! (
242
242
"Could not turn string '{initiated_at}' to rfc3339 Datetime. Error: {e}"
243
243
) )
244
244
} ,
245
245
) ?. with_timezone ( & Utc ) ,
246
- sealed_at : DateTime :: parse_from_rfc3339 ( & sealed_at) . map_err (
246
+ sealed_at : DateTime :: parse_from_rfc3339 ( sealed_at) . map_err (
247
247
|e| {
248
248
HydrationError :: InvalidData ( format ! (
249
249
"Could not turn string '{sealed_at}' to rfc3339 Datetime. Error: {e}"
@@ -777,68 +777,50 @@ mod tests {
777
777
for certificate in certificates {
778
778
let certificate_record: CertificateRecord = certificate. into ( ) ;
779
779
let mut statement = connection. prepare ( & query) ?;
780
-
781
780
statement
782
- . bind ( 1 , certificate_record. certificate_id . as_str ( ) )
783
- . unwrap ( ) ;
784
- if let Some ( parent_certificate_id) = certificate_record. parent_certificate_id {
785
- statement. bind ( 2 , parent_certificate_id. as_str ( ) ) . unwrap ( ) ;
786
- } else {
787
- statement. bind ( 2 , & Value :: Null ) . unwrap ( ) ;
788
- }
789
- statement
790
- . bind ( 3 , certificate_record. message . as_str ( ) )
791
- . unwrap ( ) ;
792
- statement
793
- . bind ( 4 , certificate_record. signature . as_str ( ) )
794
- . unwrap ( ) ;
795
- statement
796
- . bind ( 5 , certificate_record. aggregate_verification_key . as_str ( ) )
797
- . unwrap ( ) ;
798
- statement
799
- . bind ( 6 , certificate_record. epoch . 0 as i64 )
800
- . unwrap ( ) ;
801
- statement
802
- . bind (
803
- 7 ,
804
- serde_json:: to_string ( & certificate_record. beacon )
805
- . unwrap ( )
806
- . as_str ( ) ,
807
- )
808
- . unwrap ( ) ;
809
- statement
810
- . bind ( 8 , certificate_record. protocol_version . as_str ( ) )
811
- . unwrap ( ) ;
812
- statement
813
- . bind (
814
- 9 ,
815
- serde_json:: to_string ( & certificate_record. protocol_parameters )
816
- . unwrap ( )
817
- . as_str ( ) ,
818
- )
819
- . unwrap ( ) ;
820
- statement
821
- . bind (
822
- 10 ,
823
- serde_json:: to_string ( & certificate_record. protocol_message )
824
- . unwrap ( )
825
- . as_str ( ) ,
826
- )
827
- . unwrap ( ) ;
828
- statement
829
- . bind (
830
- 11 ,
831
- serde_json:: to_string ( & certificate_record. signers )
832
- . unwrap ( )
833
- . as_str ( ) ,
834
- )
835
- . unwrap ( ) ;
836
- statement
837
- . bind ( 12 , certificate_record. initiated_at . to_rfc3339 ( ) . as_str ( ) )
838
- . unwrap ( ) ;
839
- statement
840
- . bind ( 13 , certificate_record. sealed_at . to_rfc3339 ( ) . as_str ( ) )
781
+ . bind :: < & [ ( _ , Value ) ] > ( & [
782
+ ( 1 , certificate_record. certificate_id . into ( ) ) ,
783
+ (
784
+ 2 ,
785
+ match certificate_record. parent_certificate_id {
786
+ None => Value :: Null ,
787
+ Some ( parent_certificate_id) => parent_certificate_id. into ( ) ,
788
+ } ,
789
+ ) ,
790
+ ( 3 , certificate_record. message . into ( ) ) ,
791
+ ( 4 , certificate_record. signature . into ( ) ) ,
792
+ ( 5 , certificate_record. aggregate_verification_key . into ( ) ) ,
793
+ ( 6 , i64:: try_from ( certificate_record. epoch . 0 ) . unwrap ( ) . into ( ) ) ,
794
+ (
795
+ 7 ,
796
+ serde_json:: to_string ( & certificate_record. beacon )
797
+ . unwrap ( )
798
+ . into ( ) ,
799
+ ) ,
800
+ ( 8 , certificate_record. protocol_version . into ( ) ) ,
801
+ (
802
+ 9 ,
803
+ serde_json:: to_string ( & certificate_record. protocol_parameters )
804
+ . unwrap ( )
805
+ . into ( ) ,
806
+ ) ,
807
+ (
808
+ 10 ,
809
+ serde_json:: to_string ( & certificate_record. protocol_message )
810
+ . unwrap ( )
811
+ . into ( ) ,
812
+ ) ,
813
+ (
814
+ 11 ,
815
+ serde_json:: to_string ( & certificate_record. signers )
816
+ . unwrap ( )
817
+ . into ( ) ,
818
+ ) ,
819
+ ( 12 , certificate_record. initiated_at . to_rfc3339 ( ) . into ( ) ) ,
820
+ ( 13 , certificate_record. sealed_at . to_rfc3339 ( ) . into ( ) ) ,
821
+ ] )
841
822
. unwrap ( ) ;
823
+
842
824
statement. next ( ) . unwrap ( ) ;
843
825
}
844
826
0 commit comments