@tonappchain/sdk 0.6.5-mainnet-alpha → 0.6.6-mainnet-alpha
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/adapters/contractOpener.js +1 -2
- package/dist/adapters/retryableContractOpener.d.ts +21 -0
- package/dist/adapters/retryableContractOpener.js +101 -0
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.js +2 -1
- package/dist/errors/instances.d.ts +5 -3
- package/dist/errors/instances.js +9 -4
- package/dist/index.d.ts +6 -6
- package/dist/index.js +13 -13
- package/dist/sdk/LiteSequencerClient.d.ts +1 -1
- package/dist/sdk/LiteSequencerClient.js +5 -11
- package/dist/sdk/OperationTracker.d.ts +11 -9
- package/dist/sdk/OperationTracker.js +150 -72
- package/dist/sdk/TacSdk.d.ts +10 -6
- package/dist/sdk/TacSdk.js +162 -39
- package/dist/sdk/Utils.d.ts +4 -2
- package/dist/sdk/Utils.js +46 -1
- package/dist/structs/InternalStruct.d.ts +1 -1
- package/dist/structs/Struct.d.ts +41 -5
- package/dist/structs/Struct.js +6 -1
- package/dist/wrappers/JettonWallet.d.ts +11 -2
- package/dist/wrappers/JettonWallet.js +33 -16
- package/package.json +2 -2
|
@@ -70,8 +70,7 @@ async function orbsOpener(network) {
|
|
|
70
70
|
const endpoint = await (0, ton_access_1.getHttpEndpoint)({
|
|
71
71
|
network,
|
|
72
72
|
});
|
|
73
|
-
|
|
74
|
-
return client;
|
|
73
|
+
return new ton_1.TonClient({ endpoint });
|
|
75
74
|
}
|
|
76
75
|
async function orbsOpener4(network, timeout = 10000) {
|
|
77
76
|
const endpoint = await (0, ton_access_1.getHttpV4Endpoint)({ network });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ContractOpener, ContractState } from '../structs/Struct';
|
|
2
|
+
import { Address, Contract, OpenedContract } from '@ton/ton';
|
|
3
|
+
import { SandboxContract } from '@ton/sandbox';
|
|
4
|
+
import { mainnet, testnet } from '@tonappchain/artifacts';
|
|
5
|
+
export interface OpenerConfig {
|
|
6
|
+
opener: ContractOpener;
|
|
7
|
+
retries: number;
|
|
8
|
+
retryDelay: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class RetryableContractOpener implements ContractOpener {
|
|
11
|
+
private readonly openerConfigs;
|
|
12
|
+
constructor(openerConfigs: OpenerConfig[]);
|
|
13
|
+
open<T extends Contract>(src: T): OpenedContract<T> | SandboxContract<T>;
|
|
14
|
+
getContractState(address: Address): Promise<ContractState>;
|
|
15
|
+
closeConnections(): void;
|
|
16
|
+
private executeWithFallback;
|
|
17
|
+
private tryWithRetries;
|
|
18
|
+
private createRetryableContract;
|
|
19
|
+
private callMethodAcrossOpeners;
|
|
20
|
+
}
|
|
21
|
+
export declare function createDefaultRetryableOpener(artifacts: typeof testnet | typeof mainnet, maxRetries?: number, retryDelay?: number): Promise<ContractOpener>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RetryableContractOpener = void 0;
|
|
4
|
+
exports.createDefaultRetryableOpener = createDefaultRetryableOpener;
|
|
5
|
+
const Struct_1 = require("../structs/Struct");
|
|
6
|
+
const ton_1 = require("@ton/ton");
|
|
7
|
+
const artifacts_1 = require("@tonappchain/artifacts");
|
|
8
|
+
const contractOpener_1 = require("./contractOpener");
|
|
9
|
+
const instances_1 = require("../errors/instances");
|
|
10
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
11
|
+
class RetryableContractOpener {
|
|
12
|
+
constructor(openerConfigs) {
|
|
13
|
+
if (openerConfigs.length === 0) {
|
|
14
|
+
throw new Error('No ContractOpener instances available');
|
|
15
|
+
}
|
|
16
|
+
this.openerConfigs = openerConfigs;
|
|
17
|
+
}
|
|
18
|
+
open(src) {
|
|
19
|
+
const firstConfig = this.openerConfigs[0];
|
|
20
|
+
const contract = firstConfig.opener.open(src);
|
|
21
|
+
return this.createRetryableContract(contract, src);
|
|
22
|
+
}
|
|
23
|
+
async getContractState(address) {
|
|
24
|
+
const result = await this.executeWithFallback((config) => config.opener.getContractState(address));
|
|
25
|
+
if (result.success && result.data) {
|
|
26
|
+
return result.data;
|
|
27
|
+
}
|
|
28
|
+
throw result.lastError || (0, instances_1.allContractOpenerFailedError)('Failed to get contract state');
|
|
29
|
+
}
|
|
30
|
+
closeConnections() {
|
|
31
|
+
for (const config of this.openerConfigs) {
|
|
32
|
+
config.opener.closeConnections?.();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async executeWithFallback(operation) {
|
|
36
|
+
let lastError;
|
|
37
|
+
for (const config of this.openerConfigs) {
|
|
38
|
+
const result = await this.tryWithRetries(() => operation(config), config);
|
|
39
|
+
if (result.success) {
|
|
40
|
+
return { success: true, data: result.data };
|
|
41
|
+
}
|
|
42
|
+
lastError = result.lastError;
|
|
43
|
+
}
|
|
44
|
+
return { success: false, lastError };
|
|
45
|
+
}
|
|
46
|
+
async tryWithRetries(operation, config) {
|
|
47
|
+
let lastError;
|
|
48
|
+
for (let attempt = 0; attempt <= config.retries; attempt++) {
|
|
49
|
+
try {
|
|
50
|
+
const data = await operation();
|
|
51
|
+
return { success: true, data };
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
lastError = error;
|
|
55
|
+
if (attempt < config.retries) {
|
|
56
|
+
await sleep(config.retryDelay);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { success: false, lastError };
|
|
61
|
+
}
|
|
62
|
+
createRetryableContract(contract, src) {
|
|
63
|
+
return new Proxy(contract, {
|
|
64
|
+
get: (target, prop) => {
|
|
65
|
+
const value = Reflect.get(target, prop);
|
|
66
|
+
if (typeof value !== 'function')
|
|
67
|
+
return value;
|
|
68
|
+
return async (...args) => {
|
|
69
|
+
return this.callMethodAcrossOpeners(prop, args, src);
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async callMethodAcrossOpeners(methodName, args, src) {
|
|
75
|
+
const result = await this.executeWithFallback((config) => {
|
|
76
|
+
const contract = config.opener.open(src);
|
|
77
|
+
const method = Reflect.get(contract, methodName);
|
|
78
|
+
if (typeof method !== 'function') {
|
|
79
|
+
throw new Error(`Method ${String(methodName)} is not a function`);
|
|
80
|
+
}
|
|
81
|
+
return method.call(contract, ...args);
|
|
82
|
+
});
|
|
83
|
+
if (result.success)
|
|
84
|
+
return result.data;
|
|
85
|
+
throw result.lastError || (0, instances_1.allContractOpenerFailedError)('failed to call method in contract');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.RetryableContractOpener = RetryableContractOpener;
|
|
89
|
+
async function createDefaultRetryableOpener(artifacts, maxRetries = 3, retryDelay = 1000) {
|
|
90
|
+
const tonClient = new ton_1.TonClient({
|
|
91
|
+
endpoint: new URL('api/v2/jsonRPC', artifacts.TON_RPC_ENDPOINT_BY_TAC).toString(),
|
|
92
|
+
});
|
|
93
|
+
const network = artifacts === artifacts_1.testnet ? Struct_1.Network.TESTNET : Struct_1.Network.MAINNET;
|
|
94
|
+
const opener4 = await (0, contractOpener_1.orbsOpener4)(network);
|
|
95
|
+
const opener = await (0, contractOpener_1.orbsOpener)(network);
|
|
96
|
+
return new RetryableContractOpener([
|
|
97
|
+
{ opener: tonClient, retries: maxRetries, retryDelay },
|
|
98
|
+
{ opener: opener4, retries: maxRetries, retryDelay },
|
|
99
|
+
{ opener: opener, retries: maxRetries, retryDelay },
|
|
100
|
+
]);
|
|
101
|
+
}
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { emptyContractError, operationFetchError, statusFetchError, tvmAddressError, evmAddressError, unknownWalletError, unsupportedKeyError, unsupportedFormatError, notMultiplyOf8Error, prefixError, emptySettingError, invalidMethodNameError, simulationError, emptyArrayError, profilingFetchError, } from './instances';
|
|
1
|
+
export { emptyContractError, operationFetchError, statusFetchError, tvmAddressError, evmAddressError, unknownWalletError, unsupportedKeyError, unsupportedFormatError, notMultiplyOf8Error, prefixError, emptySettingError, invalidMethodNameError, simulationError, emptyArrayError, profilingFetchError, allEndpointsFailedError, } from './instances';
|
|
2
2
|
export { ContractError, FetchError, AddressError, WalletError, KeyError, FormatError, BitError, MetadataError, SettingError, EVMCallError, } from './errors';
|
package/dist/errors/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EVMCallError = exports.SettingError = exports.MetadataError = exports.BitError = exports.FormatError = exports.KeyError = exports.WalletError = exports.AddressError = exports.FetchError = exports.ContractError = exports.profilingFetchError = exports.emptyArrayError = exports.simulationError = exports.invalidMethodNameError = exports.emptySettingError = exports.prefixError = exports.notMultiplyOf8Error = exports.unsupportedFormatError = exports.unsupportedKeyError = exports.unknownWalletError = exports.evmAddressError = exports.tvmAddressError = exports.statusFetchError = exports.operationFetchError = exports.emptyContractError = void 0;
|
|
3
|
+
exports.EVMCallError = exports.SettingError = exports.MetadataError = exports.BitError = exports.FormatError = exports.KeyError = exports.WalletError = exports.AddressError = exports.FetchError = exports.ContractError = exports.allEndpointsFailedError = exports.profilingFetchError = exports.emptyArrayError = exports.simulationError = exports.invalidMethodNameError = exports.emptySettingError = exports.prefixError = exports.notMultiplyOf8Error = exports.unsupportedFormatError = exports.unsupportedKeyError = exports.unknownWalletError = exports.evmAddressError = exports.tvmAddressError = exports.statusFetchError = exports.operationFetchError = exports.emptyContractError = void 0;
|
|
4
4
|
var instances_1 = require("./instances");
|
|
5
5
|
Object.defineProperty(exports, "emptyContractError", { enumerable: true, get: function () { return instances_1.emptyContractError; } });
|
|
6
6
|
Object.defineProperty(exports, "operationFetchError", { enumerable: true, get: function () { return instances_1.operationFetchError; } });
|
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "invalidMethodNameError", { enumerable: true, get
|
|
|
17
17
|
Object.defineProperty(exports, "simulationError", { enumerable: true, get: function () { return instances_1.simulationError; } });
|
|
18
18
|
Object.defineProperty(exports, "emptyArrayError", { enumerable: true, get: function () { return instances_1.emptyArrayError; } });
|
|
19
19
|
Object.defineProperty(exports, "profilingFetchError", { enumerable: true, get: function () { return instances_1.profilingFetchError; } });
|
|
20
|
+
Object.defineProperty(exports, "allEndpointsFailedError", { enumerable: true, get: function () { return instances_1.allEndpointsFailedError; } });
|
|
20
21
|
var errors_1 = require("./errors");
|
|
21
22
|
Object.defineProperty(exports, "ContractError", { enumerable: true, get: function () { return errors_1.ContractError; } });
|
|
22
23
|
Object.defineProperty(exports, "FetchError", { enumerable: true, get: function () { return errors_1.FetchError; } });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ContractError, FetchError, AddressError, WalletError, KeyError, FormatError, BitError, MetadataError, SettingError, EVMCallError, NoValidGroupFoundError, PrepareMessageGroupError } from './errors';
|
|
2
2
|
export declare const emptyContractError: ContractError;
|
|
3
|
-
export declare const operationFetchError: FetchError;
|
|
4
|
-
export declare const statusFetchError: (msg: string) => FetchError;
|
|
3
|
+
export declare const operationFetchError: (msg: string, inner?: unknown) => FetchError;
|
|
4
|
+
export declare const statusFetchError: (msg: string, inner?: unknown) => FetchError;
|
|
5
5
|
export declare const tvmAddressError: (addr: string) => AddressError;
|
|
6
6
|
export declare const evmAddressError: (addr: string) => AddressError;
|
|
7
7
|
export declare const unknownWalletError: (version: string) => WalletError;
|
|
@@ -12,8 +12,10 @@ export declare const prefixError: MetadataError;
|
|
|
12
12
|
export declare const emptySettingError: (setting: string) => SettingError;
|
|
13
13
|
export declare const invalidMethodNameError: (methodName: string) => EVMCallError;
|
|
14
14
|
export declare const simulationError: (inner: unknown) => FetchError;
|
|
15
|
-
export declare const profilingFetchError: (msg: string) => FetchError;
|
|
15
|
+
export declare const profilingFetchError: (msg: string, inner?: unknown) => FetchError;
|
|
16
16
|
export declare const emptyArrayError: (msg: string) => FetchError;
|
|
17
17
|
export declare const invalidAssetType: FormatError;
|
|
18
18
|
export declare const prepareMessageGroupError: (isBocSizeValid: boolean, isDepthValid: boolean) => PrepareMessageGroupError;
|
|
19
19
|
export declare const noValidGroupFoundError: NoValidGroupFoundError;
|
|
20
|
+
export declare const allEndpointsFailedError: (inner: unknown) => FetchError;
|
|
21
|
+
export declare const allContractOpenerFailedError: (inner: unknown) => FetchError;
|
package/dist/errors/instances.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noValidGroupFoundError = exports.prepareMessageGroupError = exports.invalidAssetType = exports.emptyArrayError = exports.profilingFetchError = exports.simulationError = exports.invalidMethodNameError = exports.emptySettingError = exports.prefixError = exports.notMultiplyOf8Error = exports.unsupportedFormatError = exports.unsupportedKeyError = exports.unknownWalletError = exports.evmAddressError = exports.tvmAddressError = exports.statusFetchError = exports.operationFetchError = exports.emptyContractError = void 0;
|
|
3
|
+
exports.allContractOpenerFailedError = exports.allEndpointsFailedError = exports.noValidGroupFoundError = exports.prepareMessageGroupError = exports.invalidAssetType = exports.emptyArrayError = exports.profilingFetchError = exports.simulationError = exports.invalidMethodNameError = exports.emptySettingError = exports.prefixError = exports.notMultiplyOf8Error = exports.unsupportedFormatError = exports.unsupportedKeyError = exports.unknownWalletError = exports.evmAddressError = exports.tvmAddressError = exports.statusFetchError = exports.operationFetchError = exports.emptyContractError = void 0;
|
|
4
4
|
const errors_1 = require("./errors");
|
|
5
5
|
exports.emptyContractError = new errors_1.ContractError('unexpected empty contract code of given jetton.', 100);
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const operationFetchError = (msg, inner) => new errors_1.FetchError(`failed to fetch OperationId: ${msg}`, 101, inner);
|
|
7
|
+
exports.operationFetchError = operationFetchError;
|
|
8
|
+
const statusFetchError = (msg, inner) => new errors_1.FetchError(`failed to fetch status transaction: ${msg}`, 102, inner);
|
|
8
9
|
exports.statusFetchError = statusFetchError;
|
|
9
10
|
const tvmAddressError = (addr) => new errors_1.AddressError(`invalid tvm address ${addr}`, 103);
|
|
10
11
|
exports.tvmAddressError = tvmAddressError;
|
|
@@ -23,7 +24,7 @@ const invalidMethodNameError = (methodName) => new errors_1.EVMCallError(`Invali
|
|
|
23
24
|
exports.invalidMethodNameError = invalidMethodNameError;
|
|
24
25
|
const simulationError = (inner) => new errors_1.FetchError(`Failed to simulate EVM call: ${inner}`, 112, inner);
|
|
25
26
|
exports.simulationError = simulationError;
|
|
26
|
-
const profilingFetchError = (msg) => new errors_1.FetchError(`failed to fetch stage profiling: ${msg}`, 113);
|
|
27
|
+
const profilingFetchError = (msg, inner) => new errors_1.FetchError(`failed to fetch stage profiling: ${msg}`, 113, inner);
|
|
27
28
|
exports.profilingFetchError = profilingFetchError;
|
|
28
29
|
const emptyArrayError = (msg) => new errors_1.FetchError(`empty array: ${msg}`, 114);
|
|
29
30
|
exports.emptyArrayError = emptyArrayError;
|
|
@@ -31,3 +32,7 @@ exports.invalidAssetType = new errors_1.FormatError('Invalid asset type', 115);
|
|
|
31
32
|
const prepareMessageGroupError = (isBocSizeValid, isDepthValid) => new errors_1.PrepareMessageGroupError(`Failed to prepare message group: BOC size valid: ${isBocSizeValid}, depth valid: ${isDepthValid}`, 116);
|
|
32
33
|
exports.prepareMessageGroupError = prepareMessageGroupError;
|
|
33
34
|
exports.noValidGroupFoundError = new errors_1.NoValidGroupFoundError('Failed to prepare valid message group', 117);
|
|
35
|
+
const allEndpointsFailedError = (inner) => new errors_1.FetchError('All endpoints failed', 118, inner);
|
|
36
|
+
exports.allEndpointsFailedError = allEndpointsFailedError;
|
|
37
|
+
const allContractOpenerFailedError = (inner) => new errors_1.FetchError('All contract opener failed', 119, inner);
|
|
38
|
+
exports.allContractOpenerFailedError = allContractOpenerFailedError;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { liteClientOpener, orbsOpener } from './adapters/contractOpener';
|
|
2
|
+
export * from './errors';
|
|
3
|
+
export { LiteSequencerClient } from './sdk/LiteSequencerClient';
|
|
2
4
|
export { OperationTracker } from './sdk/OperationTracker';
|
|
3
5
|
export { startTracking, startTrackingMultiple } from './sdk/StartTracking';
|
|
6
|
+
export { TacSdk } from './sdk/TacSdk';
|
|
4
7
|
export * from './sender';
|
|
5
8
|
export * from './structs/Struct';
|
|
6
9
|
export { Network, SimplifiedStatuses } from './structs/Struct';
|
|
10
|
+
export { readJettonMetadata } from './wrappers/ContentUtils';
|
|
11
|
+
export { HighloadWalletV3 } from './wrappers/HighloadWalletV3';
|
|
7
12
|
export type { JettonWalletData } from './wrappers/JettonWallet';
|
|
8
13
|
export { JettonWallet, JettonWalletOpCodes } from './wrappers/JettonWallet';
|
|
9
|
-
export { HighloadWalletV3 } from './wrappers/HighloadWalletV3';
|
|
10
|
-
export { orbsOpener, liteClientOpener } from './adapters/contractOpener';
|
|
11
|
-
export * from './errors';
|
|
12
|
-
export { readJettonMetadata } from './wrappers/ContentUtils';
|
|
13
|
-
export { LiteSequencerClient } from './sdk/LiteSequencerClient';
|
package/dist/index.js
CHANGED
|
@@ -14,29 +14,29 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
18
|
-
var
|
|
19
|
-
Object.defineProperty(exports, "
|
|
17
|
+
exports.JettonWalletOpCodes = exports.JettonWallet = exports.HighloadWalletV3 = exports.readJettonMetadata = exports.SimplifiedStatuses = exports.Network = exports.TacSdk = exports.startTrackingMultiple = exports.startTracking = exports.OperationTracker = exports.LiteSequencerClient = exports.orbsOpener = exports.liteClientOpener = void 0;
|
|
18
|
+
var contractOpener_1 = require("./adapters/contractOpener");
|
|
19
|
+
Object.defineProperty(exports, "liteClientOpener", { enumerable: true, get: function () { return contractOpener_1.liteClientOpener; } });
|
|
20
|
+
Object.defineProperty(exports, "orbsOpener", { enumerable: true, get: function () { return contractOpener_1.orbsOpener; } });
|
|
21
|
+
__exportStar(require("./errors"), exports);
|
|
22
|
+
var LiteSequencerClient_1 = require("./sdk/LiteSequencerClient");
|
|
23
|
+
Object.defineProperty(exports, "LiteSequencerClient", { enumerable: true, get: function () { return LiteSequencerClient_1.LiteSequencerClient; } });
|
|
20
24
|
var OperationTracker_1 = require("./sdk/OperationTracker");
|
|
21
25
|
Object.defineProperty(exports, "OperationTracker", { enumerable: true, get: function () { return OperationTracker_1.OperationTracker; } });
|
|
22
26
|
var StartTracking_1 = require("./sdk/StartTracking");
|
|
23
27
|
Object.defineProperty(exports, "startTracking", { enumerable: true, get: function () { return StartTracking_1.startTracking; } });
|
|
24
28
|
Object.defineProperty(exports, "startTrackingMultiple", { enumerable: true, get: function () { return StartTracking_1.startTrackingMultiple; } });
|
|
29
|
+
var TacSdk_1 = require("./sdk/TacSdk");
|
|
30
|
+
Object.defineProperty(exports, "TacSdk", { enumerable: true, get: function () { return TacSdk_1.TacSdk; } });
|
|
25
31
|
__exportStar(require("./sender"), exports);
|
|
26
32
|
__exportStar(require("./structs/Struct"), exports);
|
|
27
33
|
var Struct_1 = require("./structs/Struct");
|
|
28
34
|
Object.defineProperty(exports, "Network", { enumerable: true, get: function () { return Struct_1.Network; } });
|
|
29
35
|
Object.defineProperty(exports, "SimplifiedStatuses", { enumerable: true, get: function () { return Struct_1.SimplifiedStatuses; } });
|
|
36
|
+
var ContentUtils_1 = require("./wrappers/ContentUtils");
|
|
37
|
+
Object.defineProperty(exports, "readJettonMetadata", { enumerable: true, get: function () { return ContentUtils_1.readJettonMetadata; } });
|
|
38
|
+
var HighloadWalletV3_1 = require("./wrappers/HighloadWalletV3");
|
|
39
|
+
Object.defineProperty(exports, "HighloadWalletV3", { enumerable: true, get: function () { return HighloadWalletV3_1.HighloadWalletV3; } });
|
|
30
40
|
var JettonWallet_1 = require("./wrappers/JettonWallet");
|
|
31
41
|
Object.defineProperty(exports, "JettonWallet", { enumerable: true, get: function () { return JettonWallet_1.JettonWallet; } });
|
|
32
42
|
Object.defineProperty(exports, "JettonWalletOpCodes", { enumerable: true, get: function () { return JettonWallet_1.JettonWalletOpCodes; } });
|
|
33
|
-
var HighloadWalletV3_1 = require("./wrappers/HighloadWalletV3");
|
|
34
|
-
Object.defineProperty(exports, "HighloadWalletV3", { enumerable: true, get: function () { return HighloadWalletV3_1.HighloadWalletV3; } });
|
|
35
|
-
var contractOpener_1 = require("./adapters/contractOpener");
|
|
36
|
-
Object.defineProperty(exports, "orbsOpener", { enumerable: true, get: function () { return contractOpener_1.orbsOpener; } });
|
|
37
|
-
Object.defineProperty(exports, "liteClientOpener", { enumerable: true, get: function () { return contractOpener_1.liteClientOpener; } });
|
|
38
|
-
__exportStar(require("./errors"), exports);
|
|
39
|
-
var ContentUtils_1 = require("./wrappers/ContentUtils");
|
|
40
|
-
Object.defineProperty(exports, "readJettonMetadata", { enumerable: true, get: function () { return ContentUtils_1.readJettonMetadata; } });
|
|
41
|
-
var LiteSequencerClient_1 = require("./sdk/LiteSequencerClient");
|
|
42
|
-
Object.defineProperty(exports, "LiteSequencerClient", { enumerable: true, get: function () { return LiteSequencerClient_1.LiteSequencerClient; } });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExecutionStagesByOperationId, OperationIdsByShardsKey, OperationType, StatusInfosByOperationId, TransactionLinker } from '../structs/Struct';
|
|
2
2
|
export declare class LiteSequencerClient {
|
|
3
3
|
private readonly endpoint;
|
|
4
4
|
private readonly maxChunkSize;
|
|
@@ -22,8 +22,7 @@ class LiteSequencerClient {
|
|
|
22
22
|
return response.data.response || '';
|
|
23
23
|
}
|
|
24
24
|
catch (error) {
|
|
25
|
-
|
|
26
|
-
throw errors_1.operationFetchError;
|
|
25
|
+
throw (0, errors_1.operationFetchError)(`endpoint ${this.endpoint} failed to complete request`, error);
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
28
|
async getOperationId(transactionLinker) {
|
|
@@ -40,12 +39,10 @@ class LiteSequencerClient {
|
|
|
40
39
|
catch (error) {
|
|
41
40
|
if (axios_1.default.isAxiosError(error)) {
|
|
42
41
|
if (error.response?.status === 404) {
|
|
43
|
-
console.warn(`404 Not Found: ${new URL('ton/operation-id', this.endpoint).toString()}`);
|
|
44
42
|
return '';
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
|
-
|
|
48
|
-
throw errors_1.operationFetchError;
|
|
45
|
+
throw (0, errors_1.operationFetchError)(`endpoint ${this.endpoint} failed to complete request`, error);
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
48
|
async getOperationIdsByShardsKeys(shardsKeys, caller, chunkSize = this.maxChunkSize) {
|
|
@@ -63,8 +60,7 @@ class LiteSequencerClient {
|
|
|
63
60
|
return response.response;
|
|
64
61
|
}
|
|
65
62
|
catch (error) {
|
|
66
|
-
|
|
67
|
-
throw errors_1.operationFetchError;
|
|
63
|
+
throw (0, errors_1.operationFetchError)(`endpoint ${this.endpoint} failed to complete request`, error);
|
|
68
64
|
}
|
|
69
65
|
}
|
|
70
66
|
async getStageProfilings(operationIds, chunkSize = this.maxChunkSize) {
|
|
@@ -83,8 +79,7 @@ class LiteSequencerClient {
|
|
|
83
79
|
return response.response;
|
|
84
80
|
}
|
|
85
81
|
catch (error) {
|
|
86
|
-
|
|
87
|
-
throw (0, errors_1.profilingFetchError)('endpoint failed to complete request');
|
|
82
|
+
throw (0, errors_1.profilingFetchError)(`endpoint ${this.endpoint} failed to complete request`, error);
|
|
88
83
|
}
|
|
89
84
|
}
|
|
90
85
|
async getOperationStatuses(operationIds, chunkSize = this.maxChunkSize) {
|
|
@@ -103,8 +98,7 @@ class LiteSequencerClient {
|
|
|
103
98
|
return response.response;
|
|
104
99
|
}
|
|
105
100
|
catch (error) {
|
|
106
|
-
|
|
107
|
-
throw (0, errors_1.statusFetchError)('endpoint failed to complete request');
|
|
101
|
+
throw (0, errors_1.statusFetchError)(`endpoint ${this.endpoint} failed to complete request`, error);
|
|
108
102
|
}
|
|
109
103
|
}
|
|
110
104
|
async processChunkedRequest(identificators, requestFn, chunkSize = this.maxChunkSize) {
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExecutionStages, ExecutionStagesByOperationId, Network, OperationIdsByShardsKey, OperationType, SimplifiedStatuses, StatusInfo, StatusInfosByOperationId, TransactionLinker, WaitOptions } from '../structs/Struct';
|
|
2
2
|
export declare class OperationTracker {
|
|
3
3
|
private readonly clients;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
private readonly debug;
|
|
5
|
+
constructor(network: Network, customLiteSequencerEndpoints?: string[], debug?: boolean);
|
|
6
|
+
private debugLog;
|
|
7
|
+
getOperationType(operationId: string, waitOptions?: WaitOptions<OperationType>): Promise<OperationType>;
|
|
8
|
+
getOperationId(transactionLinker: TransactionLinker, waitOptions?: WaitOptions<string>): Promise<string>;
|
|
9
|
+
getOperationIdsByShardsKeys(shardsKeys: string[], caller: string, waitOptions?: WaitOptions<OperationIdsByShardsKey>, chunkSize?: number): Promise<OperationIdsByShardsKey>;
|
|
10
|
+
getStageProfiling(operationId: string, waitOptions?: WaitOptions<ExecutionStages>): Promise<ExecutionStages>;
|
|
11
|
+
getStageProfilings(operationIds: string[], waitOptions?: WaitOptions<ExecutionStagesByOperationId>, chunkSize?: number): Promise<ExecutionStagesByOperationId>;
|
|
12
|
+
getOperationStatuses(operationIds: string[], waitOptions?: WaitOptions<StatusInfosByOperationId>, chunkSize?: number): Promise<StatusInfosByOperationId>;
|
|
13
|
+
getOperationStatus(operationId: string, waitOptions?: WaitOptions<StatusInfo>): Promise<StatusInfo>;
|
|
12
14
|
getSimplifiedOperationStatus(transactionLinker: TransactionLinker): Promise<SimplifiedStatuses>;
|
|
13
15
|
}
|
|
@@ -1,110 +1,188 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OperationTracker = void 0;
|
|
4
|
-
const Struct_1 = require("../structs/Struct");
|
|
5
4
|
const artifacts_1 = require("@tonappchain/artifacts");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const Struct_1 = require("../structs/Struct");
|
|
6
7
|
const LiteSequencerClient_1 = require("./LiteSequencerClient");
|
|
8
|
+
const Utils_1 = require("./Utils");
|
|
7
9
|
class OperationTracker {
|
|
8
|
-
constructor(network, customLiteSequencerEndpoints) {
|
|
10
|
+
constructor(network, customLiteSequencerEndpoints, debug = false) {
|
|
9
11
|
const endpoints = customLiteSequencerEndpoints ??
|
|
10
12
|
(network === Struct_1.Network.TESTNET
|
|
11
13
|
? artifacts_1.testnet.PUBLIC_LITE_SEQUENCER_ENDPOINTS
|
|
12
14
|
: artifacts_1.mainnet.PUBLIC_LITE_SEQUENCER_ENDPOINTS);
|
|
13
15
|
this.clients = endpoints.map((endpoint) => new LiteSequencerClient_1.LiteSequencerClient(endpoint));
|
|
16
|
+
this.debug = debug;
|
|
14
17
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return await client.getOperationType(operationId);
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
console.error('Failed to get operationType:', error);
|
|
22
|
-
}
|
|
18
|
+
debugLog(message) {
|
|
19
|
+
if (this.debug) {
|
|
20
|
+
console.log(`[OperationTracker Debug] ${message}`);
|
|
23
21
|
}
|
|
24
|
-
throw new Error('All endpoints failed to get operation type');
|
|
25
22
|
}
|
|
26
|
-
async
|
|
27
|
-
for (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
async getOperationType(operationId, waitOptions) {
|
|
24
|
+
this.debugLog(`Getting operation type for ${(0, Utils_1.formatObjectForLogging)(operationId)}`);
|
|
25
|
+
const requestFn = async () => {
|
|
26
|
+
let lastError;
|
|
27
|
+
for (const client of this.clients) {
|
|
28
|
+
try {
|
|
29
|
+
const type = await client.getOperationType(operationId);
|
|
30
|
+
this.debugLog(`Operation retrieved successfully`);
|
|
31
|
+
return type;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
this.debugLog(`Failed to get operationType using one of the endpoints`);
|
|
35
|
+
lastError = error;
|
|
36
|
+
}
|
|
33
37
|
}
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
this.debugLog('All endpoints failed to get operation type');
|
|
39
|
+
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
40
|
+
};
|
|
41
|
+
return waitOptions ? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn) : await requestFn();
|
|
36
42
|
}
|
|
37
|
-
async
|
|
38
|
-
for
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
async getOperationId(transactionLinker, waitOptions) {
|
|
44
|
+
this.debugLog(`Getting operation ID for transaction linker: ${(0, Utils_1.formatObjectForLogging)(transactionLinker)}`);
|
|
45
|
+
const requestFn = async () => {
|
|
46
|
+
let lastError;
|
|
47
|
+
for (const client of this.clients) {
|
|
48
|
+
try {
|
|
49
|
+
const id = await client.getOperationId(transactionLinker);
|
|
50
|
+
this.debugLog(`Operation ID ${id == '' ? 'does not exist' : 'retrieved successfully'}`);
|
|
51
|
+
return id;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
this.debugLog(`Failed to get OperationId using one of the endpoints`);
|
|
55
|
+
lastError = error;
|
|
56
|
+
}
|
|
44
57
|
}
|
|
45
|
-
|
|
46
|
-
|
|
58
|
+
this.debugLog('All endpoints failed to get operation id');
|
|
59
|
+
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
60
|
+
};
|
|
61
|
+
return waitOptions ? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn) : await requestFn();
|
|
47
62
|
}
|
|
48
|
-
async
|
|
49
|
-
for
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
63
|
+
async getOperationIdsByShardsKeys(shardsKeys, caller, waitOptions, chunkSize = 100) {
|
|
64
|
+
this.debugLog(`Getting operation IDs for shards keys: ${(0, Utils_1.formatObjectForLogging)(shardsKeys)}`);
|
|
65
|
+
this.debugLog(`Caller: ${caller}, Chunk size: ${chunkSize}`);
|
|
66
|
+
const requestFn = async () => {
|
|
67
|
+
let lastError;
|
|
68
|
+
for (const client of this.clients) {
|
|
69
|
+
try {
|
|
70
|
+
const result = await client.getOperationIdsByShardsKeys(shardsKeys, caller, chunkSize);
|
|
71
|
+
this.debugLog(`Operation IDs by shards keys retrieved successfully`);
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
this.debugLog(`Failed to get OperationIds using one of the endpoints`);
|
|
76
|
+
lastError = error;
|
|
55
77
|
}
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
console.error('Failed to get stage profiling:', error);
|
|
60
78
|
}
|
|
61
|
-
|
|
62
|
-
|
|
79
|
+
this.debugLog('All endpoints failed to get operation ids by shards keys');
|
|
80
|
+
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
81
|
+
};
|
|
82
|
+
return waitOptions ? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn) : await requestFn();
|
|
63
83
|
}
|
|
64
|
-
async
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
84
|
+
async getStageProfiling(operationId, waitOptions) {
|
|
85
|
+
this.debugLog(`Getting stage profiling for operation ${operationId}`);
|
|
86
|
+
const requestFn = async () => {
|
|
87
|
+
let lastError;
|
|
88
|
+
for (const client of this.clients) {
|
|
89
|
+
try {
|
|
90
|
+
const map = await client.getStageProfilings([operationId]);
|
|
91
|
+
const result = map[operationId];
|
|
92
|
+
if (!result) {
|
|
93
|
+
this.debugLog(`No stageProfiling data for operationId=${operationId}`);
|
|
94
|
+
throw new Error(`No stageProfiling data for operationId=${operationId}`);
|
|
95
|
+
}
|
|
96
|
+
this.debugLog(`Stage profiling retrieved successfully`);
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
this.debugLog(`Failed to get stage profiling using one of the endpoints`);
|
|
101
|
+
lastError = error;
|
|
102
|
+
}
|
|
71
103
|
}
|
|
72
|
-
|
|
73
|
-
|
|
104
|
+
this.debugLog('All endpoints failed to get stage profiling');
|
|
105
|
+
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
106
|
+
};
|
|
107
|
+
return waitOptions ? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn) : await requestFn();
|
|
74
108
|
}
|
|
75
|
-
async
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
109
|
+
async getStageProfilings(operationIds, waitOptions, chunkSize = 100) {
|
|
110
|
+
this.debugLog(`Getting stage profilings for operations: ${operationIds.join(', ')}`);
|
|
111
|
+
this.debugLog(`Chunk size: ${chunkSize}`);
|
|
112
|
+
const requestFn = async () => {
|
|
113
|
+
let lastError;
|
|
114
|
+
for (const client of this.clients) {
|
|
115
|
+
try {
|
|
116
|
+
const result = await client.getStageProfilings(operationIds, chunkSize);
|
|
117
|
+
this.debugLog(`Stage profilings retrieved successfully`);
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
this.debugLog(`Failed to get stage profilings using one of the endpoints`);
|
|
122
|
+
lastError = error;
|
|
123
|
+
}
|
|
82
124
|
}
|
|
83
|
-
|
|
84
|
-
|
|
125
|
+
this.debugLog('All endpoints failed to get stage profilings');
|
|
126
|
+
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
127
|
+
};
|
|
128
|
+
return waitOptions ? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn) : await requestFn();
|
|
85
129
|
}
|
|
86
|
-
async
|
|
87
|
-
for (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
130
|
+
async getOperationStatuses(operationIds, waitOptions, chunkSize = 100) {
|
|
131
|
+
this.debugLog(`Getting operation statuses for operations: ${(0, Utils_1.formatObjectForLogging)(operationIds)}`);
|
|
132
|
+
this.debugLog(`Chunk size: ${chunkSize}`);
|
|
133
|
+
const requestFn = async () => {
|
|
134
|
+
let lastError;
|
|
135
|
+
for (const client of this.clients) {
|
|
136
|
+
try {
|
|
137
|
+
const result = await client.getOperationStatuses(operationIds, chunkSize);
|
|
138
|
+
this.debugLog(`Operation statuses retrieved successfully`);
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
this.debugLog(`Failed to get operation statuses using one of the endpoints`);
|
|
143
|
+
lastError = error;
|
|
93
144
|
}
|
|
94
|
-
return result;
|
|
95
145
|
}
|
|
96
|
-
|
|
97
|
-
|
|
146
|
+
this.debugLog('All endpoints failed to get operation statuses');
|
|
147
|
+
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
148
|
+
};
|
|
149
|
+
return waitOptions ? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn) : await requestFn();
|
|
150
|
+
}
|
|
151
|
+
async getOperationStatus(operationId, waitOptions) {
|
|
152
|
+
this.debugLog(`Getting operation status for ${(0, Utils_1.formatObjectForLogging)(operationId)}`);
|
|
153
|
+
const requestFn = async () => {
|
|
154
|
+
let lastError;
|
|
155
|
+
for (const client of this.clients) {
|
|
156
|
+
try {
|
|
157
|
+
const map = await client.getOperationStatuses([operationId]);
|
|
158
|
+
const result = map[operationId];
|
|
159
|
+
if (!result) {
|
|
160
|
+
this.debugLog(`No operation status for operationId=${operationId}`);
|
|
161
|
+
throw new Error(`No operation status for operationId=${operationId}`);
|
|
162
|
+
}
|
|
163
|
+
this.debugLog(`Operation status retrieved successfully`);
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
this.debugLog(`Failed to get operation status using one of the endpoints`);
|
|
168
|
+
lastError = error;
|
|
169
|
+
}
|
|
98
170
|
}
|
|
99
|
-
|
|
100
|
-
|
|
171
|
+
this.debugLog('All endpoints failed to get operation status');
|
|
172
|
+
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
173
|
+
};
|
|
174
|
+
return waitOptions ? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn) : await requestFn();
|
|
101
175
|
}
|
|
102
176
|
async getSimplifiedOperationStatus(transactionLinker) {
|
|
177
|
+
this.debugLog(`Getting simplified operation status for transaction linker: ${(0, Utils_1.formatObjectForLogging)(transactionLinker)}`);
|
|
103
178
|
const operationId = await this.getOperationId(transactionLinker);
|
|
104
179
|
if (operationId == '') {
|
|
180
|
+
this.debugLog('Operation ID not found');
|
|
105
181
|
return Struct_1.SimplifiedStatuses.OPERATION_ID_NOT_FOUND;
|
|
106
182
|
}
|
|
183
|
+
this.debugLog(`Operation ID: ${operationId}`);
|
|
107
184
|
const operationType = await this.getOperationType(operationId);
|
|
185
|
+
this.debugLog(`Operation type: ${operationType}`);
|
|
108
186
|
if (operationType == Struct_1.OperationType.PENDING || operationType == Struct_1.OperationType.UNKNOWN) {
|
|
109
187
|
return Struct_1.SimplifiedStatuses.PENDING;
|
|
110
188
|
}
|