@ton/sandbox 0.21.0-beta.0 → 0.21.0-debugger.0
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/dist/blockchain/Blockchain.d.ts +3 -0
- package/dist/blockchain/Blockchain.js +7 -0
- package/dist/blockchain/SmartContract.d.ts +2 -0
- package/dist/blockchain/SmartContract.js +52 -6
- package/dist/debugger/Debuggee.d.ts +88 -0
- package/dist/debugger/Debuggee.js +467 -0
- package/dist/debugger/SourceMapCache.d.ts +5 -0
- package/dist/debugger/SourceMapCache.js +27 -0
- package/dist/debugger/debug.d.ts +5 -0
- package/dist/debugger/debug.js +63 -0
- package/dist/executor/Executor.d.ts +23 -0
- package/dist/executor/Executor.js +126 -1
- package/dist/executor/emulator-emscripten.js +1 -1
- package/dist/executor/emulator-emscripten.wasm.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/package.json +7 -2
|
@@ -98,6 +98,7 @@ export declare class Blockchain {
|
|
|
98
98
|
protected lock: AsyncLock;
|
|
99
99
|
protected contractFetches: Map<string, Promise<SmartContract>>;
|
|
100
100
|
protected nextCreateWalletIndex: number;
|
|
101
|
+
protected shouldDebug: boolean;
|
|
101
102
|
readonly executor: IExecutor;
|
|
102
103
|
/**
|
|
103
104
|
* Saves snapshot of current blockchain.
|
|
@@ -115,6 +116,8 @@ export declare class Blockchain {
|
|
|
115
116
|
* @param snapshot Snapshot of blockchain
|
|
116
117
|
*/
|
|
117
118
|
loadFrom(snapshot: BlockchainSnapshot): Promise<void>;
|
|
119
|
+
get debug(): boolean;
|
|
120
|
+
set debug(value: boolean);
|
|
118
121
|
/**
|
|
119
122
|
* @returns Current time in blockchain
|
|
120
123
|
*/
|
|
@@ -81,6 +81,12 @@ class Blockchain {
|
|
|
81
81
|
this.globalLibs = snapshot.libs;
|
|
82
82
|
this.nextCreateWalletIndex = snapshot.nextCreateWalletIndex;
|
|
83
83
|
}
|
|
84
|
+
get debug() {
|
|
85
|
+
return this.shouldDebug;
|
|
86
|
+
}
|
|
87
|
+
set debug(value) {
|
|
88
|
+
this.shouldDebug = value;
|
|
89
|
+
}
|
|
84
90
|
/**
|
|
85
91
|
* @returns Current time in blockchain
|
|
86
92
|
*/
|
|
@@ -112,6 +118,7 @@ class Blockchain {
|
|
|
112
118
|
this.lock = new AsyncLock_1.AsyncLock();
|
|
113
119
|
this.contractFetches = new Map();
|
|
114
120
|
this.nextCreateWalletIndex = 0;
|
|
121
|
+
this.shouldDebug = false;
|
|
115
122
|
this.networkConfig = blockchainConfigToBase64(opts.config);
|
|
116
123
|
this.executor = opts.executor;
|
|
117
124
|
this.storage = opts.storage;
|
|
@@ -98,4 +98,6 @@ export declare class SmartContract {
|
|
|
98
98
|
get verbosity(): LogsVerbosity;
|
|
99
99
|
set verbosity(value: LogsVerbosity);
|
|
100
100
|
setVerbosity(verbosity: Partial<LogsVerbosity> | Verbosity | undefined): void;
|
|
101
|
+
get debug(): boolean;
|
|
102
|
+
setDebug(debug: boolean | undefined): void;
|
|
101
103
|
}
|
|
@@ -10,11 +10,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _SmartContract_account, _SmartContract_parsedAccount, _SmartContract_lastTxTime, _SmartContract_verbosity;
|
|
13
|
+
var _SmartContract_account, _SmartContract_parsedAccount, _SmartContract_lastTxTime, _SmartContract_verbosity, _SmartContract_debug;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.SmartContract = exports.EmulationError = exports.TimeError = exports.GetMethodError = exports.createEmptyShardAccount = exports.createShardAccount = void 0;
|
|
16
16
|
const core_1 = require("@ton/core");
|
|
17
17
|
const selector_1 = require("../utils/selector");
|
|
18
|
+
const debug_1 = require("../debugger/debug");
|
|
19
|
+
const SourceMapCache_1 = require("../debugger/SourceMapCache");
|
|
18
20
|
function createShardAccount(args) {
|
|
19
21
|
let wc = args.workchain ?? 0;
|
|
20
22
|
let address = args.address ?? (0, core_1.contractAddress)(wc, { code: args.code, data: args.data });
|
|
@@ -128,6 +130,7 @@ class SmartContract {
|
|
|
128
130
|
_SmartContract_parsedAccount.set(this, void 0);
|
|
129
131
|
_SmartContract_lastTxTime.set(this, void 0);
|
|
130
132
|
_SmartContract_verbosity.set(this, void 0);
|
|
133
|
+
_SmartContract_debug.set(this, void 0);
|
|
131
134
|
this.address = shardAccount.account.addr;
|
|
132
135
|
__classPrivateFieldSet(this, _SmartContract_account, (0, core_1.beginCell)().store((0, core_1.storeShardAccount)(shardAccount)).endCell().toBoc().toString('base64'), "f");
|
|
133
136
|
__classPrivateFieldSet(this, _SmartContract_parsedAccount, shardAccount, "f");
|
|
@@ -210,10 +213,34 @@ class SmartContract {
|
|
|
210
213
|
now: this.blockchain.now,
|
|
211
214
|
...params,
|
|
212
215
|
};
|
|
213
|
-
|
|
216
|
+
const args = {
|
|
214
217
|
...this.createCommonArgs(params),
|
|
215
218
|
message: (0, core_1.beginCell)().store((0, core_1.storeMessage)(message)).endCell(),
|
|
216
|
-
}
|
|
219
|
+
};
|
|
220
|
+
if (this.debug) {
|
|
221
|
+
const acc = this.account;
|
|
222
|
+
if (acc.account === undefined || acc.account === null) {
|
|
223
|
+
console.log('Debugging uninitialized accounts is unsupported in debugger beta');
|
|
224
|
+
return await this.runCommon(() => this.blockchain.executor.runTransaction(args));
|
|
225
|
+
}
|
|
226
|
+
if (acc.account.storage.state.type !== 'active') {
|
|
227
|
+
console.log('Debugging uninitialized accounts is unsupported in debugger beta');
|
|
228
|
+
return await this.runCommon(() => this.blockchain.executor.runTransaction(args));
|
|
229
|
+
}
|
|
230
|
+
const code = acc.account.storage.state.state.code;
|
|
231
|
+
if (code === undefined || code === null) {
|
|
232
|
+
console.log('Debugging uninitialized accounts is unsupported in debugger beta');
|
|
233
|
+
return await this.runCommon(() => this.blockchain.executor.runTransaction(args));
|
|
234
|
+
}
|
|
235
|
+
const sm = SourceMapCache_1.defaultSourceMapCache.get(code.hash().toString('base64'));
|
|
236
|
+
if (sm === undefined) {
|
|
237
|
+
return await this.runCommon(() => this.blockchain.executor.runTransaction(args));
|
|
238
|
+
}
|
|
239
|
+
return await this.runCommon(() => (0, debug_1.debugTransaction)(this.blockchain.executor, args, code, sm));
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
return await this.runCommon(() => this.blockchain.executor.runTransaction(args));
|
|
243
|
+
}
|
|
217
244
|
}
|
|
218
245
|
async runTickTock(which, params) {
|
|
219
246
|
return await this.runCommon(() => this.blockchain.executor.runTickTock({
|
|
@@ -250,7 +277,7 @@ class SmartContract {
|
|
|
250
277
|
if (this.account.account?.storage.state.type !== 'active') {
|
|
251
278
|
throw new Error('Trying to run get method on non-active contract');
|
|
252
279
|
}
|
|
253
|
-
const
|
|
280
|
+
const args = {
|
|
254
281
|
code: this.account.account?.storage.state.state.code,
|
|
255
282
|
data: this.account.account?.storage.state.state.data,
|
|
256
283
|
methodId: typeof method === 'string' ? (0, selector_1.getSelectorForMethod)(method) : method,
|
|
@@ -264,7 +291,20 @@ class SmartContract {
|
|
|
264
291
|
randomSeed: params?.randomSeed ?? Buffer.alloc(32),
|
|
265
292
|
gasLimit: params?.gasLimit ?? 10000000n,
|
|
266
293
|
debugEnabled: this.verbosity.debugLogs,
|
|
267
|
-
}
|
|
294
|
+
};
|
|
295
|
+
let res;
|
|
296
|
+
if (this.debug) {
|
|
297
|
+
const sm = SourceMapCache_1.defaultSourceMapCache.get(args.code.hash().toString('base64'));
|
|
298
|
+
if (sm === undefined) {
|
|
299
|
+
res = await this.blockchain.executor.runGetMethod(args);
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
res = await (0, debug_1.debugGetMethod)(this.blockchain.executor, args, sm);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
res = await this.blockchain.executor.runGetMethod(args);
|
|
307
|
+
}
|
|
268
308
|
if (this.verbosity.print && this.verbosity.blockchainLogs && res.logs.length > 0) {
|
|
269
309
|
console.log(res.logs);
|
|
270
310
|
}
|
|
@@ -312,6 +352,12 @@ class SmartContract {
|
|
|
312
352
|
__classPrivateFieldSet(this, _SmartContract_verbosity, verbosity, "f");
|
|
313
353
|
}
|
|
314
354
|
}
|
|
355
|
+
get debug() {
|
|
356
|
+
return __classPrivateFieldGet(this, _SmartContract_debug, "f") ?? this.blockchain.debug;
|
|
357
|
+
}
|
|
358
|
+
setDebug(debug) {
|
|
359
|
+
__classPrivateFieldSet(this, _SmartContract_debug, debug, "f");
|
|
360
|
+
}
|
|
315
361
|
}
|
|
316
362
|
exports.SmartContract = SmartContract;
|
|
317
|
-
_SmartContract_account = new WeakMap(), _SmartContract_parsedAccount = new WeakMap(), _SmartContract_lastTxTime = new WeakMap(), _SmartContract_verbosity = new WeakMap();
|
|
363
|
+
_SmartContract_account = new WeakMap(), _SmartContract_parsedAccount = new WeakMap(), _SmartContract_lastTxTime = new WeakMap(), _SmartContract_verbosity = new WeakMap(), _SmartContract_debug = new WeakMap();
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import EventEmitter from 'node:events';
|
|
3
|
+
import { Executor, GetMethodArgs, RunTransactionArgs } from '../executor/Executor';
|
|
4
|
+
import { Cell, TupleItem } from '@ton/core';
|
|
5
|
+
import { LoggingDebugSession } from '@vscode/debugadapter';
|
|
6
|
+
import { DebugProtocol } from '@vscode/debugprotocol';
|
|
7
|
+
export type SourceMapEntry = {
|
|
8
|
+
path: string;
|
|
9
|
+
line: number;
|
|
10
|
+
variables: string[];
|
|
11
|
+
};
|
|
12
|
+
export type SourceMap = {
|
|
13
|
+
[k: number]: SourceMapEntry;
|
|
14
|
+
};
|
|
15
|
+
type Breakpoint = {
|
|
16
|
+
id: number;
|
|
17
|
+
line: number;
|
|
18
|
+
verified: boolean;
|
|
19
|
+
};
|
|
20
|
+
export declare class Debuggee extends EventEmitter {
|
|
21
|
+
executor: Executor;
|
|
22
|
+
ptr: number;
|
|
23
|
+
debugType: 'get' | 'tx';
|
|
24
|
+
sourceMap: SourceMap;
|
|
25
|
+
availableLines: {
|
|
26
|
+
[k: string]: number[];
|
|
27
|
+
};
|
|
28
|
+
codeCells: Map<string, Cell>;
|
|
29
|
+
breakpoints: Map<string, Breakpoint[]>;
|
|
30
|
+
breakpointID: number;
|
|
31
|
+
frames: string[];
|
|
32
|
+
finishedCallback: (v: any) => void;
|
|
33
|
+
constructor(executor: Executor, finishedCallback: (v: any) => void);
|
|
34
|
+
setCodeCells(code: Cell): void;
|
|
35
|
+
setSourceMap(sourceMap: SourceMap): void;
|
|
36
|
+
getAvailableSourcePaths(): string[];
|
|
37
|
+
getAvailableLines(path: string): number[];
|
|
38
|
+
isLineAvailable(path: string, line: number): boolean;
|
|
39
|
+
continue(): void;
|
|
40
|
+
step(stopEvent?: string): void;
|
|
41
|
+
startGetMethod(args: GetMethodArgs): void;
|
|
42
|
+
startTransaction(args: RunTransactionArgs): void;
|
|
43
|
+
vmStep(): boolean;
|
|
44
|
+
codePos(): {
|
|
45
|
+
hash: string;
|
|
46
|
+
offset: number;
|
|
47
|
+
};
|
|
48
|
+
getStack(): TupleItem[];
|
|
49
|
+
currentDebugInfoNumber(): number | undefined;
|
|
50
|
+
currentSourceMapEntry(): SourceMapEntry | undefined;
|
|
51
|
+
breakpointKey(path: string, line: number): string;
|
|
52
|
+
splitBreakpointKey(k: string): {
|
|
53
|
+
path: string;
|
|
54
|
+
line: number;
|
|
55
|
+
};
|
|
56
|
+
clearBreakpoints(path: string): void;
|
|
57
|
+
hasBreakpoint(path: string, line: number): boolean;
|
|
58
|
+
setBreakpoint(path: string, line: number): Breakpoint;
|
|
59
|
+
sendEvent(event: string, ...args: any[]): void;
|
|
60
|
+
onFinished(): void;
|
|
61
|
+
stepUntilLine(breakpointsOnly: boolean, stopEvent?: string): void;
|
|
62
|
+
prepareGetMethod(args: GetMethodArgs, sourceMap: SourceMap): void;
|
|
63
|
+
prepareTransaction(args: RunTransactionArgs, code: Cell, sourceMap: SourceMap): void;
|
|
64
|
+
start(debug: boolean, stopOnEntry: boolean): void;
|
|
65
|
+
}
|
|
66
|
+
export declare class TVMDebugSession extends LoggingDebugSession {
|
|
67
|
+
static readonly threadID = 1;
|
|
68
|
+
static readonly stackFrameID = 1;
|
|
69
|
+
static readonly variablesReference = 1;
|
|
70
|
+
debuggee: Debuggee;
|
|
71
|
+
constructor(debuggee: Debuggee);
|
|
72
|
+
protected initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void;
|
|
73
|
+
protected loadedSourcesRequest(response: DebugProtocol.LoadedSourcesResponse, args: DebugProtocol.LoadedSourcesArguments, request?: DebugProtocol.Request | undefined): void;
|
|
74
|
+
protected breakpointLocationsRequest(response: DebugProtocol.BreakpointLocationsResponse, args: DebugProtocol.BreakpointLocationsArguments, request?: DebugProtocol.Request | undefined): void;
|
|
75
|
+
protected launchRequest(response: DebugProtocol.LaunchResponse, args: DebugProtocol.LaunchRequestArguments, request?: DebugProtocol.Request | undefined): void;
|
|
76
|
+
protected attachRequest(response: DebugProtocol.AttachResponse, args: DebugProtocol.AttachRequestArguments, request?: DebugProtocol.Request | undefined): void;
|
|
77
|
+
protected setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments, request?: DebugProtocol.Request | undefined): void;
|
|
78
|
+
protected threadsRequest(response: DebugProtocol.ThreadsResponse, request?: DebugProtocol.Request | undefined): void;
|
|
79
|
+
protected continueRequest(response: DebugProtocol.ContinueResponse, args: DebugProtocol.ContinueArguments, request?: DebugProtocol.Request | undefined): void;
|
|
80
|
+
protected nextRequest(response: DebugProtocol.NextResponse, args: DebugProtocol.NextArguments, request?: DebugProtocol.Request | undefined): void;
|
|
81
|
+
protected stepInRequest(response: DebugProtocol.StepInResponse, args: DebugProtocol.StepInArguments, request?: DebugProtocol.Request | undefined): void;
|
|
82
|
+
protected stepOutRequest(response: DebugProtocol.StepOutResponse, args: DebugProtocol.StepOutArguments, request?: DebugProtocol.Request | undefined): void;
|
|
83
|
+
protected stackTraceRequest(response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments, request?: DebugProtocol.Request | undefined): void;
|
|
84
|
+
protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments, request?: DebugProtocol.Request | undefined): void;
|
|
85
|
+
protected variablesRequest(response: DebugProtocol.VariablesResponse, args: DebugProtocol.VariablesArguments, request?: DebugProtocol.Request | undefined): void;
|
|
86
|
+
protected disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments, request?: DebugProtocol.Request | undefined): void;
|
|
87
|
+
}
|
|
88
|
+
export {};
|