|
1 | 1 | // This script queries the events of the spoke pool and prints them in a human readable format.
|
2 | 2 | import { AnchorProvider } from "@coral-xyz/anchor";
|
3 |
| -import { address, createSolanaRpc } from "@solana/kit"; |
| 3 | +import { address, createSolanaRpc, createSolanaRpcSubscriptions } from "@solana/kit"; |
4 | 4 | import { stringifyCpiEvent } from "../../src/svm/web3-v1";
|
5 | 5 | import { SvmSpokeIdl } from "../../src/svm";
|
6 | 6 | import yargs from "yargs";
|
@@ -41,11 +41,18 @@ const argvPromise = yargs(hideBin(process.argv))
|
41 | 41 | async function queryEvents(): Promise<void> {
|
42 | 42 | const argv = await argvPromise;
|
43 | 43 | const eventName = argv.eventName || "any";
|
44 |
| - const programId = argv.programId; |
45 |
| - const rpc = createSolanaRpc(provider.connection.rpcEndpoint); |
46 |
| - const events = await readProgramEvents(rpc, address(programId), SvmSpokeIdl, "confirmed"); |
47 |
| - const filteredEvents = events.filter((event: any) => (eventName == "any" ? true : event.name == eventName)); |
48 |
| - const formattedEvents = filteredEvents.map((event: any) => stringifyCpiEvent(event)); |
| 44 | + const { programId } = argv; |
| 45 | + const { rpcEndpoint } = provider.connection; |
| 46 | + |
| 47 | + const rpc = createSolanaRpc(rpcEndpoint); |
| 48 | + const rpcSubscriptions = createSolanaRpcSubscriptions( |
| 49 | + rpcEndpoint.replace(/^http(s?):\/\//i, (_m, s) => `ws${s ?? ""}://`) |
| 50 | + ); |
| 51 | + |
| 52 | + const events = await readProgramEvents({ rpc, rpcSubscriptions }, address(programId), SvmSpokeIdl, "confirmed"); |
| 53 | + |
| 54 | + const filteredEvents = events.filter((e) => (eventName === "any" ? true : e.name === eventName)); |
| 55 | + const formattedEvents = filteredEvents.map(stringifyCpiEvent); |
49 | 56 |
|
50 | 57 | console.log(JSON.stringify(formattedEvents, null, 2));
|
51 | 58 | }
|
|
0 commit comments