@@ -31,6 +31,7 @@ use chronicle::{
31
31
MongoDb ,
32
32
} ,
33
33
types:: {
34
+ context:: { TryFromWithContext , TryIntoWithContext } ,
34
35
stardust:: block:: {
35
36
output:: OutputId ,
36
37
payload:: { milestone:: MilestoneId , transaction:: TransactionId } ,
@@ -134,17 +135,19 @@ pub async fn info(database: Extension<MongoDb>) -> ApiResult<InfoResponse> {
134
135
135
136
let latest_milestone = LatestMilestoneResponse {
136
137
index : newest_milestone. milestone_index . 0 ,
137
- timestamp : newest_milestone. milestone_timestamp . 0 ,
138
- milestone_id : bee_block_stardust:: payload:: milestone:: MilestoneId :: from (
139
- database
140
- . collection :: < MilestoneCollection > ( )
141
- . get_milestone_id ( newest_milestone. milestone_index )
142
- . await ?
143
- . ok_or ( ApiError :: Internal ( InternalApiError :: CorruptState (
144
- "no milestone in the database" ,
145
- ) ) ) ?,
146
- )
147
- . to_string ( ) ,
138
+ timestamp : Some ( newest_milestone. milestone_timestamp . 0 ) ,
139
+ milestone_id : Some (
140
+ bee_block_stardust:: payload:: milestone:: MilestoneId :: from (
141
+ database
142
+ . collection :: < MilestoneCollection > ( )
143
+ . get_milestone_id ( newest_milestone. milestone_index )
144
+ . await ?
145
+ . ok_or ( ApiError :: Internal ( InternalApiError :: CorruptState (
146
+ "no milestone in the database" ,
147
+ ) ) ) ?,
148
+ )
149
+ . to_string ( ) ,
150
+ ) ,
148
151
} ;
149
152
150
153
// Unfortunately, there is a distinction between `LatestMilestoneResponse` and `ConfirmedMilestoneResponse` in Bee.
@@ -160,6 +163,7 @@ pub async fn info(database: Extension<MongoDb>) -> ApiResult<InfoResponse> {
160
163
protocol : ProtocolResponse {
161
164
version : protocol. version ,
162
165
network_name : protocol. network_name ,
166
+ below_max_depth : protocol. below_max_depth ,
163
167
bech32_hrp : protocol. bech32_hrp ,
164
168
min_pow_score : protocol. min_pow_score ,
165
169
rent_structure : RentStructureResponse {
@@ -202,7 +206,19 @@ async fn block(
202
206
. get_block ( & block_id)
203
207
. await ?
204
208
. ok_or ( ApiError :: NoResults ) ?;
205
- Ok ( BlockResponse :: Json ( BlockDto :: try_from ( block) ?) )
209
+
210
+ let protocol_params = database
211
+ . collection :: < ProtocolUpdateCollection > ( )
212
+ . get_protocol_parameters_for_version ( block. protocol_version )
213
+ . await ?
214
+ . ok_or ( ApiError :: NoResults ) ?
215
+ . parameters
216
+ . try_into ( ) ?;
217
+
218
+ Ok ( BlockResponse :: Json ( BlockDto :: try_from_with_context (
219
+ & protocol_params,
220
+ block,
221
+ ) ?) )
206
222
}
207
223
208
224
async fn block_metadata (
@@ -272,9 +288,17 @@ async fn output(database: Extension<MongoDb>, Path(output_id): Path<String>) ->
272
288
273
289
let metadata = create_output_metadata_response ( metadata, ledger_index) ;
274
290
291
+ let protocol_params = database
292
+ . collection :: < ProtocolUpdateCollection > ( )
293
+ . get_protocol_parameters_for_ledger_index ( ledger_index)
294
+ . await ?
295
+ . ok_or ( ApiError :: NoResults ) ?
296
+ . parameters
297
+ . try_into ( ) ?;
298
+
275
299
Ok ( OutputResponse {
276
300
metadata,
277
- output : OutputDto :: try_from ( output) ?,
301
+ output : OutputDto :: try_from_with_context ( & protocol_params , output) ?,
278
302
} )
279
303
}
280
304
@@ -308,14 +332,33 @@ async fn transaction_included_block(
308
332
. await ?
309
333
. ok_or ( ApiError :: NoResults ) ?;
310
334
311
- Ok ( BlockResponse :: Json ( BlockDto :: try_from ( block) ?) )
335
+ let protocol_params = database
336
+ . collection :: < ProtocolUpdateCollection > ( )
337
+ . get_protocol_parameters_for_version ( block. protocol_version )
338
+ . await ?
339
+ . ok_or ( ApiError :: NoResults ) ?
340
+ . parameters
341
+ . try_into ( ) ?;
342
+
343
+ Ok ( BlockResponse :: Json ( BlockDto :: try_from_with_context (
344
+ & protocol_params,
345
+ block,
346
+ ) ?) )
312
347
}
313
348
314
349
async fn receipts ( database : Extension < MongoDb > ) -> ApiResult < ReceiptsResponse > {
315
350
let mut receipts_at = database. collection :: < MilestoneCollection > ( ) . get_all_receipts ( ) . await ?;
316
351
let mut receipts = Vec :: new ( ) ;
317
352
while let Some ( ( receipt, at) ) = receipts_at. try_next ( ) . await ? {
318
- let receipt: & bee_block_stardust:: payload:: milestone:: MilestoneOption = & receipt. try_into ( ) ?;
353
+ let protocol_params = database
354
+ . collection :: < ProtocolUpdateCollection > ( )
355
+ . get_protocol_parameters_for_ledger_index ( at)
356
+ . await ?
357
+ . ok_or ( ApiError :: NoResults ) ?
358
+ . parameters
359
+ . try_into ( ) ?;
360
+ let receipt: & bee_block_stardust:: payload:: milestone:: MilestoneOption =
361
+ & receipt. try_into_with_context ( & protocol_params) ?;
319
362
let receipt: bee_block_stardust:: payload:: milestone:: option:: dto:: MilestoneOptionDto = receipt. into ( ) ;
320
363
321
364
if let MilestoneOptionDto :: Receipt ( receipt) = receipt {
@@ -335,9 +378,17 @@ async fn receipts_migrated_at(database: Extension<MongoDb>, Path(index): Path<u3
335
378
. collection :: < MilestoneCollection > ( )
336
379
. get_receipts_migrated_at ( index. into ( ) )
337
380
. await ?;
381
+ let protocol_params = database
382
+ . collection :: < ProtocolUpdateCollection > ( )
383
+ . get_protocol_parameters_for_ledger_index ( index. into ( ) )
384
+ . await ?
385
+ . ok_or ( ApiError :: NoResults ) ?
386
+ . parameters
387
+ . try_into ( ) ?;
338
388
let mut receipts = Vec :: new ( ) ;
339
389
while let Some ( ( receipt, at) ) = receipts_at. try_next ( ) . await ? {
340
- let receipt: & bee_block_stardust:: payload:: milestone:: MilestoneOption = & receipt. try_into ( ) ?;
390
+ let receipt: & bee_block_stardust:: payload:: milestone:: MilestoneOption =
391
+ & receipt. try_into_with_context ( & protocol_params) ?;
341
392
let receipt: bee_block_stardust:: payload:: milestone:: option:: dto:: MilestoneOptionDto = receipt. into ( ) ;
342
393
343
394
if let MilestoneOptionDto :: Receipt ( receipt) = receipt {
@@ -376,14 +427,26 @@ async fn milestone(
376
427
. await ?
377
428
. ok_or ( ApiError :: NoResults ) ?;
378
429
430
+ let protocol_params = database
431
+ . collection :: < ProtocolUpdateCollection > ( )
432
+ . get_protocol_parameters_for_ledger_index ( milestone_payload. essence . index )
433
+ . await ?
434
+ . ok_or ( ApiError :: NoResults ) ?
435
+ . parameters
436
+ . try_into ( ) ?;
437
+
379
438
if let Some ( value) = headers. get ( axum:: http:: header:: ACCEPT ) {
380
439
if value. eq ( & * BYTE_CONTENT_HEADER ) {
381
- let milestone_payload = bee_block_stardust:: payload:: MilestonePayload :: try_from ( milestone_payload) ?;
440
+ let milestone_payload = bee_block_stardust:: payload:: MilestonePayload :: try_from_with_context (
441
+ & protocol_params,
442
+ milestone_payload,
443
+ ) ?;
382
444
return Ok ( MilestoneResponse :: Raw ( milestone_payload. pack_to_vec ( ) ) ) ;
383
445
}
384
446
}
385
447
386
- Ok ( MilestoneResponse :: Json ( MilestonePayloadDto :: try_from (
448
+ Ok ( MilestoneResponse :: Json ( MilestonePayloadDto :: try_from_with_context (
449
+ & protocol_params,
387
450
milestone_payload,
388
451
) ?) )
389
452
}
@@ -399,14 +462,26 @@ async fn milestone_by_index(
399
462
. await ?
400
463
. ok_or ( ApiError :: NoResults ) ?;
401
464
465
+ let protocol_params = database
466
+ . collection :: < ProtocolUpdateCollection > ( )
467
+ . get_protocol_parameters_for_ledger_index ( milestone_payload. essence . index )
468
+ . await ?
469
+ . ok_or ( ApiError :: NoResults ) ?
470
+ . parameters
471
+ . try_into ( ) ?;
472
+
402
473
if let Some ( value) = headers. get ( axum:: http:: header:: ACCEPT ) {
403
474
if value. eq ( & * BYTE_CONTENT_HEADER ) {
404
- let milestone_payload = bee_block_stardust:: payload:: MilestonePayload :: try_from ( milestone_payload) ?;
475
+ let milestone_payload = bee_block_stardust:: payload:: MilestonePayload :: try_from_with_context (
476
+ & protocol_params,
477
+ milestone_payload,
478
+ ) ?;
405
479
return Ok ( MilestoneResponse :: Raw ( milestone_payload. pack_to_vec ( ) ) ) ;
406
480
}
407
481
}
408
482
409
- Ok ( MilestoneResponse :: Json ( MilestonePayloadDto :: try_from (
483
+ Ok ( MilestoneResponse :: Json ( MilestonePayloadDto :: try_from_with_context (
484
+ & protocol_params,
410
485
milestone_payload,
411
486
) ?) )
412
487
}
0 commit comments