Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: typescript sdk: use cursor when accumulating accounts for transfer #1171

Conversation

sergeytimoshin
Copy link
Contributor

If we have > than 1000 accounts with 0 balance, we need to fetch accounts with cursor.

* Handle report_work transaction errors gracefully in Epoch Manager
Filter out accounts with zero balances in 'system.ts'. Update 'GetCompressedAccountsByOwnerConfig' to include optional cursor and limit properties. Enhance the transfer action to batch fetch compressed accounts with positive balances.
Replaced the do-while loop with a while loop to ensure accumulated lamports threshold is met. Removed redundant filtering and directly added accounts until the required balance is reached, with an error throw if the balance is insufficient.
The redundant condition checking 'accumulatedLamports' was removed from the loop that compresses accounts. This ensures the loop processes all eligible accounts without prematurely exiting once the lamports threshold is met.
@@ -664,7 +664,7 @@ export class Rpc extends Connection implements CompressionApiInterface {
*/
async getCompressedAccountsByOwner(
owner: PublicKey,
config?: GetCompressedAccountsByOwnerConfig,
config?: GetCompressedAccountsByOwnerConfig | undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove undefined, ? already takes care of it

js/stateless.js/src/rpc-interface.ts Outdated Show resolved Hide resolved
@@ -40,7 +40,7 @@ export interface LatestNonVotingSignatures {
export interface GetCompressedAccountsByOwnerConfig {
filters?: GetCompressedAccountsFilter[];
dataSlice?: DataSlice;
cursor?: string;
cursor: string | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why replace undefined with null? this makes the interface inconsistent

js/stateless.js/src/test-helpers/test-rpc/test-rpc.ts Outdated Show resolved Hide resolved
js/stateless.js/src/actions/transfer.ts Outdated Show resolved Hide resolved
sergeytimoshin and others added 2 commits September 9, 2024 00:05
Updated the `cursor` property in `GetCompressedAccountsByOwnerConfig` to be optional and modified associated methods to streamline `cursor` management. Adjusted `_config` handling in test-rpc methods for consistency.
@sergeytimoshin sergeytimoshin merged commit 087cfbb into main Sep 9, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants