-
Notifications
You must be signed in to change notification settings - Fork 31
feat(synapse-core): support paginated client dataset reads from FWSS #698
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
Merged
hugomrdias
merged 4 commits into
FilOzone:master
from
Chaitu-Tatipamula:paginated-fwss-reads
Apr 2, 2026
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d10caa6
feat(synapse-core): support paginated client dataset reads from FWSS
Chaitu-Tatipamula ed66393
fix(synapse-core): address PR review — simplify getClientDataSets arg…
Chaitu-Tatipamula 30b78b6
chore: add version label to GIT_REF
Chaitu-Tatipamula 6807891
refactor: rename getClientDataSetsIds to getClientDataSetIds
Chaitu-Tatipamula File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
packages/synapse-core/src/warm-storage/get-client-data-sets-ids.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| import type { Simplify } from 'type-fest' | ||
| import type { | ||
| Address, | ||
| Chain, | ||
| Client, | ||
| ContractFunctionParameters, | ||
| ContractFunctionReturnType, | ||
| ReadContractErrorType, | ||
| Transport, | ||
| } from 'viem' | ||
| import { readContract } from 'viem/actions' | ||
| import type { fwssView as storageViewAbi } from '../abis/index.ts' | ||
| import { asChain } from '../chains.ts' | ||
| import type { ActionCallChain } from '../types.ts' | ||
|
|
||
| export namespace getClientDataSetsIds { | ||
| export type OptionsType = { | ||
| /** Client address to fetch data set IDs for. */ | ||
| address: Address | ||
| /** Starting index (0-based). Use 0 to start from beginning. Defaults to 0. */ | ||
| offset?: bigint | ||
| /** Maximum number of dataset IDs to return. Use 0 to get all remaining IDs. Defaults to 0. */ | ||
| limit?: bigint | ||
| /** Warm storage contract address. If not provided, the default is the storage view contract address for the chain. */ | ||
| contractAddress?: Address | ||
| } | ||
|
|
||
| export type ContractOutputType = ContractFunctionReturnType< | ||
| typeof storageViewAbi, | ||
| 'pure' | 'view', | ||
| 'clientDataSets', | ||
| [Address, bigint, bigint] | ||
| > | ||
|
|
||
| /** Array of client data set IDs */ | ||
| export type OutputType = bigint[] | ||
|
|
||
| export type ErrorType = asChain.ErrorType | ReadContractErrorType | ||
| } | ||
|
|
||
| /** | ||
| * Get client data set IDs with optional pagination | ||
| * | ||
| * For large lists, use pagination to avoid gas limit issues. If limit=0, | ||
| * returns all remaining IDs starting from offset. | ||
| * | ||
| * @param client - The client to use to get data set IDs. | ||
| * @param options - {@link getClientDataSetsIds.OptionsType} | ||
| * @returns Array of data set IDs {@link getClientDataSetsIds.OutputType} | ||
| * @throws Errors {@link getClientDataSetsIds.ErrorType} | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { getClientDataSetsIds } from '@filoz/synapse-core/warm-storage' | ||
| * import { createPublicClient, http } from 'viem' | ||
| * import { calibration } from '@filoz/synapse-core/chains' | ||
| * | ||
| * const client = createPublicClient({ | ||
| * chain: calibration, | ||
| * transport: http(), | ||
| * }) | ||
| * | ||
| * // Get first 100 dataset IDs | ||
| * const ids = await getClientDataSetsIds(client, { | ||
| * address: '0x0000000000000000000000000000000000000000', | ||
| * offset: 0n, | ||
| * limit: 100n, | ||
| * }) | ||
| * | ||
| * console.log(ids) | ||
| * ``` | ||
| */ | ||
| export async function getClientDataSetsIds( | ||
| client: Client<Transport, Chain>, | ||
| options: getClientDataSetsIds.OptionsType | ||
| ): Promise<getClientDataSetsIds.OutputType> { | ||
| const data = await readContract( | ||
| client, | ||
| getClientDataSetsIdsCall({ | ||
| chain: client.chain, | ||
| address: options.address, | ||
| offset: options.offset, | ||
| limit: options.limit, | ||
| contractAddress: options.contractAddress, | ||
| }) | ||
| ) | ||
| return data as getClientDataSetsIds.OutputType | ||
| } | ||
|
|
||
| export namespace getClientDataSetsIdsCall { | ||
| export type OptionsType = Simplify<getClientDataSetsIds.OptionsType & ActionCallChain> | ||
| export type ErrorType = asChain.ErrorType | ||
| export type OutputType = ContractFunctionParameters< | ||
| typeof storageViewAbi, | ||
| 'pure' | 'view', | ||
| 'clientDataSets', | ||
| [Address, bigint, bigint] | ||
| > | ||
| } | ||
|
|
||
| /** | ||
| * Create a call to the {@link getClientDataSetsIds} function for use with the Viem multicall, readContract, or simulateContract functions. | ||
| * | ||
| * @param options - {@link getClientDataSetsIdsCall.OptionsType} | ||
| * @returns The call to the clientDataSets function {@link getClientDataSetsIdsCall.OutputType} | ||
| * @throws Errors {@link getClientDataSetsIdsCall.ErrorType} | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { getClientDataSetsIdsCall } from '@filoz/synapse-core/warm-storage' | ||
| * import { createPublicClient, http } from 'viem' | ||
| * import { multicall } from 'viem/actions' | ||
| * import { calibration } from '@filoz/synapse-core/chains' | ||
| * | ||
| * const client = createPublicClient({ | ||
| * chain: calibration, | ||
| * transport: http(), | ||
| * }) | ||
| * | ||
| * // Paginate through IDs in batches of 50 | ||
| * const results = await multicall(client, { | ||
| * contracts: [ | ||
| * getClientDataSetsIdsCall({ chain: calibration, address: '0x...', offset: 0n, limit: 50n }), | ||
| * getClientDataSetsIdsCall({ chain: calibration, address: '0x...', offset: 50n, limit: 50n }), | ||
| * ], | ||
| * }) | ||
| * | ||
| * console.log(results) | ||
| * ``` | ||
| */ | ||
| export function getClientDataSetsIdsCall(options: getClientDataSetsIdsCall.OptionsType) { | ||
| const chain = asChain(options.chain) | ||
| return { | ||
| abi: chain.contracts.fwssView.abi, | ||
| address: options.contractAddress ?? chain.contracts.fwssView.address, | ||
| functionName: 'clientDataSets', | ||
| args: [options.address, options.offset ?? 0n, options.limit ?? 0n], | ||
| } satisfies getClientDataSetsIdsCall.OutputType | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Chaitu-Tatipamula can we
s/getClientDataSetsIds/getClientDataSetIds/in here please to get rid of the double plural? (sets ids)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure!