Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export const getStakeAccounts = async (connection: Connection, withdrawAuthority: PublicKey | null, stakeAuthority: PublicKey | null): Promise<{
- pubkey: PublicKey;
- account: AccountInfo<ParsedAccountData>;
- }[]> => {
- if (!stakeAuthority && !withdrawAuthority) {
- throw new Error('At least one authority must be provided')
- }
- const filters: GetProgramAccountsFilter[] = []
- if (stakeAuthority) {
- filters.push({
- memcmp: {
- bytes: stakeAuthority.toBase58(),
- offset: 4 + 8
- }
- })
- }
- if (withdrawAuthority) {
- filters.push({
- memcmp: {
- bytes: withdrawAuthority.toBase58(),
- offset: 4 + 8 + 32
- }
- })
- }
- const stakeAccounts = await connection.getParsedProgramAccounts(StakeProgram.programId, { filters })
- return stakeAccounts as {
- pubkey: PublicKey;
- account: AccountInfo<ParsedAccountData>;
- }[]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement