Skip to content

Commit f9f32f1

Browse files
committed
topic filter
1 parent 61c2225 commit f9f32f1

File tree

2 files changed

+29
-12
lines changed
  • apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/cross-chain
  • packages/thirdweb/src/event/actions

2 files changed

+29
-12
lines changed

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/cross-chain/page.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { fetchPublishedContractsFromDeploy } from "components/contract-component
22
import { notFound } from "next/navigation";
33
import {
44
type ContractOptions,
5-
eth_blockNumber,
65
eth_getTransactionByHash,
76
eth_getTransactionReceipt,
87
getContractEvents,
@@ -111,16 +110,15 @@ export default async function Page(props: {
111110
let creationBlockNumber: bigint | undefined;
112111

113112
if (twCloneFactoryContract) {
114-
const latestBlockNumber = await eth_blockNumber(
115-
getRpcClient({
116-
client: contract.client,
117-
chain: contract.chain,
118-
}),
119-
);
120113
const events = await getContractEvents({
121114
contract: twCloneFactoryContract,
122115
events: [ProxyDeployedEvent],
123-
blockRange: latestBlockNumber < 100000n ? latestBlockNumber : 100000n,
116+
insightTopicFilters: [
117+
{
118+
topic: params.contractAddress as `0x${string}`,
119+
index: 2,
120+
},
121+
],
124122
});
125123
const event = events.find(
126124
(e) =>

packages/thirdweb/src/event/actions/get-events.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,14 @@ export type GetContractEventsResult<
5757

5858
export type GetLogsParamsExtra = {
5959
signature?: string;
60+
insightTopicFilters?: InsightTopicFilter[];
6061
} & GetLogsParams;
6162

63+
export type InsightTopicFilter = {
64+
topic: Hex;
65+
index: 1 | 2 | 3;
66+
};
67+
6268
/**
6369
* Retrieves events from a contract based on the provided options.
6470
* @param options - The options for retrieving events.
@@ -114,7 +120,9 @@ export async function getContractEvents<
114120
>[],
115121
const TStrict extends boolean = true,
116122
>(
117-
options: GetContractEventsOptions<abi, abiEvents, TStrict>,
123+
options: GetContractEventsOptions<abi, abiEvents, TStrict> & {
124+
insightTopicFilters?: InsightTopicFilter[];
125+
},
118126
): Promise<GetContractEventsResult<abiEvents, TStrict>> {
119127
const { contract, events, blockRange, ...restParams } = options;
120128

@@ -182,6 +190,7 @@ export async function getContractEvents<
182190
address: getAddress(contract.address),
183191
topics: e.topics,
184192
signature: `${e?.abiEvent.name}(${e?.abiEvent.inputs.map((i) => i.type).join(",")})`,
193+
insightTopicFilters: options.insightTopicFilters,
185194
}))
186195
: // otherwise we want "all" events (aka not pass any topics at all)
187196
[{ ...restParams, address: getAddress(contract.address) }];
@@ -220,8 +229,9 @@ async function getLogsFromInsight(options: {
220229
chain: Chain;
221230
client: ThirdwebClient;
222231
signature?: string;
232+
insightTopicFilters?: InsightTopicFilter[];
223233
}): Promise<Log[]> {
224-
const { params, chain, client } = options;
234+
const { params, chain, client, signature, insightTopicFilters } = options;
225235

226236
const chainServices = await getChainServices(chain);
227237
const insightEnabled = chainServices.some(
@@ -237,8 +247,8 @@ async function getLogsFromInsight(options: {
237247
let path = "";
238248
if (params.address) {
239249
path += `/${params.address}`;
240-
if (params.signature) {
241-
path += `/${params.signature}`;
250+
if (signature) {
251+
path += `/${signature}`;
242252
}
243253
}
244254
const url = new URL(path, baseUrl);
@@ -267,6 +277,15 @@ async function getLogsFromInsight(options: {
267277
}
268278
}
269279

280+
if (insightTopicFilters) {
281+
for (const topicFilter of insightTopicFilters) {
282+
url.searchParams.set(
283+
`filter_topic_${topicFilter.index}`,
284+
topicFilter.topic,
285+
);
286+
}
287+
}
288+
270289
const clientFetch = getClientFetch(client);
271290
const result = await clientFetch(url.toString());
272291
const fetchedEventData = (await result.json()) as {

0 commit comments

Comments
 (0)