Skip to content

Commit 75a9749

Browse files
refactor(sdk): transition SVM events client to use blocks instead of slots
This commit changes the SVM events client implementation to primarily work with blocks rather than slots, pushing the slot-to-block translation logic upstream. This makes the interface more consistent with other chain implementations and eliminates slot-specific handling throughout the codebase. By dealing with blocks as the primary unit of reference, we simplify cross-chain compatibility and create a more unified developer experience across all supported chains. The slot-to-block translation now happens in lower-level utils functions, keeping the main client interface clean. Signed-off-by: james-a-morris <[email protected]>
1 parent 27ce8ec commit 75a9749

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

Diff for: src/arch/svm/eventsClient.ts

+24-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import web3, {
1111
import { bs58 } from "../../utils";
1212
import { EventData, EventName, EventWithData } from "./types";
1313
import { decodeEvent, isDevnet } from "./utils";
14+
import { getEventName, parseEventData } from "./utils/events";
15+
import { getSlotForBlock } from "../arch/svm";
1416

1517
// Utility type to extract the return type for the JSON encoding overload. We only care about the overload where the
1618
// configuration parameter (C) has the optional property 'encoding' set to 'json'.
@@ -64,38 +66,51 @@ export class SvmSpokeEventsClient {
6466
* Queries events for the SvmSpoke program filtered by event name.
6567
*
6668
* @param eventName - The name of the event to filter by.
67-
* @param fromSlot - Optional starting slot.
68-
* @param toSlot - Optional ending slot.
69+
* @param fromBlock - Optional starting block.
70+
* @param toBlock - Optional ending block.
6971
* @param options - Options for fetching signatures.
7072
* @returns A promise that resolves to an array of events matching the eventName.
7173
*/
7274
public async queryEvents<T extends EventData>(
7375
eventName: EventName,
74-
fromSlot?: bigint,
75-
toSlot?: bigint,
76+
fromBlock?: bigint,
77+
toBlock?: bigint,
7678
options: GetSignaturesForAddressConfig = { limit: 1000, commitment: "confirmed" }
7779
): Promise<EventWithData<T>[]> {
78-
const events = await this.queryAllEvents(fromSlot, toSlot, options);
80+
const events = await this.queryAllEvents(fromBlock, toBlock, options);
7981
return events.filter((event) => event.name === eventName) as EventWithData<T>[];
8082
}
8183

8284
/**
8385
* Queries all events for a specific program.
8486
*
85-
* @param fromSlot - Optional starting slot.
86-
* @param toSlot - Optional ending slot.
87+
* @param fromBlock - Optional starting block.
88+
* @param toBlock - Optional ending block.
8789
* @param options - Options for fetching signatures.
8890
* @returns A promise that resolves to an array of all events with additional metadata.
8991
*/
9092
private async queryAllEvents(
91-
fromSlot?: bigint,
92-
toSlot?: bigint,
93+
fromBlock?: bigint,
94+
toBlock?: bigint,
9395
options: GetSignaturesForAddressConfig = { limit: 1000, commitment: "confirmed" }
9496
): Promise<EventWithData<EventData>[]> {
9597
const allSignatures: GetSignaturesForAddressTransaction[] = [];
9698
let hasMoreSignatures = true;
9799
let currentOptions = options;
98100

101+
let fromSlot: bigint | undefined;
102+
let toSlot: bigint | undefined;
103+
104+
if (fromBlock) {
105+
const slot = await getSlotForBlock(this.rpc, fromBlock, BigInt(0));
106+
fromSlot = slot;
107+
}
108+
109+
if (toBlock) {
110+
const slot = await getSlotForBlock(this.rpc, toBlock, BigInt(0));
111+
toSlot = slot;
112+
}
113+
99114
while (hasMoreSignatures) {
100115
const signatures: GetSignaturesForAddressApiResponse = await this.rpc
101116
.getSignaturesForAddress(this.svmSpokeAddress, currentOptions)

0 commit comments

Comments
 (0)