From 716f9bc9168a088f0aa32e1b17756f1d1c803eb5 Mon Sep 17 00:00:00 2001 From: canonbrother Date: Tue, 29 Oct 2024 15:35:21 +0800 Subject: [PATCH] fix list_vault_auction_history pagination --- lib/ain-ocean/src/api/loan.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/ain-ocean/src/api/loan.rs b/lib/ain-ocean/src/api/loan.rs index 42cf8ae603..790bb9db2e 100644 --- a/lib/ain-ocean/src/api/loan.rs +++ b/lib/ain-ocean/src/api/loan.rs @@ -551,7 +551,7 @@ async fn list_vault_auction_history( liquidation_height, batch_index ); - let next = query + let (liquidation_height, txid) = query .next .map(|q| { let (height, txid) = parse_query_height_txid(&q)?; @@ -560,8 +560,6 @@ async fn list_vault_auction_history( .transpose()? .unwrap_or((liquidation_height, Txid::from_byte_array([0xffu8; 32]))); - let size = if query.size > 0 { query.size } else { 30 }; - let liquidation_block_expiry = match ctx.network { Network::Regtest => 36, _ => 720, @@ -575,20 +573,21 @@ async fn list_vault_auction_history( Some(( vault_id, batch_index.to_be_bytes(), - next.0.to_be_bytes(), - next.1, + liquidation_height.to_be_bytes(), + txid, )), SortOrder::Descending, )? - .take(size) .take_while(|item| match item { Ok((k, _)) => { k.0 == vault_id - && k.1 == batch_index.to_be_bytes() - && u32::from_be_bytes(k.2) > liquidation_height - liquidation_block_expiry + && k.1 == batch_index.to_be_bytes() + && u32::from_be_bytes(k.2) > liquidation_height - liquidation_block_expiry } _ => true, }) + .take(query.size + usize::from(query.next.is_some())) + .skip(usize::from(query.next.is_some())) .map(|item| { let (id, history) = item?; let address = from_script(&history.from, ctx.network)?;