@tonappchain/sdk 0.5.1 → 0.5.4

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/README.md CHANGED
@@ -688,22 +688,22 @@ Fetches the current status information for multiple operations based on their op
688
688
 
689
689
  Track the execution of crosschain operation with `startTracking` method
690
690
 
691
- #### Method: `async function startTracking(transactionLinker: TransactionLinker, network: Network, customLiteSequencerEndpoints?: string[], delay: number = 10, maxIterationCount = MAX_ITERATION_COUNT, returnValue: boolean = false): Promise<void | { profilingData: ExecutionStages; tableData: ExecutionStagesTableData[]; }>`
691
+ #### Method: `async function startTracking(transactionLinker: TransactionLinker, network: Network, options?: { customLiteSequencerEndpoints?: string[]; delay?: number; maxIterationCount?: number; returnValue?: boolean; tableView?: boolean; }): Promise<void | ExecutionStages>`
692
692
 
693
693
  #### **Parameters**:
694
694
  - `transactionLinker`: A `TransactionLinker` object returned from `sendCrossChainTransaction` function.
695
695
  - `network`: TON network (`Network` type).
696
- - `customLiteSequencerEndpoints` *(optional)*: specify custom lite sequencer API URL for sending requests there.
697
- - `delay` *(optional)*: specify custom delay after requests there.
698
- - `maxIterationCount` *(optional)*: specify custom max iteration count there.
699
- - `returnValue` *(optional)*: specify whether to return the data to you after tracking. When `false` will write to the console. Default is `false`
696
+ - `options` *(optional)*:
697
+ - `customLiteSequencerEndpoints` *(optional)*: specify custom lite sequencer API URL for sending requests there. Default is `undefined`
698
+ - `delay` *(optional)*: specify custom delay after requests there. Default is `10`
699
+ - `maxIterationCount` *(optional)*: specify custom max iteration count there. Default is `120`
700
+ - `returnValue` *(optional)*: specify whether to return the data to you after tracking. When `false` will write to the console. Default is `false`
701
+ - `tableView` *(optional)*: specify data display in the table. Default is `true`
700
702
 
701
703
  #### **Returns**:
702
704
  - Will stop requesting status once the final status of crosschain operation has been reached.
703
705
  - if returnValue is `false` return `Promise<void>`
704
- - if `true` return `Promise<TrackingOperationResult>` with value:
705
- - **`profilingData`**: `ExecutionStages` - execution stages profiling data;
706
- - **`tableData`**: `ExecutionStagesTableData[]` - execution stages profiling data in table format;
706
+ - if `true` return `Promise<ExecutionStages>` - execution stages profiling data.
707
707
 
708
708
  #### **Possible exceptions**
709
709
 
@@ -1028,6 +1028,7 @@ Combines `StageData` with an additional stage identifier.
1028
1028
  - **`stage`**: Current stage in `StageName` enum.
1029
1029
  - **Other Properties from `StageData`**
1030
1030
 
1031
+
1031
1032
  ### `OperationType`
1032
1033
 
1033
1034
  ```typescript
@@ -1088,24 +1089,6 @@ Represents the profiling data for all execution stages within an operation.
1088
1089
  - **`INCLUDED_IN_TON_CONSENSUS`**.
1089
1090
  - **`EXECUTED_IN_TON`**.
1090
1091
 
1091
- ### `ExecutionStagesTableData`
1092
-
1093
- ```typescript
1094
- export type ExecutionStagesTableData = {
1095
- stage: string;
1096
- exists: string;
1097
- success: string;
1098
- timestamp: string;
1099
- transactions: string;
1100
- noteContent: string;
1101
- errorName: string;
1102
- internalMsg: string;
1103
- bytesError: string;
1104
- };
1105
- ```
1106
-
1107
- Represents the profiling data for all execution stages in table format.
1108
-
1109
1092
 
1110
1093
  ### `ExecutionStagesByOperationId`
1111
1094
 
@@ -35,21 +35,32 @@ class OperationTracker {
35
35
  throw errors_1.operationFetchError;
36
36
  }
37
37
  async getOperationId(transactionLinker) {
38
+ const requestBody = {
39
+ shardsKey: transactionLinker.shardsKey,
40
+ caller: transactionLinker.caller,
41
+ shardCount: transactionLinker.shardCount,
42
+ timestamp: transactionLinker.timestamp,
43
+ };
44
+ let operationId = undefined;
38
45
  for (const endpoint of this.customLiteSequencerEndpoints) {
39
46
  try {
40
- const requestBody = {
41
- shardsKey: transactionLinker.shardsKey,
42
- caller: transactionLinker.caller,
43
- shardCount: transactionLinker.shardCount,
44
- timestamp: transactionLinker.timestamp,
45
- };
46
47
  const response = await axios_1.default.post(`${endpoint}/ton/operation-id`, requestBody);
47
48
  return response.data.response || '';
48
49
  }
49
50
  catch (error) {
51
+ if (axios_1.default.isAxiosError(error)) {
52
+ if (error.response?.status === 404) {
53
+ console.warn(`404 Not Found: ${endpoint}/ton/operation-id`);
54
+ operationId = '';
55
+ continue;
56
+ }
57
+ }
50
58
  console.error(`Failed to get OperationId with ${endpoint}:`, error);
51
59
  }
52
60
  }
61
+ if (operationId !== undefined) {
62
+ return operationId;
63
+ }
53
64
  throw errors_1.operationFetchError;
54
65
  }
55
66
  async getOperationIdsByShardsKeys(shardsKeys, caller) {
@@ -1,2 +1,8 @@
1
- import { Network, TrackingOperationResult, TransactionLinker } from '../structs/Struct';
2
- export declare function startTracking(transactionLinker: TransactionLinker, network: Network, customLiteSequencerEndpoints?: string[], delay?: number, maxIterationCount?: number, returnValue?: boolean): Promise<void | TrackingOperationResult>;
1
+ import { ExecutionStages, Network, TransactionLinker } from '../structs/Struct';
2
+ export declare function startTracking(transactionLinker: TransactionLinker, network: Network, options?: {
3
+ customLiteSequencerEndpoints?: string[];
4
+ delay?: number;
5
+ maxIterationCount?: number;
6
+ returnValue?: boolean;
7
+ tableView?: boolean;
8
+ }): Promise<void | ExecutionStages>;
@@ -1,11 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.startTracking = startTracking;
4
7
  const Struct_1 = require("../structs/Struct");
5
8
  const Consts_1 = require("./Consts");
6
9
  const OperationTracker_1 = require("./OperationTracker");
7
10
  const Utils_1 = require("./Utils");
8
- async function startTracking(transactionLinker, network, customLiteSequencerEndpoints, delay = 10, maxIterationCount = Consts_1.MAX_ITERATION_COUNT, returnValue = false) {
11
+ const cli_table3_1 = __importDefault(require("cli-table3"));
12
+ async function startTracking(transactionLinker, network, options) {
13
+ const { customLiteSequencerEndpoints, delay = 10, maxIterationCount = Consts_1.MAX_ITERATION_COUNT, returnValue = false, tableView = true, } = options || {};
9
14
  const tracker = new OperationTracker_1.OperationTracker(network, customLiteSequencerEndpoints);
10
15
  console.log('Start tracking operation');
11
16
  console.log('caller: ', transactionLinker.caller);
@@ -16,7 +21,7 @@ async function startTracking(transactionLinker, network, customLiteSequencerEndp
16
21
  let iteration = 0; // number of iterations
17
22
  let operationType = '';
18
23
  let ok = true; // finished successfully
19
- let errorMessage;
24
+ let errorMessage = '';
20
25
  while (true) {
21
26
  ++iteration;
22
27
  if (iteration >= maxIterationCount) {
@@ -30,9 +35,7 @@ async function startTracking(transactionLinker, network, customLiteSequencerEndp
30
35
  try {
31
36
  operationId = await tracker.getOperationId(transactionLinker);
32
37
  }
33
- catch (err) {
34
- console.log('get operationId error');
35
- }
38
+ catch (err) { }
36
39
  }
37
40
  else {
38
41
  console.log('request operationType');
@@ -53,15 +56,22 @@ async function startTracking(transactionLinker, network, customLiteSequencerEndp
53
56
  }
54
57
  console.log('Tracking finished');
55
58
  if (!ok) {
59
+ if (returnValue) {
60
+ throw Error(errorMessage);
61
+ }
56
62
  console.log(errorMessage);
57
63
  }
58
64
  const profilingData = await tracker.getStageProfiling(operationId);
59
- const tableData = formatExecutionStages(profilingData);
60
65
  if (returnValue) {
61
- return { profilingData, tableData };
66
+ return profilingData;
62
67
  }
63
68
  console.log(profilingData.operationType);
64
- console.table(tableData);
69
+ if (tableView) {
70
+ printExecutionStagesTable(profilingData);
71
+ }
72
+ else {
73
+ console.log(formatExecutionStages(profilingData));
74
+ }
65
75
  }
66
76
  function formatExecutionStages(stages) {
67
77
  const { operationType, ...stagesData } = stages;
@@ -74,7 +84,7 @@ function formatExecutionStages(stages) {
74
84
  data.stageData &&
75
85
  data.stageData.transactions != null &&
76
86
  data.stageData.transactions.length > 0
77
- ? data.stageData.transactions.map((t) => t.hash).join(', ')
87
+ ? data.stageData.transactions.map((t) => t.hash).join(' \n')
78
88
  : '-',
79
89
  noteContent: data.exists && data.stageData && data.stageData.note != null ? data.stageData.note.content : '-',
80
90
  errorName: data.exists && data.stageData && data.stageData.note != null ? data.stageData.note.errorName : '-',
@@ -82,3 +92,35 @@ function formatExecutionStages(stages) {
82
92
  bytesError: data.exists && data.stageData && data.stageData.note != null ? data.stageData.note.internalBytesError : '-',
83
93
  }));
84
94
  }
95
+ function printExecutionStagesTable(stages) {
96
+ const table = new cli_table3_1.default({
97
+ head: [
98
+ 'Stage',
99
+ 'Exists',
100
+ 'Success',
101
+ 'Timestamp',
102
+ 'Transactions',
103
+ 'NoteContent',
104
+ 'ErrorName',
105
+ 'InternalMsg',
106
+ 'BytesError',
107
+ ],
108
+ colWidths: [30, 8, 9, 13, 70, 13, 13, 13, 13],
109
+ wordWrap: true,
110
+ });
111
+ const tableData = formatExecutionStages(stages);
112
+ tableData.forEach((row) => {
113
+ table.push([
114
+ row.stage,
115
+ row.exists,
116
+ row.success,
117
+ row.timestamp,
118
+ row.transactions,
119
+ row.noteContent,
120
+ row.errorName,
121
+ row.internalMsg,
122
+ row.bytesError,
123
+ ]);
124
+ });
125
+ console.log(table.toString());
126
+ }
@@ -38,7 +38,7 @@ class SenderFactory {
38
38
  config.walletId = {
39
39
  networkGlobalId: params.network === Struct_1.Network.TESTNET ? -3 : -239,
40
40
  context: {
41
- walletVersion: 'V5R1',
41
+ walletVersion: 'v5r1',
42
42
  workchain: 0,
43
43
  subwalletNumber: params.options?.v5r1?.subwalletNumber ?? 0,
44
44
  },
@@ -152,12 +152,12 @@ export type TACSimulationRequest = {
152
152
  tonCaller: string;
153
153
  };
154
154
  export declare enum StageName {
155
- COLLECTED_IN_TAC = "COLLECTED_IN_TAC",
156
- INCLUDED_IN_TAC_CONSENSUS = "INCLUDED_IN_TAC_CONSENSUS",
157
- EXECUTED_IN_TAC = "EXECUTED_IN_TAC",
158
- COLLECTED_IN_TON = "COLLECTED_IN_TON",
159
- INCLUDED_IN_TON_CONSENSUS = "INCLUDED_IN_TON_CONSENSUS",
160
- EXECUTED_IN_TON = "EXECUTED_IN_TON"
155
+ COLLECTED_IN_TAC = "collectedInTAC",
156
+ INCLUDED_IN_TAC_CONSENSUS = "includedInTACConsensus",
157
+ EXECUTED_IN_TAC = "executedInTAC",
158
+ COLLECTED_IN_TON = "collectedInTON",
159
+ INCLUDED_IN_TON_CONSENSUS = "includedInTONConsensus",
160
+ EXECUTED_IN_TON = "executedInTON"
161
161
  }
162
162
  export type TransactionData = {
163
163
  hash: string;
@@ -185,21 +185,6 @@ export type ProfilingStageData = {
185
185
  export type ExecutionStages = {
186
186
  operationType: OperationType;
187
187
  } & Record<StageName, ProfilingStageData>;
188
- export type ExecutionStagesTableData = {
189
- stage: string;
190
- exists: string;
191
- success: string;
192
- timestamp: string;
193
- transactions: string;
194
- noteContent: string;
195
- errorName: string;
196
- internalMsg: string;
197
- bytesError: string;
198
- };
199
- export type TrackingOperationResult = {
200
- profilingData: ExecutionStages;
201
- tableData: ExecutionStagesTableData[];
202
- };
203
188
  export type ExecutionStagesByOperationId = Record<string, ExecutionStages>;
204
189
  export type StatusInfosByOperationId = Record<string, StatusInfo>;
205
190
  export type OperationIds = {
@@ -29,10 +29,10 @@ var OperationType;
29
29
  })(OperationType || (exports.OperationType = OperationType = {}));
30
30
  var StageName;
31
31
  (function (StageName) {
32
- StageName["COLLECTED_IN_TAC"] = "COLLECTED_IN_TAC";
33
- StageName["INCLUDED_IN_TAC_CONSENSUS"] = "INCLUDED_IN_TAC_CONSENSUS";
34
- StageName["EXECUTED_IN_TAC"] = "EXECUTED_IN_TAC";
35
- StageName["COLLECTED_IN_TON"] = "COLLECTED_IN_TON";
36
- StageName["INCLUDED_IN_TON_CONSENSUS"] = "INCLUDED_IN_TON_CONSENSUS";
37
- StageName["EXECUTED_IN_TON"] = "EXECUTED_IN_TON";
32
+ StageName["COLLECTED_IN_TAC"] = "collectedInTAC";
33
+ StageName["INCLUDED_IN_TAC_CONSENSUS"] = "includedInTACConsensus";
34
+ StageName["EXECUTED_IN_TAC"] = "executedInTAC";
35
+ StageName["COLLECTED_IN_TON"] = "collectedInTON";
36
+ StageName["INCLUDED_IN_TON_CONSENSUS"] = "includedInTONConsensus";
37
+ StageName["EXECUTED_IN_TON"] = "executedInTON";
38
38
  })(StageName || (exports.StageName = StageName = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonappchain/sdk",
3
- "version": "0.5.1",
3
+ "version": "0.5.4",
4
4
  "repository": "https://github.com/TacBuild/tac-sdk.git",
5
5
  "author": "TAC. <developers@tac>",
6
6
  "license": "MIT",
@@ -24,6 +24,7 @@
24
24
  "@tonappchain/ton-lite-client": "3.0.6",
25
25
  "@tonconnect/ui": "^2.0.11",
26
26
  "bn.js": "^5.2.1",
27
+ "cli-table3": "^0.6.5",
27
28
  "dotenv": "^16.4.7",
28
29
  "ethers": "^6.13.5",
29
30
  "ton-crypto": "^3.2.0"