@@ -51,6 +51,21 @@ impl MithrilProverService {
51
51
}
52
52
}
53
53
54
+ async fn get_transactions_by_hashes_with_block_range (
55
+ & self ,
56
+ hashes : Vec < TransactionHash > ,
57
+ ) -> StdResult < Vec < ( BlockRange , CardanoTransaction ) > > {
58
+ let transactions = self . transaction_retriever . get_by_hashes ( hashes) . await ?;
59
+ let transactions_with_block_range = transactions
60
+ . into_iter ( )
61
+ . map ( |transaction| {
62
+ let block_range = BlockRange :: from_block_number ( transaction. block_number ) ;
63
+ ( block_range, transaction)
64
+ } )
65
+ . collect :: < Vec < _ > > ( ) ;
66
+ Ok ( transactions_with_block_range)
67
+ }
68
+
54
69
fn compute_merkle_map_from_transactions (
55
70
& self ,
56
71
transactions : Vec < CardanoTransaction > ,
@@ -89,20 +104,13 @@ impl ProverService for MithrilProverService {
89
104
up_to : & CardanoDbBeacon ,
90
105
transaction_hashes : & [ TransactionHash ] ,
91
106
) -> StdResult < Vec < CardanoTransactionsSetProof > > {
92
- let transactions = self . transaction_retriever . get_up_to ( up_to) . await ?;
93
-
94
107
// 1 - Get transactions to prove per block range
95
- let transactions_to_prove = transactions
96
- . iter ( )
97
- . filter_map ( |transaction| {
98
- let block_range = BlockRange :: from_block_number ( transaction. block_number ) ;
99
- transaction_hashes
100
- . contains ( & transaction. transaction_hash )
101
- . then_some ( ( block_range, transaction. clone ( ) ) )
102
- } )
103
- . collect :: < Vec < _ > > ( ) ;
108
+ let transactions_to_prove = self
109
+ . get_transactions_by_hashes_with_block_range ( transaction_hashes. to_vec ( ) )
110
+ . await ?;
104
111
105
112
// 2 - Compute Transactions Merkle Tree
113
+ let transactions = self . transaction_retriever . get_up_to ( up_to) . await ?;
106
114
let mk_map = self . compute_merkle_map_from_transactions ( transactions) ?;
107
115
108
116
// 3 - Compute proof for each transaction to prove
@@ -178,6 +186,11 @@ mod tests {
178
186
async fn compute_proof_for_one_set_with_multiple_transactions ( ) {
179
187
let ( transaction_hashes, transactions) = generate_transactions ( 3 ) ;
180
188
let prover = build_prover ( |retriever_mock| {
189
+ let transactions_by_hashes_res = transactions. clone ( ) ;
190
+ retriever_mock
191
+ . expect_get_by_hashes ( )
192
+ . with ( eq ( transaction_hashes. clone ( ) ) )
193
+ . return_once ( move |_| Ok ( transactions_by_hashes_res) ) ;
181
194
retriever_mock
182
195
. expect_get_up_to ( )
183
196
. with ( eq ( fake_data:: beacon ( ) ) )
@@ -199,8 +212,12 @@ mod tests {
199
212
200
213
#[ tokio:: test]
201
214
async fn cant_compute_proof_for_unknown_transaction ( ) {
202
- let ( transaction_hashes, _transactions ) = generate_transactions ( 3 ) ;
215
+ let ( transaction_hashes, transactions ) = generate_transactions ( 3 ) ;
203
216
let prover = build_prover ( |retriever_mock| {
217
+ retriever_mock
218
+ . expect_get_by_hashes ( )
219
+ . with ( eq ( transaction_hashes. clone ( ) ) )
220
+ . return_once ( move |_| Ok ( transactions) ) ;
204
221
retriever_mock
205
222
. expect_get_up_to ( )
206
223
. with ( eq ( fake_data:: beacon ( ) ) )
@@ -221,6 +238,11 @@ mod tests {
221
238
let prover = build_prover ( |retriever_mock| {
222
239
// The last two are not in the "store"
223
240
let transactions = transactions[ 0 ..=2 ] . to_vec ( ) ;
241
+ let transactions_by_hashes_res = transactions. clone ( ) ;
242
+ retriever_mock
243
+ . expect_get_by_hashes ( )
244
+ . with ( eq ( transaction_hashes. clone ( ) ) )
245
+ . return_once ( move |_| Ok ( transactions_by_hashes_res) ) ;
224
246
retriever_mock
225
247
. expect_get_up_to ( )
226
248
. with ( eq ( fake_data:: beacon ( ) ) )
@@ -245,8 +267,8 @@ mod tests {
245
267
let ( transaction_hashes, _transactions) = generate_transactions ( 3 ) ;
246
268
let prover = build_prover ( |retriever_mock| {
247
269
retriever_mock
248
- . expect_get_up_to ( )
249
- . with ( eq ( fake_data :: beacon ( ) ) )
270
+ . expect_get_by_hashes ( )
271
+ . with ( eq ( transaction_hashes . clone ( ) ) )
250
272
. returning ( |_| Err ( anyhow ! ( "Error" ) ) ) ;
251
273
} ) ;
252
274
0 commit comments