Skip to content

Commit

Permalink
feat(store-sync): add startBlock option to syncToRecs (#1236)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic authored Aug 3, 2023
1 parent 582388b commit 8fcd82e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/store-sync/src/recs/syncToRecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type SyncToRecsOptions<
publicClient: PublicClient;
// TODO: generate these from config and return instead?
components: TComponents;
startBlock?: bigint;
indexerUrl?: string;
initialState?: {
blockNumber: bigint | null;
Expand Down Expand Up @@ -78,6 +79,7 @@ export async function syncToRecs<
address,
publicClient,
components: initialComponents,
startBlock = 0n,
initialState,
indexerUrl,
}: SyncToRecsOptions<TConfig, TComponents>): Promise<SyncToRecsResult<TConfig, TComponents>> {
Expand All @@ -88,11 +90,9 @@ export async function syncToRecs<

world.registerEntity({ id: singletonEntity });

let startBlock = 0n;

if (indexerUrl != null && initialState == null) {
const indexer = createIndexerClient({ url: indexerUrl });
try {
const indexer = createIndexerClient({ url: indexerUrl });
const chainId = publicClient.chain?.id ?? (await publicClient.getChainId());
initialState = await indexer.findAll.query({ chainId, address });
} catch (error) {
Expand Down

0 comments on commit 8fcd82e

Please sign in to comment.