@ton/ton 13.7.0 → 13.8.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.
@@ -261,33 +261,58 @@ class TonClient {
261
261
  }
262
262
  exports.TonClient = TonClient;
263
263
  _TonClient_api = new WeakMap();
264
- function parseStack(src) {
265
- let stack = [];
266
- for (let s of src) {
267
- if (s[0] === 'num') {
268
- let val = s[1];
269
- if (val.startsWith('-')) {
270
- stack.push({ type: 'int', value: -BigInt(val.slice(1)) });
271
- }
272
- else {
273
- stack.push({ type: 'int', value: BigInt(val) });
274
- }
275
- }
276
- else if (s[0] === 'null') {
277
- stack.push({ type: 'null' });
278
- }
279
- else if (s[0] === 'cell') {
280
- stack.push({ type: 'cell', cell: core_1.Cell.fromBoc(Buffer.from(s[1].bytes, 'base64'))[0] });
281
- }
282
- else if (s[0] === 'slice') {
283
- stack.push({ type: 'slice', cell: core_1.Cell.fromBoc(Buffer.from(s[1].bytes, 'base64'))[0] });
284
- }
285
- else if (s[0] === 'builder') {
286
- stack.push({ type: 'builder', cell: core_1.Cell.fromBoc(Buffer.from(s[1].bytes, 'base64'))[0] });
264
+ function parseStackEntry(s) {
265
+ switch (s["@type"]) {
266
+ case "tvm.stackEntryNumber":
267
+ return { type: 'int', value: BigInt(s.number.number) };
268
+ case "tvm.stackEntryCell":
269
+ return { type: 'cell', cell: core_1.Cell.fromBase64(s.cell) };
270
+ case 'tvm.stackEntryTuple':
271
+ return { type: 'tuple', items: s.tuple.elements.map(parseStackEntry) };
272
+ default:
273
+ throw Error("Unsupported item type: " + s["@type"]);
274
+ }
275
+ }
276
+ function parseStackItem(s) {
277
+ if (s[0] === 'num') {
278
+ let val = s[1];
279
+ if (val.startsWith('-')) {
280
+ return { type: 'int', value: -BigInt(val.slice(1)) };
287
281
  }
288
282
  else {
289
- throw Error('Unsupported stack item type: ' + s[0]);
283
+ return { type: 'int', value: BigInt(val) };
284
+ }
285
+ }
286
+ else if (s[0] === 'null') {
287
+ return { type: 'null' };
288
+ }
289
+ else if (s[0] === 'cell') {
290
+ return { type: 'cell', cell: core_1.Cell.fromBoc(Buffer.from(s[1].bytes, 'base64'))[0] };
291
+ }
292
+ else if (s[0] === 'slice') {
293
+ return { type: 'slice', cell: core_1.Cell.fromBoc(Buffer.from(s[1].bytes, 'base64'))[0] };
294
+ }
295
+ else if (s[0] === 'builder') {
296
+ return { type: 'builder', cell: core_1.Cell.fromBoc(Buffer.from(s[1].bytes, 'base64'))[0] };
297
+ }
298
+ else if (s[0] === 'tuple' || s[0] === 'list') {
299
+ // toncenter.com missbehaviour
300
+ if (s[1].elements.length === 0) {
301
+ return { type: 'null' };
290
302
  }
303
+ return {
304
+ type: s[0],
305
+ items: s[1].elements.map(parseStackEntry)
306
+ };
307
+ }
308
+ else {
309
+ throw Error('Unsupported stack item type: ' + s[0]);
310
+ }
311
+ }
312
+ function parseStack(src) {
313
+ let stack = [];
314
+ for (let s of src) {
315
+ stack.push(parseStackItem(s));
291
316
  }
292
317
  return new core_1.TupleReader(stack);
293
318
  }