Target repo
Summary
The solana-client-tools crate has a family of helpers for fetching and deserializing zero-copy accounts (T: Pod + PrecomputedDiscriminator):
try_fetch_zero_copy_data (single account by pubkey)
try_fetch_zero_copy_data_with_commitment
try_fetch_multiple_zero_copy_data (multiple accounts by pubkey)
There is no equivalent for fetching every account of a given type from a program (a getProgramAccounts scan filtered by discriminator). Callers that need all accounts of a type currently hand-roll the same loop each time: a getProgramAccounts request with a discriminator memcmp at offset 0, a skip of zero-lamport (closed) accounts, and a checked_from_bytes_with_discriminator::<T> per account. Only the type and a label differ between copies.
Proposed helper
Add a sibling to the existing family:
pub async fn try_fetch_program_zero_copy_accounts<T: Pod + PrecomputedDiscriminator>(
&self,
program_id: &Pubkey,
commitment: CommitmentConfig,
) -> Result<Vec<(Pubkey, ZeroCopyAccountOwnedData<T>)>>
- Builds the
RpcProgramAccountsConfig with a single Memcmp filter at offset 0 carrying T's discriminator, base64 encoding, and the supplied commitment.
- Skips accounts with
lamports == 0.
- Deserializes each remaining account via
ZeroCopyAccountOwnedData<T>, the same checked_from_bytes_with_discriminator path the other helpers use.
- Returns each account paired with its pubkey.
Take commitment as a parameter to match try_fetch_zero_copy_data_with_commitment, and optionally add a default-commitment convenience wrapper mirroring try_fetch_zero_copy_data.
Motivation
Several callers reimplement this scan-and-deserialize loop. A shared helper removes the duplication and keeps the discriminator-filter and skip-empty details in one place, consistent with the rest of the zero-copy fetch family.
Target repo
solana-client-toolscrateSummary
The
solana-client-toolscrate has a family of helpers for fetching and deserializing zero-copy accounts (T: Pod + PrecomputedDiscriminator):try_fetch_zero_copy_data(single account by pubkey)try_fetch_zero_copy_data_with_commitmenttry_fetch_multiple_zero_copy_data(multiple accounts by pubkey)There is no equivalent for fetching every account of a given type from a program (a
getProgramAccountsscan filtered by discriminator). Callers that need all accounts of a type currently hand-roll the same loop each time: agetProgramAccountsrequest with a discriminatormemcmpat offset 0, a skip of zero-lamport (closed) accounts, and achecked_from_bytes_with_discriminator::<T>per account. Only the type and a label differ between copies.Proposed helper
Add a sibling to the existing family:
RpcProgramAccountsConfigwith a singleMemcmpfilter at offset 0 carryingT's discriminator, base64 encoding, and the supplied commitment.lamports == 0.ZeroCopyAccountOwnedData<T>, the samechecked_from_bytes_with_discriminatorpath the other helpers use.Take
commitmentas a parameter to matchtry_fetch_zero_copy_data_with_commitment, and optionally add a default-commitment convenience wrapper mirroringtry_fetch_zero_copy_data.Motivation
Several callers reimplement this scan-and-deserialize loop. A shared helper removes the duplication and keeps the discriminator-filter and skip-empty details in one place, consistent with the rest of the zero-copy fetch family.