Skip to content

Commit

Permalink
Fix pagination for token balances (helius-labs#251)
Browse files Browse the repository at this point in the history
* Fix pagination for token balances

* Fix pagination for token balances
  • Loading branch information
pmantica11 authored Nov 20, 2024
1 parent 0273820 commit 97189d7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "photon-indexer"
publish = true
readme = "README.md"
repository = "https://github.com/helius-labs/photon"
version = "0.49.0"
version = "0.50.0"

[[bin]]
name = "photon"
Expand Down
2 changes: 1 addition & 1 deletion src/api/method/get_compressed_token_balances_by_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub async fn get_compressed_token_balances_by_owner(
bytes.len()
)));
};
filter = filter.and(token_owner_balances::Column::Mint.gte::<Vec<u8>>(mint.into()));
filter = filter.and(token_owner_balances::Column::Mint.gt::<Vec<u8>>(mint.into()));
}
let limit = limit.map(|l| l.value()).unwrap_or(PAGE_LIMIT);

Expand Down
39 changes: 39 additions & 0 deletions tests/integration_tests/mock_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,45 @@ async fn test_persist_token_data(
assert_eq!(item.balance.0, *owner_to_balance.get(&item.owner).unwrap());
}
}

let mut owner_to_balances = HashMap::new();
for (mint, balances) in mint_to_owner_to_balance.into_iter() {
for (owner, balance) in balances.into_iter() {
owner_to_balances
.entry(owner)
.or_insert(HashMap::new())
.insert(mint, balance);
}
}
for owner in owner_to_balances.keys() {
let mut cursor = None;
let mut mint_to_balance = HashMap::new();

loop {
let request = GetCompressedTokenBalancesByOwnerRequest {
owner: owner.clone(),
cursor,
limit: Some(photon_indexer::api::method::utils::Limit::new(1).unwrap()),
..Default::default()
};
let res = setup
.api
.get_compressed_token_balances_by_owner(request)
.await
.unwrap()
.value;
let token_balances = res.token_balances;
for token_balance in token_balances.iter() {
let balance = mint_to_balance.entry(token_balance.mint).or_insert(0);
*balance += token_balance.balance.0;
}
cursor = res.cursor;
if cursor.is_none() {
break;
}
}
assert_eq!(mint_to_balance, *owner_to_balances.get(owner).unwrap());
}
}

#[tokio::test]
Expand Down

0 comments on commit 97189d7

Please sign in to comment.