@drift-labs/sdk 2.95.0-beta.8 → 2.95.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/VERSION +1 -1
- package/lib/events/parse.d.ts +4 -0
- package/lib/events/parse.js +24 -1
- package/package.json +1 -1
- package/src/events/parse.ts +33 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.95.0-beta.
|
|
1
|
+
2.95.0-beta.9
|
package/lib/events/parse.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { Program, Event } from '@coral-xyz/anchor';
|
|
2
2
|
export declare function parseLogs(program: Program, logs: string[], programId?: string): Event[];
|
|
3
|
+
export declare function parseLogsWithRaw(program: Program, logs: string[], programId?: string): {
|
|
4
|
+
events: Event[];
|
|
5
|
+
rawLogs: string[];
|
|
6
|
+
};
|
package/lib/events/parse.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseLogs = void 0;
|
|
3
|
+
exports.parseLogsWithRaw = exports.parseLogs = void 0;
|
|
4
4
|
const driftProgramId = 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH';
|
|
5
5
|
const PROGRAM_LOG = 'Program log: ';
|
|
6
6
|
const PROGRAM_DATA = 'Program data: ';
|
|
@@ -27,6 +27,29 @@ function parseLogs(program, logs, programId = driftProgramId) {
|
|
|
27
27
|
return events;
|
|
28
28
|
}
|
|
29
29
|
exports.parseLogs = parseLogs;
|
|
30
|
+
function parseLogsWithRaw(program, logs, programId = driftProgramId) {
|
|
31
|
+
const events = [];
|
|
32
|
+
const rawLogs = [];
|
|
33
|
+
const execution = new ExecutionContext();
|
|
34
|
+
for (const log of logs) {
|
|
35
|
+
if (log.startsWith('Log truncated')) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
const [event, newProgram, didPop] = handleLog(execution, log, program, programId);
|
|
39
|
+
if (event) {
|
|
40
|
+
events.push(event);
|
|
41
|
+
rawLogs.push(log);
|
|
42
|
+
}
|
|
43
|
+
if (newProgram) {
|
|
44
|
+
execution.push(newProgram);
|
|
45
|
+
}
|
|
46
|
+
if (didPop) {
|
|
47
|
+
execution.pop();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { events, rawLogs };
|
|
51
|
+
}
|
|
52
|
+
exports.parseLogsWithRaw = parseLogsWithRaw;
|
|
30
53
|
function handleLog(execution, log, program, programId = driftProgramId) {
|
|
31
54
|
// Executing program is drift program.
|
|
32
55
|
if (execution.stack.length > 0 && execution.program() === programId) {
|
package/package.json
CHANGED
package/src/events/parse.ts
CHANGED
|
@@ -37,6 +37,39 @@ export function parseLogs(
|
|
|
37
37
|
return events;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
export function parseLogsWithRaw(
|
|
41
|
+
program: Program,
|
|
42
|
+
logs: string[],
|
|
43
|
+
programId = driftProgramId
|
|
44
|
+
): { events: Event[]; rawLogs: string[] } {
|
|
45
|
+
const events = [];
|
|
46
|
+
const rawLogs = [];
|
|
47
|
+
const execution = new ExecutionContext();
|
|
48
|
+
for (const log of logs) {
|
|
49
|
+
if (log.startsWith('Log truncated')) {
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const [event, newProgram, didPop] = handleLog(
|
|
54
|
+
execution,
|
|
55
|
+
log,
|
|
56
|
+
program,
|
|
57
|
+
programId
|
|
58
|
+
);
|
|
59
|
+
if (event) {
|
|
60
|
+
events.push(event);
|
|
61
|
+
rawLogs.push(log);
|
|
62
|
+
}
|
|
63
|
+
if (newProgram) {
|
|
64
|
+
execution.push(newProgram);
|
|
65
|
+
}
|
|
66
|
+
if (didPop) {
|
|
67
|
+
execution.pop();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return { events, rawLogs };
|
|
71
|
+
}
|
|
72
|
+
|
|
40
73
|
function handleLog(
|
|
41
74
|
execution: ExecutionContext,
|
|
42
75
|
log: string,
|