-
Notifications
You must be signed in to change notification settings - Fork 11
/
parseEvent.ts
52 lines (45 loc) · 1.23 KB
/
parseEvent.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { PublicKey, Connection } from "@solana/web3.js";
import {
AnchorProvider,
BN,
Wallet,
BorshCoder,
} from "@coral-xyz/anchor";
import { RPC, programId } from "./utils";
import { authority } from "./utils";
import {
OpenBookV2Client,
PlaceOrderArgs,
Side,
IDL,
} from "@openbook-dex/openbook-v2";
async function main() {
const wallet = new Wallet(authority);
const provider = new AnchorProvider(new Connection(RPC), wallet, {
commitment: "confirmed",
});
const client = new OpenBookV2Client(provider);
const txId =
"64uAnfXqUHTrTPYTPzyU11bu38dqDPj1owXvLH3j6WRK35dRBvVwaD5S2KoqSQwNCxpapdvzPNyT9MN79TSP7QLD";
// Get transaction from its signature
const tx = await client.connection.getTransaction(txId, {
commitment: "confirmed",
});
let borshCoder = new BorshCoder(IDL);
if (tx && tx.meta?.logMessages) {
for (const logs of tx.meta?.logMessages) {
const event = extractEventData(logs.toString());
if (event) {
console.log(borshCoder.events.decode(event));
}
}
}
}
function extractEventData(input: string): string | null {
const prefix = "Program data: ";
if (input.startsWith(prefix)) {
return input.substring(prefix.length);
}
return null;
}
main();