Skip to content

Commit

Permalink
fix list_vault_auction_history pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Oct 29, 2024
1 parent e37d5e4 commit 716f9bc
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/ain-ocean/src/api/loan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -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,
Expand All @@ -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)?;
Expand Down

0 comments on commit 716f9bc

Please sign in to comment.