@tonappchain/sdk 0.7.2-alpha-11 → 0.7.2-alpha-13
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/artifacts/dev/ton/internal/build/CrossChainLayer.compiled.json +1 -1
- package/dist/src/adapters/BaseContractOpener.d.ts +71 -0
- package/dist/src/adapters/BaseContractOpener.js +290 -0
- package/dist/src/adapters/LiteClientOpener.d.ts +33 -0
- package/dist/src/adapters/LiteClientOpener.js +117 -0
- package/dist/src/adapters/OpenerUtils.d.ts +3 -0
- package/dist/src/adapters/OpenerUtils.js +39 -0
- package/dist/src/adapters/RetryableContractOpener.d.ts +35 -0
- package/dist/src/adapters/{retryableContractOpener.js → RetryableContractOpener.js} +60 -12
- package/dist/src/adapters/SandboxOpener.d.ts +15 -0
- package/dist/src/adapters/SandboxOpener.js +35 -0
- package/dist/src/adapters/TonClient4Opener.d.ts +21 -0
- package/dist/src/adapters/TonClient4Opener.js +86 -0
- package/dist/src/adapters/TonClientOpener.d.ts +16 -0
- package/dist/src/adapters/TonClientOpener.js +70 -0
- package/dist/src/adapters/index.d.ts +7 -2
- package/dist/src/adapters/index.js +7 -2
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +3 -2
- package/dist/src/interfaces/ContractOpener.d.ts +69 -2
- package/dist/src/interfaces/ITacSDK.d.ts +5 -0
- package/dist/src/sdk/Configuration.js +1 -1
- package/dist/src/sdk/Consts.d.ts +5 -2
- package/dist/src/sdk/Consts.js +8 -4
- package/dist/src/sdk/StartTracking.d.ts +3 -4
- package/dist/src/sdk/StartTracking.js +7 -7
- package/dist/src/sdk/TONTransactionManager.d.ts +1 -3
- package/dist/src/sdk/TONTransactionManager.js +2 -3
- package/dist/src/sdk/TacSdk.d.ts +3 -1
- package/dist/src/sdk/TacSdk.js +5 -3
- package/dist/src/sdk/TxFinalizer.d.ts +1 -8
- package/dist/src/sdk/TxFinalizer.js +10 -122
- package/dist/src/sdk/Utils.d.ts +5 -0
- package/dist/src/sdk/Utils.js +24 -0
- package/dist/src/structs/InternalStruct.d.ts +1 -16
- package/dist/src/structs/Struct.d.ts +90 -5
- package/package.json +1 -1
- package/dist/src/adapters/contractOpener.d.ts +0 -24
- package/dist/src/adapters/contractOpener.js +0 -310
- package/dist/src/adapters/retryableContractOpener.d.ts +0 -29
|
@@ -4,15 +4,25 @@ exports.RetryableContractOpener = void 0;
|
|
|
4
4
|
exports.createDefaultRetryableOpener = createDefaultRetryableOpener;
|
|
5
5
|
const ton_1 = require("@ton/ton");
|
|
6
6
|
const instances_1 = require("../errors/instances");
|
|
7
|
+
const Consts_1 = require("../sdk/Consts");
|
|
7
8
|
const Struct_1 = require("../structs/Struct");
|
|
8
|
-
const
|
|
9
|
+
const TonClient4Opener_1 = require("./TonClient4Opener");
|
|
10
|
+
const TonClientOpener_1 = require("./TonClientOpener");
|
|
9
11
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
10
12
|
class RetryableContractOpener {
|
|
11
|
-
constructor(openerConfigs) {
|
|
13
|
+
constructor(openerConfigs, logger) {
|
|
12
14
|
if (openerConfigs.length === 0) {
|
|
13
15
|
throw new Error('No ContractOpener instances available');
|
|
14
16
|
}
|
|
15
17
|
this.openerConfigs = openerConfigs;
|
|
18
|
+
this.logger = logger;
|
|
19
|
+
}
|
|
20
|
+
async getTransactions(address, opts) {
|
|
21
|
+
const result = await this.executeWithFallback((config) => config.opener.getTransactions(address, opts));
|
|
22
|
+
if (result.success && result.data) {
|
|
23
|
+
return result.data;
|
|
24
|
+
}
|
|
25
|
+
throw result.lastError || (0, instances_1.allContractOpenerFailedError)('Failed to get transactions');
|
|
16
26
|
}
|
|
17
27
|
async getTransactionByHash(address, hash, opts) {
|
|
18
28
|
const result = await this.executeWithFallback((config) => config.opener.getTransactionByHash(address, hash, opts));
|
|
@@ -21,12 +31,12 @@ class RetryableContractOpener {
|
|
|
21
31
|
}
|
|
22
32
|
throw result.lastError || (0, instances_1.allContractOpenerFailedError)('Failed to get transaction by hash');
|
|
23
33
|
}
|
|
24
|
-
async getAdjacentTransactions(address, hash) {
|
|
25
|
-
const result = await this.executeWithFallback((config) => config.opener.getAdjacentTransactions(address, hash));
|
|
34
|
+
async getAdjacentTransactions(address, hash, opts) {
|
|
35
|
+
const result = await this.executeWithFallback((config) => config.opener.getAdjacentTransactions(address, hash, opts));
|
|
26
36
|
if (result.success && result.data) {
|
|
27
37
|
return result.data;
|
|
28
38
|
}
|
|
29
|
-
throw result.lastError || (0, instances_1.allContractOpenerFailedError)('Failed to get
|
|
39
|
+
throw result.lastError || (0, instances_1.allContractOpenerFailedError)('Failed to get adjacent transactions');
|
|
30
40
|
}
|
|
31
41
|
open(src) {
|
|
32
42
|
const firstConfig = this.openerConfigs[0];
|
|
@@ -54,11 +64,49 @@ class RetryableContractOpener {
|
|
|
54
64
|
}
|
|
55
65
|
throw result.lastError || (0, instances_1.allContractOpenerFailedError)('Failed to get blockchain config');
|
|
56
66
|
}
|
|
67
|
+
async getTransactionByTxHash(address, txHash, opts) {
|
|
68
|
+
const result = await this.executeWithFallback((config) => config.opener.getTransactionByTxHash(address, txHash, opts));
|
|
69
|
+
if (result.success) {
|
|
70
|
+
return result.data ?? null;
|
|
71
|
+
}
|
|
72
|
+
throw result.lastError || (0, instances_1.allContractOpenerFailedError)('Failed to get transaction by transaction hash');
|
|
73
|
+
}
|
|
74
|
+
async getTransactionByInMsgHash(address, msgHash, opts) {
|
|
75
|
+
const result = await this.executeWithFallback((config) => config.opener.getTransactionByInMsgHash(address, msgHash, opts));
|
|
76
|
+
if (result.success) {
|
|
77
|
+
return result.data ?? null;
|
|
78
|
+
}
|
|
79
|
+
throw result.lastError || (0, instances_1.allContractOpenerFailedError)('Failed to get transaction by message hash');
|
|
80
|
+
}
|
|
81
|
+
async getTransactionByOutMsgHash(address, msgHash, opts) {
|
|
82
|
+
const result = await this.executeWithFallback((config) => config.opener.getTransactionByOutMsgHash(address, msgHash, opts));
|
|
83
|
+
if (result.success) {
|
|
84
|
+
return result.data ?? null;
|
|
85
|
+
}
|
|
86
|
+
throw result.lastError || (0, instances_1.allContractOpenerFailedError)('Failed to get transaction by outgoing message hash');
|
|
87
|
+
}
|
|
57
88
|
closeConnections() {
|
|
58
89
|
for (const config of this.openerConfigs) {
|
|
59
90
|
config.opener.closeConnections?.();
|
|
60
91
|
}
|
|
61
92
|
}
|
|
93
|
+
async trackTransactionTree(address, hash, params) {
|
|
94
|
+
const result = await this.executeWithFallback(async (config) => {
|
|
95
|
+
return config.opener.trackTransactionTree(address, hash, params);
|
|
96
|
+
});
|
|
97
|
+
if (!result.success) {
|
|
98
|
+
throw result.lastError || (0, instances_1.allContractOpenerFailedError)('Failed to track transaction tree');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async trackTransactionTreeWithResult(address, hash, params) {
|
|
102
|
+
const result = await this.executeWithFallback(async (config) => {
|
|
103
|
+
return config.opener.trackTransactionTreeWithResult(address, hash, params);
|
|
104
|
+
});
|
|
105
|
+
if (!result.success) {
|
|
106
|
+
throw result.lastError || (0, instances_1.allContractOpenerFailedError)('Failed to track transaction tree with result');
|
|
107
|
+
}
|
|
108
|
+
return result.data;
|
|
109
|
+
}
|
|
62
110
|
async executeWithFallback(operation) {
|
|
63
111
|
let lastError;
|
|
64
112
|
for (const config of this.openerConfigs) {
|
|
@@ -113,26 +161,26 @@ class RetryableContractOpener {
|
|
|
113
161
|
}
|
|
114
162
|
}
|
|
115
163
|
exports.RetryableContractOpener = RetryableContractOpener;
|
|
116
|
-
async function createDefaultRetryableOpener(tonRpcEndpoint, networkType, maxRetries =
|
|
164
|
+
async function createDefaultRetryableOpener(tonRpcEndpoint, networkType, maxRetries = Consts_1.DEFAULT_RETRY_MAX_COUNT, retryDelay = Consts_1.DEFAULT_RETRY_DELAY_MS, logger) {
|
|
117
165
|
const openers = [];
|
|
118
166
|
const tonClient = new ton_1.TonClient({ endpoint: new URL('api/v2/jsonRPC', tonRpcEndpoint).toString() });
|
|
119
|
-
const opener = (0,
|
|
167
|
+
const opener = (0, TonClientOpener_1.tonClientOpener)(tonClient);
|
|
120
168
|
openers.push({ opener, retries: maxRetries, retryDelay });
|
|
121
169
|
if (networkType !== Struct_1.Network.DEV) {
|
|
122
170
|
try {
|
|
123
|
-
const
|
|
124
|
-
openers.push({ opener:
|
|
171
|
+
const opener = await (0, TonClientOpener_1.orbsOpener)(networkType);
|
|
172
|
+
openers.push({ opener: opener, retries: maxRetries, retryDelay });
|
|
125
173
|
}
|
|
126
174
|
catch {
|
|
127
175
|
// skip opener in case of failure
|
|
128
176
|
}
|
|
129
177
|
try {
|
|
130
|
-
const
|
|
131
|
-
openers.push({ opener:
|
|
178
|
+
const opener4 = await (0, TonClient4Opener_1.orbsOpener4)(networkType);
|
|
179
|
+
openers.push({ opener: opener4, retries: maxRetries, retryDelay });
|
|
132
180
|
}
|
|
133
181
|
catch {
|
|
134
182
|
// skip opener in case of failure
|
|
135
183
|
}
|
|
136
184
|
}
|
|
137
|
-
return new RetryableContractOpener(openers);
|
|
185
|
+
return new RetryableContractOpener(openers, logger);
|
|
138
186
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Blockchain, SandboxContract } from '@ton/sandbox';
|
|
2
|
+
import { Address, Contract, Transaction } from '@ton/ton';
|
|
3
|
+
import { ContractOpener } from '../interfaces';
|
|
4
|
+
import { AddressInformation, ContractState } from '../structs/Struct';
|
|
5
|
+
import { BaseContractOpener } from './BaseContractOpener';
|
|
6
|
+
export declare class SandboxOpener extends BaseContractOpener {
|
|
7
|
+
private readonly blockchain;
|
|
8
|
+
constructor(blockchain: Blockchain);
|
|
9
|
+
open<T extends Contract>(contract: T): SandboxContract<T>;
|
|
10
|
+
getContractState(address: Address): Promise<ContractState>;
|
|
11
|
+
getTransactions(): Promise<Transaction[]>;
|
|
12
|
+
getAddressInformation(): Promise<AddressInformation>;
|
|
13
|
+
getConfig(): Promise<string>;
|
|
14
|
+
}
|
|
15
|
+
export declare function sandboxOpener(blockchain: Blockchain): ContractOpener;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SandboxOpener = void 0;
|
|
4
|
+
exports.sandboxOpener = sandboxOpener;
|
|
5
|
+
const BaseContractOpener_1 = require("./BaseContractOpener");
|
|
6
|
+
class SandboxOpener extends BaseContractOpener_1.BaseContractOpener {
|
|
7
|
+
constructor(blockchain) {
|
|
8
|
+
super();
|
|
9
|
+
this.blockchain = blockchain;
|
|
10
|
+
}
|
|
11
|
+
open(contract) {
|
|
12
|
+
return this.blockchain.openContract(contract);
|
|
13
|
+
}
|
|
14
|
+
async getContractState(address) {
|
|
15
|
+
const state = await this.blockchain.provider(address).getState();
|
|
16
|
+
return {
|
|
17
|
+
balance: state.balance,
|
|
18
|
+
code: 'code' in state.state ? (state.state.code ?? null) : null,
|
|
19
|
+
state: state.state.type === 'uninit' ? 'uninitialized' : state.state.type,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
async getTransactions() {
|
|
23
|
+
throw new Error('getTransactions not implemented for sandboxOpener');
|
|
24
|
+
}
|
|
25
|
+
async getAddressInformation() {
|
|
26
|
+
throw new Error('getAddressInformation not implemented for sandboxOpener');
|
|
27
|
+
}
|
|
28
|
+
async getConfig() {
|
|
29
|
+
return this.blockchain.config.toBoc().toString('base64');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.SandboxOpener = SandboxOpener;
|
|
33
|
+
function sandboxOpener(blockchain) {
|
|
34
|
+
return new SandboxOpener(blockchain);
|
|
35
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Address, Contract, OpenedContract, TonClient4, Transaction } from '@ton/ton';
|
|
2
|
+
import { AddressInformation, ContractState, GetTransactionsOptions, Network } from '../structs/Struct';
|
|
3
|
+
import { BaseContractOpener } from './BaseContractOpener';
|
|
4
|
+
export declare class TonClient4Opener extends BaseContractOpener {
|
|
5
|
+
private readonly client4;
|
|
6
|
+
constructor(client4: TonClient4);
|
|
7
|
+
static create(endpoint: string, timeout?: number): TonClient4Opener;
|
|
8
|
+
open<T extends Contract>(contract: T): OpenedContract<T>;
|
|
9
|
+
getContractState(address: Address): Promise<ContractState>;
|
|
10
|
+
getTransactions(address: Address, opts: GetTransactionsOptions): Promise<Transaction[]>;
|
|
11
|
+
getAddressInformation(addr: Address): Promise<AddressInformation>;
|
|
12
|
+
getConfig(): Promise<string>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates a TonClient4Opener instance using TonHub public API
|
|
16
|
+
* @param network Network to connect to (mainnet or testnet)
|
|
17
|
+
* @param timeout Request timeout in milliseconds
|
|
18
|
+
*/
|
|
19
|
+
export declare function tonHubApi4Opener(network: Network, timeout?: number): TonClient4Opener;
|
|
20
|
+
export declare function tonClient4Opener(client: TonClient4): TonClient4Opener;
|
|
21
|
+
export declare function orbsOpener4(network: Network, timeout?: number): Promise<TonClient4Opener>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TonClient4Opener = void 0;
|
|
4
|
+
exports.tonHubApi4Opener = tonHubApi4Opener;
|
|
5
|
+
exports.tonClient4Opener = tonClient4Opener;
|
|
6
|
+
exports.orbsOpener4 = orbsOpener4;
|
|
7
|
+
const ton_1 = require("@ton/ton");
|
|
8
|
+
const Consts_1 = require("../sdk/Consts");
|
|
9
|
+
const Struct_1 = require("../structs/Struct");
|
|
10
|
+
const BaseContractOpener_1 = require("./BaseContractOpener");
|
|
11
|
+
const OpenerUtils_1 = require("./OpenerUtils");
|
|
12
|
+
class TonClient4Opener extends BaseContractOpener_1.BaseContractOpener {
|
|
13
|
+
constructor(client4) {
|
|
14
|
+
super();
|
|
15
|
+
this.client4 = client4;
|
|
16
|
+
}
|
|
17
|
+
static create(endpoint, timeout = 10000) {
|
|
18
|
+
const client4 = new ton_1.TonClient4({ endpoint, timeout });
|
|
19
|
+
return new TonClient4Opener(client4);
|
|
20
|
+
}
|
|
21
|
+
open(contract) {
|
|
22
|
+
return this.client4.open(contract);
|
|
23
|
+
}
|
|
24
|
+
async getContractState(address) {
|
|
25
|
+
const latestBlock = await this.client4.getLastBlock();
|
|
26
|
+
const latestBlockNumber = latestBlock.last.seqno;
|
|
27
|
+
const state = await this.client4.getAccount(latestBlockNumber, address);
|
|
28
|
+
return {
|
|
29
|
+
balance: BigInt(state.account.balance.coins),
|
|
30
|
+
code: 'code' in state.account.state && state.account.state.code !== null
|
|
31
|
+
? Buffer.from(state.account.state.code, 'base64')
|
|
32
|
+
: null,
|
|
33
|
+
state: state.account.state.type === 'uninit' ? 'uninitialized' : state.account.state.type,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async getTransactions(address, opts) {
|
|
37
|
+
const allTxs = await this.client4
|
|
38
|
+
.getAccountTransactions(address, opts.lt ? BigInt(opts.lt) : 0n, opts.hash ? Buffer.from(opts.hash, 'base64') : Buffer.alloc(0))
|
|
39
|
+
.then((res) => res.map((t) => t.tx));
|
|
40
|
+
// Apply limit if specified
|
|
41
|
+
let txs = opts.limit ? allTxs.slice(0, opts.limit) : allTxs;
|
|
42
|
+
// Apply to_lt filter if specified
|
|
43
|
+
if (opts.to_lt) {
|
|
44
|
+
const toLt = BigInt(opts.to_lt);
|
|
45
|
+
txs = txs.filter((tx) => {
|
|
46
|
+
const comparison = tx.lt > toLt;
|
|
47
|
+
return opts.inclusive ? tx.lt >= toLt : comparison;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return txs;
|
|
51
|
+
}
|
|
52
|
+
async getAddressInformation(addr) {
|
|
53
|
+
const latestBlock = await this.client4.getLastBlock();
|
|
54
|
+
const latestBlockNumber = latestBlock.last.seqno;
|
|
55
|
+
const state = await this.client4.getAccount(latestBlockNumber, addr);
|
|
56
|
+
return {
|
|
57
|
+
lastTransaction: {
|
|
58
|
+
lt: state.account.last?.lt ?? '',
|
|
59
|
+
hash: state.account.last?.hash ?? '',
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async getConfig() {
|
|
64
|
+
const block = await this.client4.getLastBlock();
|
|
65
|
+
const { config } = await this.client4.getConfig(block.last.seqno);
|
|
66
|
+
return config.cell;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.TonClient4Opener = TonClient4Opener;
|
|
70
|
+
/**
|
|
71
|
+
* Creates a TonClient4Opener instance using TonHub public API
|
|
72
|
+
* @param network Network to connect to (mainnet or testnet)
|
|
73
|
+
* @param timeout Request timeout in milliseconds
|
|
74
|
+
*/
|
|
75
|
+
function tonHubApi4Opener(network, timeout = Consts_1.DEFAULT_HTTP_CLIENT_TIMEOUT_MS) {
|
|
76
|
+
const endpoint = network === Struct_1.Network.MAINNET ? 'https://mainnet-v4.tonhubapi.com' : 'https://testnet-v4.tonhubapi.com';
|
|
77
|
+
return TonClient4Opener.create(endpoint, timeout);
|
|
78
|
+
}
|
|
79
|
+
function tonClient4Opener(client) {
|
|
80
|
+
return new TonClient4Opener(client);
|
|
81
|
+
}
|
|
82
|
+
async function orbsOpener4(network, timeout = Consts_1.DEFAULT_HTTP_CLIENT_TIMEOUT_MS) {
|
|
83
|
+
const endpoint = await (0, OpenerUtils_1.getHttpV4EndpointWithRetry)(network);
|
|
84
|
+
const client = new ton_1.TonClient4({ endpoint, timeout });
|
|
85
|
+
return new TonClient4Opener(client);
|
|
86
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Address, Contract, OpenedContract, TonClient, Transaction } from '@ton/ton';
|
|
2
|
+
import { AddressInformation, ContractState, GetTransactionsOptions, Network } from '../structs/Struct';
|
|
3
|
+
import { BaseContractOpener } from './BaseContractOpener';
|
|
4
|
+
export declare class TonClientOpener extends BaseContractOpener {
|
|
5
|
+
private readonly client;
|
|
6
|
+
private readonly httpClient;
|
|
7
|
+
constructor(client: TonClient);
|
|
8
|
+
static create(endpoint: string, timeout?: number): TonClientOpener;
|
|
9
|
+
open<T extends Contract>(contract: T): OpenedContract<T>;
|
|
10
|
+
getContractState(address: Address): Promise<ContractState>;
|
|
11
|
+
getTransactions(address: Address, opts: GetTransactionsOptions): Promise<Transaction[]>;
|
|
12
|
+
getAddressInformation(addr: Address): Promise<AddressInformation>;
|
|
13
|
+
getConfig(): Promise<string>;
|
|
14
|
+
}
|
|
15
|
+
export declare function tonClientOpener(client: TonClient): TonClientOpener;
|
|
16
|
+
export declare function orbsOpener(network: Network): Promise<TonClientOpener>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TonClientOpener = void 0;
|
|
4
|
+
exports.tonClientOpener = tonClientOpener;
|
|
5
|
+
exports.orbsOpener = orbsOpener;
|
|
6
|
+
const ton_1 = require("@ton/ton");
|
|
7
|
+
const AxiosHttpClient_1 = require("../sdk/AxiosHttpClient");
|
|
8
|
+
const Consts_1 = require("../sdk/Consts");
|
|
9
|
+
const BaseContractOpener_1 = require("./BaseContractOpener");
|
|
10
|
+
const OpenerUtils_1 = require("./OpenerUtils");
|
|
11
|
+
class TonClientOpener extends BaseContractOpener_1.BaseContractOpener {
|
|
12
|
+
constructor(client) {
|
|
13
|
+
super();
|
|
14
|
+
this.client = client;
|
|
15
|
+
this.httpClient = new AxiosHttpClient_1.AxiosHttpClient({ timeout: Consts_1.DEFAULT_HTTP_CLIENT_TIMEOUT_MS });
|
|
16
|
+
}
|
|
17
|
+
static create(endpoint, timeout = Consts_1.DEFAULT_HTTP_CLIENT_TIMEOUT_MS) {
|
|
18
|
+
const client = new ton_1.TonClient({ endpoint, timeout });
|
|
19
|
+
return new TonClientOpener(client);
|
|
20
|
+
}
|
|
21
|
+
open(contract) {
|
|
22
|
+
return this.client.open(contract);
|
|
23
|
+
}
|
|
24
|
+
async getContractState(address) {
|
|
25
|
+
return this.client.getContractState(address);
|
|
26
|
+
}
|
|
27
|
+
async getTransactions(address, opts) {
|
|
28
|
+
// TonClient doesn't accept timeoutMs and retryDelayMs, filter them out
|
|
29
|
+
const clientOpts = {
|
|
30
|
+
limit: opts.limit ?? Consts_1.DEFAULT_FIND_TX_LIMIT,
|
|
31
|
+
lt: opts.lt,
|
|
32
|
+
hash: opts.hash,
|
|
33
|
+
to_lt: opts.to_lt,
|
|
34
|
+
inclusive: opts.inclusive,
|
|
35
|
+
archival: opts.archival,
|
|
36
|
+
};
|
|
37
|
+
return this.client.getTransactions(address, clientOpts);
|
|
38
|
+
}
|
|
39
|
+
async getAddressInformation(addr) {
|
|
40
|
+
const state = await this.client.getContractState(addr);
|
|
41
|
+
return {
|
|
42
|
+
lastTransaction: {
|
|
43
|
+
lt: state.lastTransaction?.lt ?? '',
|
|
44
|
+
hash: state.lastTransaction?.hash ?? '',
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async getConfig() {
|
|
49
|
+
const info = await this.client.getMasterchainInfo();
|
|
50
|
+
const url = new URL('getConfigAll', this.client.parameters.endpoint);
|
|
51
|
+
url.searchParams.append('seqno', info.latestSeqno.toString());
|
|
52
|
+
// Use longer timeout for getConfig as the response is very large (~100KB+)
|
|
53
|
+
// and Brotli decompression can take significant time
|
|
54
|
+
const response = await this.httpClient.get(url.toString(), { timeout: 60000 });
|
|
55
|
+
const body = response.data;
|
|
56
|
+
if (!body?.ok || !body.result?.config?.bytes) {
|
|
57
|
+
throw new Error(`Failed to fetch config: ${JSON.stringify(body)}`);
|
|
58
|
+
}
|
|
59
|
+
return body.result.config.bytes;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.TonClientOpener = TonClientOpener;
|
|
63
|
+
function tonClientOpener(client) {
|
|
64
|
+
return new TonClientOpener(client);
|
|
65
|
+
}
|
|
66
|
+
async function orbsOpener(network) {
|
|
67
|
+
const endpoint = await (0, OpenerUtils_1.getHttpEndpointWithRetry)(network);
|
|
68
|
+
const client = new ton_1.TonClient({ endpoint });
|
|
69
|
+
return new TonClientOpener(client);
|
|
70
|
+
}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
1
|
+
export * from './BaseContractOpener';
|
|
2
|
+
export * from './LiteClientOpener';
|
|
3
|
+
export * from './OpenerUtils';
|
|
4
|
+
export * from './RetryableContractOpener';
|
|
5
|
+
export * from './SandboxOpener';
|
|
6
|
+
export * from './TonClient4Opener';
|
|
7
|
+
export * from './TonClientOpener';
|
|
@@ -14,5 +14,10 @@ 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
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./BaseContractOpener"), exports);
|
|
18
|
+
__exportStar(require("./LiteClientOpener"), exports);
|
|
19
|
+
__exportStar(require("./OpenerUtils"), exports);
|
|
20
|
+
__exportStar(require("./RetryableContractOpener"), exports);
|
|
21
|
+
__exportStar(require("./SandboxOpener"), exports);
|
|
22
|
+
__exportStar(require("./TonClient4Opener"), exports);
|
|
23
|
+
__exportStar(require("./TonClientOpener"), exports);
|
package/dist/src/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export { TacExplorerClient } from './sdk/TacExplorerClient';
|
|
|
15
15
|
export { TacSdk } from './sdk/TacSdk';
|
|
16
16
|
export { TACTransactionManager } from './sdk/TACTransactionManager';
|
|
17
17
|
export { TONTransactionManager } from './sdk/TONTransactionManager';
|
|
18
|
-
export
|
|
18
|
+
export { TonTxFinalizer } from './sdk/TxFinalizer';
|
|
19
19
|
export * from './sender';
|
|
20
20
|
export * from './structs/Struct';
|
|
21
21
|
export * from './wrappers/ContentUtils';
|
package/dist/src/index.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
36
36
|
};
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.TONTransactionManager = exports.TACTransactionManager = exports.TacSdk = exports.TacExplorerClient = exports.Simulator = exports.OperationTracker = exports.NoopLogger = exports.ConsoleLogger = exports.LiteSequencerClient = exports.Configuration = exports.AxiosHttpClient = exports.AgnosticStructs = exports.AgnosticProxySDK = void 0;
|
|
39
|
+
exports.TonTxFinalizer = exports.TONTransactionManager = exports.TACTransactionManager = exports.TacSdk = exports.TacExplorerClient = exports.Simulator = exports.OperationTracker = exports.NoopLogger = exports.ConsoleLogger = exports.LiteSequencerClient = exports.Configuration = exports.AxiosHttpClient = exports.AgnosticStructs = exports.AgnosticProxySDK = void 0;
|
|
40
40
|
__exportStar(require("./adapters"), exports);
|
|
41
41
|
var AgnosticSdk_1 = require("./agnosticSdk/AgnosticSdk");
|
|
42
42
|
Object.defineProperty(exports, "AgnosticProxySDK", { enumerable: true, get: function () { return AgnosticSdk_1.AgnosticProxySDK; } });
|
|
@@ -66,7 +66,8 @@ var TACTransactionManager_1 = require("./sdk/TACTransactionManager");
|
|
|
66
66
|
Object.defineProperty(exports, "TACTransactionManager", { enumerable: true, get: function () { return TACTransactionManager_1.TACTransactionManager; } });
|
|
67
67
|
var TONTransactionManager_1 = require("./sdk/TONTransactionManager");
|
|
68
68
|
Object.defineProperty(exports, "TONTransactionManager", { enumerable: true, get: function () { return TONTransactionManager_1.TONTransactionManager; } });
|
|
69
|
-
|
|
69
|
+
var TxFinalizer_1 = require("./sdk/TxFinalizer");
|
|
70
|
+
Object.defineProperty(exports, "TonTxFinalizer", { enumerable: true, get: function () { return TxFinalizer_1.TonTxFinalizer; } });
|
|
70
71
|
__exportStar(require("./sender"), exports);
|
|
71
72
|
__exportStar(require("./structs/Struct"), exports);
|
|
72
73
|
__exportStar(require("./wrappers/ContentUtils"), exports);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { SandboxContract } from '@ton/sandbox';
|
|
2
2
|
import type { Address, Contract, OpenedContract, Transaction } from '@ton/ton';
|
|
3
|
-
import { AddressInformation, GetTransactionsOptions } from '../structs/
|
|
4
|
-
import { ContractState } from '../structs/Struct';
|
|
3
|
+
import { AddressInformation, ContractState, GetTransactionsOptions, TrackTransactionTreeParams, TrackTransactionTreeResult } from '../structs/Struct';
|
|
5
4
|
export interface ContractOpener {
|
|
6
5
|
/**
|
|
7
6
|
* Opens a contract for interaction using the underlying client (lite client, sandbox, etc.).
|
|
@@ -19,8 +18,76 @@ export interface ContractOpener {
|
|
|
19
18
|
* Closes any underlying connections if supported by the implementation.
|
|
20
19
|
*/
|
|
21
20
|
closeConnections?: () => unknown;
|
|
21
|
+
/**
|
|
22
|
+
* Fetches transactions for a given address.
|
|
23
|
+
* @param address Address to fetch transactions for.
|
|
24
|
+
* @param opts Options for fetching transactions (limit, archival, etc.).
|
|
25
|
+
* @returns Promise with array of transactions.
|
|
26
|
+
*/
|
|
27
|
+
getTransactions(address: Address, opts: GetTransactionsOptions): Promise<Transaction[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Find transaction by its hash.
|
|
30
|
+
* Searches by transaction hash, and also by incoming message hash (both external-in and internal).
|
|
31
|
+
* This is a universal method that checks all possible hash types.
|
|
32
|
+
* @param address Account address where to search
|
|
33
|
+
* @param hash Transaction or message hash in any format (base64, hex)
|
|
34
|
+
* @param opts Search options (limit, pagination, etc.)
|
|
35
|
+
* @returns Transaction if found, null otherwise
|
|
36
|
+
*/
|
|
22
37
|
getTransactionByHash(address: Address, hash: string, opts?: GetTransactionsOptions): Promise<Transaction | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Find transaction by its transaction hash only.
|
|
40
|
+
* More efficient than getTransactionByHash if you know it's a transaction hash.
|
|
41
|
+
* @param address Account address where to search
|
|
42
|
+
* @param txHash Transaction hash in any format (base64, hex)
|
|
43
|
+
* @param opts Search options
|
|
44
|
+
* @returns Transaction if found, null otherwise
|
|
45
|
+
*/
|
|
46
|
+
getTransactionByTxHash(address: Address, txHash: string, opts?: GetTransactionsOptions): Promise<Transaction | null>;
|
|
47
|
+
/**
|
|
48
|
+
* Find transaction by its incoming message hash.
|
|
49
|
+
* Useful for finding the transaction that processed a specific message.
|
|
50
|
+
* @param address Account address where to search
|
|
51
|
+
* @param msgHash Message hash in any format (base64, hex)
|
|
52
|
+
* @param opts Search options
|
|
53
|
+
* @returns Transaction if found, null otherwise
|
|
54
|
+
*/
|
|
55
|
+
getTransactionByInMsgHash(address: Address, msgHash: string, opts?: GetTransactionsOptions): Promise<Transaction | null>;
|
|
56
|
+
/**
|
|
57
|
+
* Find transaction by its outgoing message hash.
|
|
58
|
+
* Useful for finding the parent transaction that sent a specific message.
|
|
59
|
+
* @param address Account address where to search
|
|
60
|
+
* @param msgHash Outgoing message hash in any format (base64, hex)
|
|
61
|
+
* @param opts Search options
|
|
62
|
+
* @returns Transaction if found, null otherwise
|
|
63
|
+
*/
|
|
64
|
+
getTransactionByOutMsgHash(address: Address, msgHash: string, opts?: GetTransactionsOptions): Promise<Transaction | null>;
|
|
65
|
+
/**
|
|
66
|
+
* Get adjacent transactions (children via outgoing messages and parent via incoming message).
|
|
67
|
+
* @param address Account address
|
|
68
|
+
* @param hash Transaction or message hash in any format (base64, hex)
|
|
69
|
+
* @param opts Search options
|
|
70
|
+
* @returns Array of adjacent transactions
|
|
71
|
+
*/
|
|
23
72
|
getAdjacentTransactions(address: Address, hash: string, opts?: GetTransactionsOptions): Promise<Transaction[]>;
|
|
24
73
|
getAddressInformation(address: Address): Promise<AddressInformation>;
|
|
25
74
|
getConfig(): Promise<string>;
|
|
75
|
+
/**
|
|
76
|
+
* Track and validate entire transaction tree starting from a root transaction.
|
|
77
|
+
* Recursively follows outgoing messages and validates all child transactions.
|
|
78
|
+
* @param address Root account address
|
|
79
|
+
* @param hash Root transaction or message hash
|
|
80
|
+
* @param params Tracking parameters (maxDepth, ignoreOpcodeList, etc.)
|
|
81
|
+
* @throws Error if any transaction in the tree failed
|
|
82
|
+
*/
|
|
83
|
+
trackTransactionTree(address: string, hash: string, params?: TrackTransactionTreeParams): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Track and validate entire transaction tree starting from a root transaction (returns result instead of throwing).
|
|
86
|
+
* Recursively follows outgoing messages and validates all child transactions.
|
|
87
|
+
* @param address Root account address
|
|
88
|
+
* @param hash Root transaction or message hash
|
|
89
|
+
* @param params Tracking parameters (maxDepth, ignoreOpcodeList, etc.)
|
|
90
|
+
* @returns Result object with success flag and error details if validation failed
|
|
91
|
+
*/
|
|
92
|
+
trackTransactionTreeWithResult(address: string, hash: string, params?: TrackTransactionTreeParams): Promise<TrackTransactionTreeResult>;
|
|
26
93
|
}
|
|
@@ -4,6 +4,7 @@ import { FT, NFT } from '../assets';
|
|
|
4
4
|
import type { SenderAbstraction } from '../sender';
|
|
5
5
|
import { AssetFromFTArg, AssetFromNFTCollectionArg, AssetFromNFTItemArg, AssetLike, BatchCrossChainTxWithAssetLike, CrossChainPayloadResult, CrossChainTransactionOptions, CrossChainTransactionsOptions, CrosschainTx, EVMAddress, EvmProxyMsg, ExecutionFeeEstimationResult, NFTAddressType, SuggestedTVMExecutorFee, TACSimulationParams, TACSimulationResult, TransactionLinkerWithOperationId, TVMAddress, UserWalletBalanceExtended, WaitOptions } from '../structs/Struct';
|
|
6
6
|
import { Asset } from './Asset';
|
|
7
|
+
import { ContractOpener } from './ContractOpener';
|
|
7
8
|
import { IConfiguration } from './IConfiguration';
|
|
8
9
|
import { IOperationTracker } from './IOperationTracker';
|
|
9
10
|
import { ITacExplorerClient } from './ITacExplorerClient';
|
|
@@ -187,6 +188,10 @@ export interface ITacSDK {
|
|
|
187
188
|
* Returns the TAC explorer client instance used for querying blockchain explorer data.
|
|
188
189
|
*/
|
|
189
190
|
getTacExplorerClient(): ITacExplorerClient;
|
|
191
|
+
/**
|
|
192
|
+
* Returns the TON contract opener client instance used for querying TON blockchain data.
|
|
193
|
+
*/
|
|
194
|
+
getTonContractOpener(): ContractOpener;
|
|
190
195
|
/**
|
|
191
196
|
* Prepares the transaction payloads required for a cross-chain operation without sending them.
|
|
192
197
|
* @param evmProxyMsg Encoded EVM proxy message.
|
|
@@ -52,7 +52,7 @@ class Configuration {
|
|
|
52
52
|
else {
|
|
53
53
|
contractOpener =
|
|
54
54
|
TONParams?.contractOpener ??
|
|
55
|
-
(await (0, adapters_1.createDefaultRetryableOpener)(artifacts.TON_RPC_ENDPOINT_BY_TAC, network, 5, delay));
|
|
55
|
+
(await (0, adapters_1.createDefaultRetryableOpener)(artifacts.TON_RPC_ENDPOINT_BY_TAC, network, 5, delay, logger));
|
|
56
56
|
settingsAddress = TONParams?.settingsAddress ?? artifacts.TON_SETTINGS_ADDRESS;
|
|
57
57
|
}
|
|
58
58
|
const settings = contractOpener.open(artifacts.ton.wrappers.Settings.createFromAddress(ton_1.Address.parse(settingsAddress)));
|
package/dist/src/sdk/Consts.d.ts
CHANGED
|
@@ -15,9 +15,12 @@ export declare const TON_DECIMALS = 9;
|
|
|
15
15
|
export declare const TAC_DECIMALS = 18;
|
|
16
16
|
export declare const FIVE_MINUTES: number;
|
|
17
17
|
export declare const TON_BURN_ADDRESS = "EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c";
|
|
18
|
-
export declare const
|
|
19
|
-
export declare const
|
|
18
|
+
export declare const DEFAULT_HTTP_CLIENT_TIMEOUT_MS = 30000;
|
|
19
|
+
export declare const DEFAULT_FIND_TX_TIMEOUT_MS = 180000;
|
|
20
|
+
export declare const DEFAULT_RETRY_MAX_COUNT = 5;
|
|
21
|
+
export declare const DEFAULT_RETRY_DELAY_MS = 1000;
|
|
20
22
|
export declare const DEFAULT_FIND_TX_LIMIT = 10;
|
|
21
23
|
export declare const DEFAULT_FIND_TX_ARCHIVAL = true;
|
|
22
24
|
export declare const DEFAULT_FIND_TX_MAX_DEPTH = 10;
|
|
23
25
|
export declare const IGNORE_MSG_VALUE_1_NANO = 1n;
|
|
26
|
+
export declare const IGNORE_OPCODE: number[];
|
package/dist/src/sdk/Consts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IGNORE_MSG_VALUE_1_NANO = exports.DEFAULT_FIND_TX_MAX_DEPTH = exports.DEFAULT_FIND_TX_ARCHIVAL = exports.DEFAULT_FIND_TX_LIMIT = exports.
|
|
3
|
+
exports.IGNORE_OPCODE = exports.IGNORE_MSG_VALUE_1_NANO = exports.DEFAULT_FIND_TX_MAX_DEPTH = exports.DEFAULT_FIND_TX_ARCHIVAL = exports.DEFAULT_FIND_TX_LIMIT = exports.DEFAULT_RETRY_DELAY_MS = exports.DEFAULT_RETRY_MAX_COUNT = exports.DEFAULT_FIND_TX_TIMEOUT_MS = exports.DEFAULT_HTTP_CLIENT_TIMEOUT_MS = exports.TON_BURN_ADDRESS = exports.FIVE_MINUTES = exports.TAC_DECIMALS = exports.TON_DECIMALS = exports.ONE_YEAR_SECONDS = exports.FIFTEEN_MINUTES = exports.TAC_SYMBOL = exports.TON_SYMBOL = exports.MAX_MSG_DEPTH = exports.MAX_HIGHLOAD_GROUP_MSG_NUM = exports.MAX_EXT_MSG_SIZE = exports.SOLIDITY_METHOD_NAME_REGEX = exports.SOLIDITY_SIGNATURE_REGEX = exports.DEFAULT_DELAY = exports.MAX_ITERATION_COUNT = exports.NFT_TRANSFER_FORWARD_TON_AMOUNT = exports.JETTON_TRANSFER_FORWARD_TON_AMOUNT = void 0;
|
|
4
4
|
const ton_1 = require("@ton/ton");
|
|
5
5
|
exports.JETTON_TRANSFER_FORWARD_TON_AMOUNT = (0, ton_1.toNano)(0.2);
|
|
6
6
|
exports.NFT_TRANSFER_FORWARD_TON_AMOUNT = (0, ton_1.toNano)(0.3);
|
|
@@ -19,10 +19,14 @@ exports.TON_DECIMALS = 9;
|
|
|
19
19
|
exports.TAC_DECIMALS = 18;
|
|
20
20
|
exports.FIVE_MINUTES = 5 * 60 * 1000;
|
|
21
21
|
exports.TON_BURN_ADDRESS = 'EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c';
|
|
22
|
-
|
|
23
|
-
exports.DEFAULT_FIND_TX_TIMEOUT_MS =
|
|
24
|
-
exports.
|
|
22
|
+
exports.DEFAULT_HTTP_CLIENT_TIMEOUT_MS = 30000;
|
|
23
|
+
exports.DEFAULT_FIND_TX_TIMEOUT_MS = 180000;
|
|
24
|
+
exports.DEFAULT_RETRY_MAX_COUNT = 5;
|
|
25
|
+
exports.DEFAULT_RETRY_DELAY_MS = 1000;
|
|
25
26
|
exports.DEFAULT_FIND_TX_LIMIT = 10;
|
|
26
27
|
exports.DEFAULT_FIND_TX_ARCHIVAL = true;
|
|
27
28
|
exports.DEFAULT_FIND_TX_MAX_DEPTH = 10;
|
|
28
29
|
exports.IGNORE_MSG_VALUE_1_NANO = 1n;
|
|
30
|
+
exports.IGNORE_OPCODE = [
|
|
31
|
+
0xd53276db, // Excess
|
|
32
|
+
];
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { ILogger } from '../interfaces';
|
|
2
|
-
import { ITxFinalizer } from '../interfaces/ITxFinalizer';
|
|
1
|
+
import { ContractOpener, ILogger } from '../interfaces';
|
|
3
2
|
import { ExecutionStages, Network, TransactionLinker } from '../structs/Struct';
|
|
4
3
|
export declare function startTracking(transactionLinker: TransactionLinker, network: Network, options?: {
|
|
5
4
|
customLiteSequencerEndpoints?: string[];
|
|
@@ -8,7 +7,7 @@ export declare function startTracking(transactionLinker: TransactionLinker, netw
|
|
|
8
7
|
returnValue?: boolean;
|
|
9
8
|
tableView?: boolean;
|
|
10
9
|
logger?: ILogger;
|
|
11
|
-
|
|
10
|
+
contractOpener?: ContractOpener;
|
|
12
11
|
cclAddress?: string;
|
|
13
12
|
}): Promise<void | ExecutionStages>;
|
|
14
13
|
export declare function startTrackingMultiple(transactionLinkers: TransactionLinker[], network: Network, options?: {
|
|
@@ -18,6 +17,6 @@ export declare function startTrackingMultiple(transactionLinkers: TransactionLin
|
|
|
18
17
|
returnValue?: boolean;
|
|
19
18
|
tableView?: boolean;
|
|
20
19
|
logger?: ILogger;
|
|
21
|
-
|
|
20
|
+
contractOpener?: ContractOpener;
|
|
22
21
|
}): Promise<void | ExecutionStages[]>;
|
|
23
22
|
export declare function printExecutionStagesTable(stages: ExecutionStages, logger: ILogger): void;
|