@@ -4,6 +4,7 @@ use acropolis_common::{
4
4
messages:: { Message , RESTResponse , StateQuery , StateQueryResponse } ,
5
5
queries:: {
6
6
blocks:: { BlockKey , BlocksStateQuery , BlocksStateQueryResponse } ,
7
+ misc:: Order ,
7
8
utils:: query_state,
8
9
} ,
9
10
BlockHash ,
@@ -147,28 +148,58 @@ async fn handle_blocks_hash_number_blockfrost(
147
148
pub async fn handle_blocks_latest_hash_number_transactions_blockfrost (
148
149
context : Arc < Context < Message > > ,
149
150
params : Vec < String > ,
151
+ query_params : HashMap < String , String > ,
150
152
handlers_config : Arc < HandlersConfig > ,
151
153
) -> Result < RESTResponse > {
152
154
let param = match params. as_slice ( ) {
153
155
[ param] => param,
154
156
_ => return Ok ( RESTResponse :: with_text ( 400 , "Invalid parameters" ) ) ,
155
157
} ;
156
158
159
+ extract_strict_query_params ! ( query_params, {
160
+ "count" => limit: Option <u64 >,
161
+ "page" => page: Option <u64 >,
162
+ "order" => order: Option <Order >,
163
+ } ) ;
164
+ let limit = limit. unwrap_or ( 100 ) ;
165
+ let skip = ( page. unwrap_or ( 1 ) - 1 ) * limit;
166
+ let order = order. unwrap_or ( Order :: Asc ) ;
167
+
157
168
match param. as_str ( ) {
158
- "latest" => handle_blocks_latest_transactions_blockfrost ( context, handlers_config) . await ,
169
+ "latest" => {
170
+ handle_blocks_latest_transactions_blockfrost (
171
+ context,
172
+ limit,
173
+ skip,
174
+ order,
175
+ handlers_config,
176
+ )
177
+ . await
178
+ }
159
179
_ => {
160
- handle_blocks_hash_number_transactions_blockfrost ( context, param, handlers_config) . await
180
+ handle_blocks_hash_number_transactions_blockfrost (
181
+ context,
182
+ param,
183
+ limit,
184
+ skip,
185
+ order,
186
+ handlers_config,
187
+ )
188
+ . await
161
189
}
162
190
}
163
191
}
164
192
165
193
/// Handle `/blocks/latest/txs`
166
194
async fn handle_blocks_latest_transactions_blockfrost (
167
195
context : Arc < Context < Message > > ,
196
+ limit : u64 ,
197
+ skip : u64 ,
198
+ order : Order ,
168
199
handlers_config : Arc < HandlersConfig > ,
169
200
) -> Result < RESTResponse > {
170
201
let blocks_latest_txs_msg = Arc :: new ( Message :: StateQuery ( StateQuery :: Blocks (
171
- BlocksStateQuery :: GetLatestBlockTransactions ,
202
+ BlocksStateQuery :: GetLatestBlockTransactions { limit , skip , order } ,
172
203
) ) ) ;
173
204
let block_txs = query_state (
174
205
& context,
@@ -207,6 +238,9 @@ async fn handle_blocks_latest_transactions_blockfrost(
207
238
async fn handle_blocks_hash_number_transactions_blockfrost (
208
239
context : Arc < Context < Message > > ,
209
240
hash_or_number : & str ,
241
+ limit : u64 ,
242
+ skip : u64 ,
243
+ order : Order ,
210
244
handlers_config : Arc < HandlersConfig > ,
211
245
) -> Result < RESTResponse > {
212
246
let block_key = match parse_block_key ( hash_or_number) {
@@ -215,7 +249,12 @@ async fn handle_blocks_hash_number_transactions_blockfrost(
215
249
} ;
216
250
217
251
let block_txs_msg = Arc :: new ( Message :: StateQuery ( StateQuery :: Blocks (
218
- BlocksStateQuery :: GetBlockTransactions { block_key } ,
252
+ BlocksStateQuery :: GetBlockTransactions {
253
+ block_key,
254
+ limit,
255
+ skip,
256
+ order,
257
+ } ,
219
258
) ) ) ;
220
259
let block_txs = query_state (
221
260
& context,
@@ -260,31 +299,58 @@ async fn handle_blocks_hash_number_transactions_blockfrost(
260
299
pub async fn handle_blocks_latest_hash_number_transactions_cbor_blockfrost (
261
300
context : Arc < Context < Message > > ,
262
301
params : Vec < String > ,
302
+ query_params : HashMap < String , String > ,
263
303
handlers_config : Arc < HandlersConfig > ,
264
304
) -> Result < RESTResponse > {
265
305
let param = match params. as_slice ( ) {
266
306
[ param] => param,
267
307
_ => return Ok ( RESTResponse :: with_text ( 400 , "Invalid parameters" ) ) ,
268
308
} ;
269
309
310
+ extract_strict_query_params ! ( query_params, {
311
+ "count" => limit: Option <u64 >,
312
+ "page" => page: Option <u64 >,
313
+ "order" => order: Option <Order >,
314
+ } ) ;
315
+ let limit = limit. unwrap_or ( 100 ) ;
316
+ let skip = ( page. unwrap_or ( 1 ) - 1 ) * limit;
317
+ let order = order. unwrap_or ( Order :: Asc ) ;
318
+
270
319
match param. as_str ( ) {
271
320
"latest" => {
272
- handle_blocks_latest_transactions_cbor_blockfrost ( context, handlers_config) . await
321
+ handle_blocks_latest_transactions_cbor_blockfrost (
322
+ context,
323
+ limit,
324
+ skip,
325
+ order,
326
+ handlers_config,
327
+ )
328
+ . await
273
329
}
274
330
_ => {
275
- handle_blocks_hash_number_transactions_cbor_blockfrost ( context, param, handlers_config)
276
- . await
331
+ handle_blocks_hash_number_transactions_cbor_blockfrost (
332
+ context,
333
+ param,
334
+ limit,
335
+ skip,
336
+ order,
337
+ handlers_config,
338
+ )
339
+ . await
277
340
}
278
341
}
279
342
}
280
343
281
344
/// Handle `/blocks/latest/txs/cbor`
282
345
async fn handle_blocks_latest_transactions_cbor_blockfrost (
283
346
context : Arc < Context < Message > > ,
347
+ limit : u64 ,
348
+ skip : u64 ,
349
+ order : Order ,
284
350
handlers_config : Arc < HandlersConfig > ,
285
351
) -> Result < RESTResponse > {
286
352
let blocks_latest_txs_msg = Arc :: new ( Message :: StateQuery ( StateQuery :: Blocks (
287
- BlocksStateQuery :: GetLatestBlockTransactionsCBOR ,
353
+ BlocksStateQuery :: GetLatestBlockTransactionsCBOR { limit , skip , order } ,
288
354
) ) ) ;
289
355
let block_txs_cbor = query_state (
290
356
& context,
@@ -323,6 +389,9 @@ async fn handle_blocks_latest_transactions_cbor_blockfrost(
323
389
async fn handle_blocks_hash_number_transactions_cbor_blockfrost (
324
390
context : Arc < Context < Message > > ,
325
391
hash_or_number : & str ,
392
+ limit : u64 ,
393
+ skip : u64 ,
394
+ order : Order ,
326
395
handlers_config : Arc < HandlersConfig > ,
327
396
) -> Result < RESTResponse > {
328
397
let block_key = match parse_block_key ( hash_or_number) {
@@ -331,7 +400,12 @@ async fn handle_blocks_hash_number_transactions_cbor_blockfrost(
331
400
} ;
332
401
333
402
let block_txs_cbor_msg = Arc :: new ( Message :: StateQuery ( StateQuery :: Blocks (
334
- BlocksStateQuery :: GetBlockTransactionsCBOR { block_key } ,
403
+ BlocksStateQuery :: GetBlockTransactionsCBOR {
404
+ block_key,
405
+ limit,
406
+ skip,
407
+ order,
408
+ } ,
335
409
) ) ) ;
336
410
let block_txs_cbor = query_state (
337
411
& context,
0 commit comments