@@ -25,7 +25,10 @@ use bee_block_stardust::{
25
25
} ;
26
26
use chronicle:: {
27
27
db:: {
28
- collections:: { OutputMetadataResult , OutputWithMetadataResult , UtxoChangesResult } ,
28
+ collections:: {
29
+ BlockCollection , MilestoneCollection , OutputCollection , OutputMetadataResult , OutputWithMetadataResult ,
30
+ ProtocolUpdateCollection , TreasuryCollection , UtxoChangesResult ,
31
+ } ,
29
32
MongoDb ,
30
33
} ,
31
34
types:: {
@@ -101,6 +104,7 @@ pub fn routes() -> Router {
101
104
102
105
pub async fn info ( database : Extension < MongoDb > ) -> ApiResult < InfoResponse > {
103
106
let protocol = database
107
+ . collection :: < ProtocolUpdateCollection > ( )
104
108
. get_latest_protocol_parameters ( )
105
109
. await ?
106
110
. ok_or ( ApiError :: Internal ( InternalApiError :: CorruptState (
@@ -113,26 +117,27 @@ pub async fn info(database: Extension<MongoDb>) -> ApiResult<InfoResponse> {
113
117
false
114
118
} ) ;
115
119
116
- let newest_milestone =
117
- database
118
- . get_newest_milestone ( )
119
- . await ?
120
- . ok_or ( ApiError :: Internal ( InternalApiError :: CorruptState (
121
- "no milestone in the database" ,
122
- ) ) ) ?;
123
- let oldest_milestone =
124
- database
125
- . get_oldest_milestone ( )
126
- . await ?
127
- . ok_or ( ApiError :: Internal ( InternalApiError :: CorruptState (
128
- "no milestone in the database" ,
129
- ) ) ) ?;
120
+ let newest_milestone = database
121
+ . collection :: < MilestoneCollection > ( )
122
+ . get_newest_milestone ( )
123
+ . await ?
124
+ . ok_or ( ApiError :: Internal ( InternalApiError :: CorruptState (
125
+ "no milestone in the database" ,
126
+ ) ) ) ?;
127
+ let oldest_milestone = database
128
+ . collection :: < MilestoneCollection > ( )
129
+ . get_oldest_milestone ( )
130
+ . await ?
131
+ . ok_or ( ApiError :: Internal ( InternalApiError :: CorruptState (
132
+ "no milestone in the database" ,
133
+ ) ) ) ?;
130
134
131
135
let latest_milestone = LatestMilestoneResponse {
132
136
index : newest_milestone. milestone_index . 0 ,
133
137
timestamp : newest_milestone. milestone_timestamp . 0 ,
134
138
milestone_id : bee_block_stardust:: payload:: milestone:: MilestoneId :: from (
135
139
database
140
+ . collection :: < MilestoneCollection > ( )
136
141
. get_milestone_id ( newest_milestone. milestone_index )
137
142
. await ?
138
143
. ok_or ( ApiError :: Internal ( InternalApiError :: CorruptState (
@@ -183,12 +188,20 @@ async fn block(
183
188
if let Some ( value) = headers. get ( axum:: http:: header:: ACCEPT ) {
184
189
if value. eq ( & * BYTE_CONTENT_HEADER ) {
185
190
return Ok ( BlockResponse :: Raw (
186
- database. get_block_raw ( & block_id) . await ?. ok_or ( ApiError :: NoResults ) ?,
191
+ database
192
+ . collection :: < BlockCollection > ( )
193
+ . get_block_raw ( & block_id)
194
+ . await ?
195
+ . ok_or ( ApiError :: NoResults ) ?,
187
196
) ) ;
188
197
}
189
198
}
190
199
191
- let block = database. get_block ( & block_id) . await ?. ok_or ( ApiError :: NoResults ) ?;
200
+ let block = database
201
+ . collection :: < BlockCollection > ( )
202
+ . get_block ( & block_id)
203
+ . await ?
204
+ . ok_or ( ApiError :: NoResults ) ?;
192
205
Ok ( BlockResponse :: Json ( BlockDto :: try_from ( block) ?) )
193
206
}
194
207
@@ -198,6 +211,7 @@ async fn block_metadata(
198
211
) -> ApiResult < BlockMetadataResponse > {
199
212
let block_id = BlockId :: from_str ( & block_id_str) . map_err ( ApiError :: bad_parse) ?;
200
213
let metadata = database
214
+ . collection :: < BlockCollection > ( )
201
215
. get_block_metadata ( & block_id)
202
216
. await ?
203
217
. ok_or ( ApiError :: NoResults ) ?;
@@ -243,6 +257,7 @@ fn create_output_metadata_response(metadata: OutputMetadataResult) -> OutputMeta
243
257
async fn output ( database : Extension < MongoDb > , Path ( output_id) : Path < String > ) -> ApiResult < OutputResponse > {
244
258
let output_id = OutputId :: from_str ( & output_id) . map_err ( ApiError :: bad_parse) ?;
245
259
let OutputWithMetadataResult { output, metadata } = database
260
+ . collection :: < OutputCollection > ( )
246
261
. get_output_with_metadata ( & output_id)
247
262
. await ?
248
263
. ok_or ( ApiError :: NoResults ) ?;
@@ -261,6 +276,7 @@ async fn output_metadata(
261
276
) -> ApiResult < OutputMetadataResponse > {
262
277
let output_id = OutputId :: from_str ( & output_id) . map_err ( ApiError :: bad_parse) ?;
263
278
let metadata = database
279
+ . collection :: < OutputCollection > ( )
264
280
. get_output_metadata ( & output_id)
265
281
. await ?
266
282
. ok_or ( ApiError :: NoResults ) ?;
@@ -274,6 +290,7 @@ async fn transaction_included_block(
274
290
) -> ApiResult < BlockResponse > {
275
291
let transaction_id = TransactionId :: from_str ( & transaction_id) . map_err ( ApiError :: bad_parse) ?;
276
292
let block = database
293
+ . collection :: < BlockCollection > ( )
277
294
. get_block_for_transaction ( & transaction_id)
278
295
. await ?
279
296
. ok_or ( ApiError :: NoResults ) ?;
@@ -282,7 +299,10 @@ async fn transaction_included_block(
282
299
}
283
300
284
301
async fn receipts ( database : Extension < MongoDb > ) -> ApiResult < ReceiptsResponse > {
285
- let mut receipts_at = database. stream_all_receipts ( ) . await ?;
302
+ let mut receipts_at = database
303
+ . collection :: < MilestoneCollection > ( )
304
+ . stream_all_receipts ( )
305
+ . await ?;
286
306
let mut receipts = Vec :: new ( ) ;
287
307
while let Some ( ( receipt, at) ) = receipts_at. try_next ( ) . await ? {
288
308
let receipt: & bee_block_stardust:: payload:: milestone:: MilestoneOption = & receipt. try_into ( ) ?;
@@ -301,7 +321,10 @@ async fn receipts(database: Extension<MongoDb>) -> ApiResult<ReceiptsResponse> {
301
321
}
302
322
303
323
async fn receipts_migrated_at ( database : Extension < MongoDb > , Path ( index) : Path < u32 > ) -> ApiResult < ReceiptsResponse > {
304
- let mut receipts_at = database. stream_receipts_migrated_at ( index. into ( ) ) . await ?;
324
+ let mut receipts_at = database
325
+ . collection :: < MilestoneCollection > ( )
326
+ . stream_receipts_migrated_at ( index. into ( ) )
327
+ . await ?;
305
328
let mut receipts = Vec :: new ( ) ;
306
329
while let Some ( ( receipt, at) ) = receipts_at. try_next ( ) . await ? {
307
330
let receipt: & bee_block_stardust:: payload:: milestone:: MilestoneOption = & receipt. try_into ( ) ?;
@@ -321,6 +344,7 @@ async fn receipts_migrated_at(database: Extension<MongoDb>, Path(index): Path<u3
321
344
322
345
async fn treasury ( database : Extension < MongoDb > ) -> ApiResult < TreasuryResponse > {
323
346
database
347
+ . collection :: < TreasuryCollection > ( )
324
348
. get_latest_treasury ( )
325
349
. await ?
326
350
. ok_or ( ApiError :: NoResults )
@@ -337,6 +361,7 @@ async fn milestone(
337
361
) -> ApiResult < MilestoneResponse > {
338
362
let milestone_id = MilestoneId :: from_str ( & milestone_id) . map_err ( ApiError :: bad_parse) ?;
339
363
let milestone_payload = database
364
+ . collection :: < MilestoneCollection > ( )
340
365
. get_milestone_payload_by_id ( & milestone_id)
341
366
. await ?
342
367
. ok_or ( ApiError :: NoResults ) ?;
@@ -359,6 +384,7 @@ async fn milestone_by_index(
359
384
headers : HeaderMap ,
360
385
) -> ApiResult < MilestoneResponse > {
361
386
let milestone_payload = database
387
+ . collection :: < MilestoneCollection > ( )
362
388
. get_milestone_payload ( index)
363
389
. await ?
364
390
. ok_or ( ApiError :: NoResults ) ?;
@@ -381,6 +407,7 @@ async fn utxo_changes(
381
407
) -> ApiResult < UtxoChangesResponse > {
382
408
let milestone_id = MilestoneId :: from_str ( & milestone_id) . map_err ( ApiError :: bad_parse) ?;
383
409
let milestone_index = database
410
+ . collection :: < MilestoneCollection > ( )
384
411
. get_milestone_payload_by_id ( & milestone_id)
385
412
. await ?
386
413
. ok_or ( ApiError :: NoResults ) ?
@@ -401,6 +428,7 @@ async fn collect_utxo_changes(database: &MongoDb, milestone_index: MilestoneInde
401
428
created_outputs,
402
429
consumed_outputs,
403
430
} = database
431
+ . collection :: < OutputCollection > ( )
404
432
. get_utxo_changes ( milestone_index)
405
433
. await ?
406
434
. ok_or ( ApiError :: NoResults ) ?;
0 commit comments