@@ -118,12 +118,7 @@ impl ProverService for MithrilProverService {
118118 // 2 - Compute block ranges sub Merkle trees
119119 let mut mk_trees = BTreeMap :: new ( ) ;
120120 for ( block_range, transactions) in block_range_transactions {
121- let mk_tree = MKTree :: new (
122- & transactions
123- . iter ( )
124- . map ( |t| t. transaction_hash . clone ( ) )
125- . collect :: < Vec < _ > > ( ) ,
126- ) ?;
121+ let mk_tree = MKTree :: new ( & transactions) ?;
127122 mk_trees. insert ( block_range, mk_tree) ;
128123 }
129124
@@ -140,15 +135,11 @@ impl ProverService for MithrilProverService {
140135
141136 // 5 - Compute the proof for all transactions
142137 if let Ok ( mk_proof) = mk_map. compute_proof ( transaction_hashes) {
143- let transaction_hashes_certified = transaction_hashes
138+ let transaction_hashes_certified: Vec < TransactionHash > = transaction_hashes
144139 . iter ( )
145- . filter_map ( |hash| {
146- mk_proof
147- . contains ( & hash. to_owned ( ) . into ( ) )
148- . ok ( )
149- . map ( |_| hash. clone ( ) )
150- } )
151- . collect :: < Vec < _ > > ( ) ;
140+ . filter ( |hash| mk_proof. contains ( & hash. as_str ( ) . into ( ) ) . is_ok ( ) )
141+ . cloned ( )
142+ . collect ( ) ;
152143
153144 Ok ( vec ! [ CardanoTransactionsSetProof :: new(
154145 transaction_hashes_certified,
@@ -194,7 +185,7 @@ mod tests {
194185
195186 // Generate transactions for 'total_block_ranges' consecutive block ranges,
196187 // with 'total_transactions_per_block_range' transactions per block range
197- pub ( crate ) fn generate_transactions (
188+ pub fn generate_transactions (
198189 total_block_ranges : usize ,
199190 total_transactions_per_block_range : usize ,
200191 ) -> Vec < CardanoTransaction > {
@@ -229,7 +220,7 @@ mod tests {
229220 transactions
230221 }
231222
232- pub ( crate ) fn filter_transactions_for_indices (
223+ pub fn filter_transactions_for_indices (
233224 indices : & [ usize ] ,
234225 transactions : & [ CardanoTransaction ] ,
235226 ) -> Vec < CardanoTransaction > {
@@ -241,7 +232,7 @@ mod tests {
241232 . collect ( )
242233 }
243234
244- pub ( crate ) fn compute_transaction_hashes_from_transactions (
235+ pub fn compute_transaction_hashes_from_transactions (
245236 transactions : & [ CardanoTransaction ] ,
246237 ) -> Vec < TransactionHash > {
247238 transactions
@@ -250,7 +241,7 @@ mod tests {
250241 . collect ( )
251242 }
252243
253- pub ( crate ) fn compute_block_ranges_map_from_transactions (
244+ pub fn compute_block_ranges_map_from_transactions (
254245 transactions : & [ CardanoTransaction ] ,
255246 ) -> BTreeMap < BlockRange , Vec < CardanoTransaction > > {
256247 let mut block_ranges_map = BTreeMap :: new ( ) ;
@@ -264,7 +255,7 @@ mod tests {
264255 block_ranges_map
265256 }
266257
267- pub ( crate ) fn filter_transactions_for_block_ranges (
258+ pub fn filter_transactions_for_block_ranges (
268259 block_ranges : & [ BlockRange ] ,
269260 transactions : & [ CardanoTransaction ] ,
270261 ) -> Vec < CardanoTransaction > {
@@ -275,13 +266,7 @@ mod tests {
275266 . collect ( )
276267 }
277268
278- pub ( crate ) fn compute_mk_tree_from_transactions (
279- transactions : & [ CardanoTransaction ] ,
280- ) -> MKTree {
281- MKTree :: new ( & compute_transaction_hashes_from_transactions ( transactions) ) . unwrap ( )
282- }
283-
284- pub ( crate ) fn compute_mk_map_from_block_ranges_map (
269+ pub fn compute_mk_map_from_block_ranges_map (
285270 block_ranges_map : BTreeMap < BlockRange , Vec < CardanoTransaction > > ,
286271 ) -> MKMap < BlockRange , MKMapNode < BlockRange > > {
287272 MKMap :: new_from_iter (
@@ -291,7 +276,8 @@ mod tests {
291276 (
292277 block_range,
293278 MKMapNode :: TreeNode (
294- compute_mk_tree_from_transactions ( & transactions)
279+ MKTree :: new ( & transactions)
280+ . unwrap ( )
295281 . compute_root ( )
296282 . unwrap ( )
297283 . clone ( ) ,
@@ -302,7 +288,7 @@ mod tests {
302288 . unwrap ( )
303289 }
304290
305- pub ( crate ) fn compute_beacon_from_transactions (
291+ pub fn compute_beacon_from_transactions (
306292 transactions : & [ CardanoTransaction ] ,
307293 ) -> CardanoDbBeacon {
308294 CardanoDbBeacon {
@@ -311,15 +297,15 @@ mod tests {
311297 }
312298 }
313299
314- pub ( crate ) struct TestData {
315- pub ( crate ) transaction_hashes_to_prove : Vec < TransactionHash > ,
316- pub ( crate ) block_ranges_map : BTreeMap < BlockRange , Vec < CardanoTransaction > > ,
317- pub ( crate ) block_ranges_to_prove : Vec < BlockRange > ,
318- pub ( crate ) all_transactions_in_block_ranges_to_prove : Vec < CardanoTransaction > ,
319- pub ( crate ) beacon : CardanoDbBeacon ,
300+ pub struct TestData {
301+ pub transaction_hashes_to_prove : Vec < TransactionHash > ,
302+ pub block_ranges_map : BTreeMap < BlockRange , Vec < CardanoTransaction > > ,
303+ pub block_ranges_to_prove : Vec < BlockRange > ,
304+ pub all_transactions_in_block_ranges_to_prove : Vec < CardanoTransaction > ,
305+ pub beacon : CardanoDbBeacon ,
320306 }
321307
322- pub ( crate ) fn build_test_data (
308+ pub fn build_test_data (
323309 transactions_to_prove : & [ CardanoTransaction ] ,
324310 transactions : & [ CardanoTransaction ] ,
325311 ) -> TestData {
@@ -480,12 +466,11 @@ mod tests {
480466 vec ! [ "tx-unknown-123" . to_string( ) , "tx-unknown-456" . to_string( ) ] ;
481467 let mut test_data = test_data:: build_test_data ( & transactions_to_prove, & transactions) ;
482468 let transaction_hashes_known = test_data. transaction_hashes_to_prove . clone ( ) ;
483- test_data. transaction_hashes_to_prove = test_data
484- . transaction_hashes_to_prove
485- . clone ( )
486- . into_iter ( )
487- . chain ( transaction_hashes_unknown. into_iter ( ) )
488- . collect :: < Vec < _ > > ( ) ;
469+ test_data. transaction_hashes_to_prove = [
470+ test_data. transaction_hashes_to_prove . clone ( ) ,
471+ transaction_hashes_unknown,
472+ ]
473+ . concat ( ) ;
489474 let prover = build_prover (
490475 |retriever_mock| {
491476 let transaction_hashes_to_prove = test_data. transaction_hashes_to_prove . clone ( ) ;
@@ -541,10 +526,8 @@ mod tests {
541526 let test_data = test_data:: build_test_data ( & transactions_to_prove, & transactions) ;
542527 let prover = build_prover (
543528 |retriever_mock| {
544- let transaction_hashes_to_prove = test_data. transaction_hashes_to_prove . clone ( ) ;
545529 retriever_mock
546530 . expect_get_by_hashes ( )
547- . with ( eq ( transaction_hashes_to_prove) )
548531 . returning ( |_| Err ( anyhow ! ( "Error" ) ) ) ;
549532 } ,
550533 |block_range_root_retriever_mock| {
@@ -573,19 +556,15 @@ mod tests {
573556 let test_data = test_data:: build_test_data ( & transactions_to_prove, & transactions) ;
574557 let prover = build_prover (
575558 |retriever_mock| {
576- let transaction_hashes_to_prove = test_data. transaction_hashes_to_prove . clone ( ) ;
577559 let transactions_to_prove = transactions_to_prove. clone ( ) ;
578560 retriever_mock
579561 . expect_get_by_hashes ( )
580- . with ( eq ( transaction_hashes_to_prove) )
581562 . return_once ( move |_| Ok ( transactions_to_prove) ) ;
582563
583- let block_ranges_to_prove = test_data. block_ranges_to_prove . clone ( ) ;
584564 let all_transactions_in_block_ranges_to_prove =
585565 test_data. all_transactions_in_block_ranges_to_prove . clone ( ) ;
586566 retriever_mock
587567 . expect_get_by_block_ranges ( )
588- . with ( eq ( block_ranges_to_prove) )
589568 . return_once ( move |_| Ok ( all_transactions_in_block_ranges_to_prove) ) ;
590569 } ,
591570 |block_range_root_retriever_mock| {
0 commit comments