@ton/ton 13.9.0 → 13.11.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.
@@ -6,8 +6,9 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  /// <reference types="node" />
9
+ import { HttpApi } from "./api/HttpApi";
9
10
  import { AxiosAdapter } from 'axios';
10
- import { Address, Cell, Contract, ContractProvider, Message, Transaction, TupleItem, TupleReader } from '@ton/core';
11
+ import { Address, Cell, Contract, ContractProvider, Message, Transaction, TupleItem, TupleReader, StateInit, OpenedContract } from '@ton/core';
11
12
  export declare type TonClientParameters = {
12
13
  /**
13
14
  * API Endpoint
@@ -27,8 +28,8 @@ export declare type TonClientParameters = {
27
28
  httpAdapter?: AxiosAdapter;
28
29
  };
29
30
  export declare class TonClient {
30
- #private;
31
31
  readonly parameters: TonClientParameters;
32
+ protected api: HttpApi;
32
33
  constructor(parameters: TonClientParameters);
33
34
  /**
34
35
  * Get Address Balance
@@ -102,6 +103,22 @@ export declare class TonClient {
102
103
  * @returns transaction or null if not exist
103
104
  */
104
105
  getTransaction(address: Address, lt: string, hash: string): Promise<Transaction | null>;
106
+ /**
107
+ * Locate outcoming transaction of destination address by incoming message
108
+ * @param source message source address
109
+ * @param destination message destination address
110
+ * @param created_lt message's created lt
111
+ * @returns transaction
112
+ */
113
+ tryLocateResultTx(source: Address, destination: Address, created_lt: string): Promise<Transaction>;
114
+ /**
115
+ * Locate incoming transaction of source address by outcoming message
116
+ * @param source message source address
117
+ * @param destination message destination address
118
+ * @param created_lt message's created lt
119
+ * @returns transaction
120
+ */
121
+ tryLocateSourceTx(source: Address, destination: Address, created_lt: string): Promise<Transaction>;
105
122
  /**
106
123
  * Fetch latest masterchain info
107
124
  * @returns masterchain info
@@ -199,15 +216,12 @@ export declare class TonClient {
199
216
  * @param src source contract
200
217
  * @returns contract
201
218
  */
202
- open<T extends Contract>(src: T): import("@ton/core").OpenedContract<T>;
219
+ open<T extends Contract>(src: T): OpenedContract<T>;
203
220
  /**
204
221
  * Create a provider
205
222
  * @param address address
206
223
  * @param init optional init
207
224
  * @returns provider
208
225
  */
209
- provider(address: Address, init: {
210
- code: Cell | null;
211
- data: Cell | null;
212
- } | null): ContractProvider;
226
+ provider(address: Address, init?: StateInit | null): ContractProvider;
213
227
  }
@@ -6,33 +6,20 @@
6
6
  * This source code is licensed under the MIT license found in the
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  */
9
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
10
- if (kind === "m") throw new TypeError("Private method is not writable");
11
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
12
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
13
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
14
- };
15
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
16
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
17
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
18
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
19
- };
20
- var _TonClient_api;
21
9
  Object.defineProperty(exports, "__esModule", { value: true });
22
10
  exports.TonClient = void 0;
23
11
  const HttpApi_1 = require("./api/HttpApi");
24
12
  const core_1 = require("@ton/core");
25
13
  class TonClient {
26
14
  constructor(parameters) {
27
- _TonClient_api.set(this, void 0);
28
15
  this.parameters = {
29
16
  endpoint: parameters.endpoint
30
17
  };
31
- __classPrivateFieldSet(this, _TonClient_api, new HttpApi_1.HttpApi(this.parameters.endpoint, {
18
+ this.api = new HttpApi_1.HttpApi(this.parameters.endpoint, {
32
19
  timeout: parameters.timeout,
33
20
  apiKey: parameters.apiKey,
34
21
  adapter: parameters.httpAdapter
35
- }), "f");
22
+ });
36
23
  }
37
24
  /**
38
25
  * Get Address Balance
@@ -50,7 +37,7 @@ class TonClient {
50
37
  * @returns stack and gas_used field
51
38
  */
52
39
  async runMethod(address, name, stack = []) {
53
- let res = await __classPrivateFieldGet(this, _TonClient_api, "f").callGetMethod(address, name, stack);
40
+ let res = await this.api.callGetMethod(address, name, stack);
54
41
  if (res.exit_code !== 0) {
55
42
  throw Error('Unable to execute get method. Got exit_code: ' + res.exit_code);
56
43
  }
@@ -75,7 +62,7 @@ class TonClient {
75
62
  * @returns stack and gas_used field
76
63
  */
77
64
  async runMethodWithError(address, name, params = []) {
78
- let res = await __classPrivateFieldGet(this, _TonClient_api, "f").callGetMethod(address, name, params);
65
+ let res = await this.api.callGetMethod(address, name, params);
79
66
  return { gas_used: res.gas_used, stack: parseStack(res.stack), exit_code: res.exit_code };
80
67
  }
81
68
  /**
@@ -95,7 +82,7 @@ class TonClient {
95
82
  */
96
83
  async getTransactions(address, opts) {
97
84
  // Fetch transactions
98
- let tx = await __classPrivateFieldGet(this, _TonClient_api, "f").getTransactions(address, opts);
85
+ let tx = await this.api.getTransactions(address, opts);
99
86
  let res = [];
100
87
  for (let r of tx) {
101
88
  res.push((0, core_1.loadTransaction)(core_1.Cell.fromBoc(Buffer.from(r.data, 'base64'))[0].beginParse()));
@@ -110,7 +97,7 @@ class TonClient {
110
97
  * @returns transaction or null if not exist
111
98
  */
112
99
  async getTransaction(address, lt, hash) {
113
- let res = await __classPrivateFieldGet(this, _TonClient_api, "f").getTransaction(address, lt, hash);
100
+ let res = await this.api.getTransaction(address, lt, hash);
114
101
  if (res) {
115
102
  return (0, core_1.loadTransaction)(core_1.Cell.fromBoc(Buffer.from(res.data, 'base64'))[0].beginParse());
116
103
  }
@@ -118,12 +105,34 @@ class TonClient {
118
105
  return null;
119
106
  }
120
107
  }
108
+ /**
109
+ * Locate outcoming transaction of destination address by incoming message
110
+ * @param source message source address
111
+ * @param destination message destination address
112
+ * @param created_lt message's created lt
113
+ * @returns transaction
114
+ */
115
+ async tryLocateResultTx(source, destination, created_lt) {
116
+ let res = await this.api.tryLocateResultTx(source, destination, created_lt);
117
+ return (0, core_1.loadTransaction)(core_1.Cell.fromBase64(res.data).beginParse());
118
+ }
119
+ /**
120
+ * Locate incoming transaction of source address by outcoming message
121
+ * @param source message source address
122
+ * @param destination message destination address
123
+ * @param created_lt message's created lt
124
+ * @returns transaction
125
+ */
126
+ async tryLocateSourceTx(source, destination, created_lt) {
127
+ let res = await this.api.tryLocateSourceTx(source, destination, created_lt);
128
+ return (0, core_1.loadTransaction)(core_1.Cell.fromBase64(res.data).beginParse());
129
+ }
121
130
  /**
122
131
  * Fetch latest masterchain info
123
132
  * @returns masterchain info
124
133
  */
125
134
  async getMasterchainInfo() {
126
- let r = await __classPrivateFieldGet(this, _TonClient_api, "f").getMasterchainInfo();
135
+ let r = await this.api.getMasterchainInfo();
127
136
  return {
128
137
  workchain: r.init.workchain,
129
138
  shard: r.last.shard,
@@ -136,7 +145,7 @@ class TonClient {
136
145
  * @param seqno masterchain seqno
137
146
  */
138
147
  async getWorkchainShards(seqno) {
139
- let r = await __classPrivateFieldGet(this, _TonClient_api, "f").getShards(seqno);
148
+ let r = await this.api.getShards(seqno);
140
149
  return r.map((m) => ({
141
150
  workchain: m.workchain,
142
151
  shard: m.shard,
@@ -150,7 +159,7 @@ class TonClient {
150
159
  * @param shard
151
160
  */
152
161
  async getShardTransactions(workchain, seqno, shard) {
153
- let tx = await __classPrivateFieldGet(this, _TonClient_api, "f").getBlockTransactions(workchain, seqno, shard);
162
+ let tx = await this.api.getBlockTransactions(workchain, seqno, shard);
154
163
  if (tx.incomplete) {
155
164
  throw Error('Unsupported');
156
165
  }
@@ -169,14 +178,14 @@ class TonClient {
169
178
  .store((0, core_1.storeMessage)(src))
170
179
  .endCell()
171
180
  .toBoc();
172
- await __classPrivateFieldGet(this, _TonClient_api, "f").sendBoc(boc);
181
+ await this.api.sendBoc(boc);
173
182
  }
174
183
  /**
175
184
  * Send file to a network
176
185
  * @param src source file
177
186
  */
178
187
  async sendFile(src) {
179
- await __classPrivateFieldGet(this, _TonClient_api, "f").sendBoc(src);
188
+ await this.api.sendBoc(src);
180
189
  }
181
190
  /**
182
191
  * Estimate fees for external message
@@ -184,7 +193,7 @@ class TonClient {
184
193
  * @returns
185
194
  */
186
195
  async estimateExternalMessageFee(address, args) {
187
- return await __classPrivateFieldGet(this, _TonClient_api, "f").estimateFee(address, { body: args.body, initCode: args.initCode, initData: args.initData, ignoreSignature: args.ignoreSignature });
196
+ return await this.api.estimateFee(address, { body: args.body, initCode: args.initCode, initData: args.initData, ignoreSignature: args.ignoreSignature });
188
197
  }
189
198
  /**
190
199
  * Send external message to contract
@@ -202,7 +211,7 @@ class TonClient {
202
211
  else {
203
212
  const message = (0, core_1.external)({
204
213
  to: contract.address,
205
- init: { code: contract.init.code, data: contract.init.data },
214
+ init: contract.init,
206
215
  body: src
207
216
  });
208
217
  await this.sendMessage(message);
@@ -221,7 +230,7 @@ class TonClient {
221
230
  * @param address contract address
222
231
  */
223
232
  async getContractState(address) {
224
- let info = await __classPrivateFieldGet(this, _TonClient_api, "f").getAddressInformation(address);
233
+ let info = await this.api.getAddressInformation(address);
225
234
  let balance = BigInt(info.balance);
226
235
  let state = info.state;
227
236
  return {
@@ -256,11 +265,10 @@ class TonClient {
256
265
  * @returns provider
257
266
  */
258
267
  provider(address, init) {
259
- return createProvider(this, address, init);
268
+ return createProvider(this, address, init ?? null);
260
269
  }
261
270
  }
262
271
  exports.TonClient = TonClient;
263
- _TonClient_api = new WeakMap();
264
272
  function parseStackEntry(s) {
265
273
  switch (s["@type"]) {
266
274
  case "tvm.stackEntryNumber":
@@ -367,7 +375,7 @@ function createProvider(client, address, init) {
367
375
  //
368
376
  const ext = (0, core_1.external)({
369
377
  to: address,
370
- init: neededInit ? { code: neededInit.code, data: neededInit.data } : null,
378
+ init: neededInit,
371
379
  body: message
372
380
  });
373
381
  let boc = (0, core_1.beginCell)()
@@ -412,6 +420,12 @@ function createProvider(client, address, init) {
412
420
  init: neededInit,
413
421
  body
414
422
  });
423
+ },
424
+ open(contract) {
425
+ return (0, core_1.openContract)(contract, (args) => createProvider(client, args.address, args.init ?? null));
426
+ },
427
+ getTransactions(address, lt, hash, limit) {
428
+ return client.getTransactions(address, { limit: limit ?? 100, lt: lt.toString(), hash: hash.toString('base64'), inclusive: true });
415
429
  }
416
430
  };
417
431
  }
@@ -34,4 +34,12 @@ describeConditional('TonClient', () => {
34
34
  let wcShards = await client.getWorkchainShards(info.latestSeqno);
35
35
  console.log(info, shardInfo, wcShards);
36
36
  });
37
+ it('should locate source/result tx', async () => {
38
+ let source = core_1.Address.parse('UQDDT0TOC4PMp894jtCo3-d1-8ltSjXMX2EuWww_pCNibsUH');
39
+ let createdLt = '37508996000002';
40
+ let infoSource = await client.tryLocateSourceTx(source, testAddress, createdLt);
41
+ console.log(infoSource);
42
+ let infoResult = await client.tryLocateResultTx(source, testAddress, createdLt);
43
+ console.log(infoResult);
44
+ });
37
45
  });
@@ -7,7 +7,7 @@
7
7
  */
8
8
  /// <reference types="node" />
9
9
  import { AxiosAdapter } from "axios";
10
- import { Address, Cell, Contract, ContractProvider, Transaction, TupleItem, TupleReader } from "@ton/core";
10
+ import { Address, Contract, ContractProvider, OpenedContract, StateInit, Transaction, TupleItem, TupleReader } from "@ton/core";
11
11
  import { z } from 'zod';
12
12
  export declare type TonClient4Parameters = {
13
13
  /**
@@ -267,24 +267,21 @@ export declare class TonClient4 {
267
267
  * @param contract contract
268
268
  * @returns opened contract
269
269
  */
270
- open<T extends Contract>(contract: T): import("@ton/core").OpenedContract<T>;
270
+ open<T extends Contract>(contract: T): OpenedContract<T>;
271
271
  /**
272
272
  * Open smart contract
273
273
  * @param block block number
274
274
  * @param contract contract
275
275
  * @returns opened contract
276
276
  */
277
- openAt<T extends Contract>(block: number, contract: T): import("@ton/core").OpenedContract<T>;
277
+ openAt<T extends Contract>(block: number, contract: T): OpenedContract<T>;
278
278
  /**
279
279
  * Create provider
280
280
  * @param address address
281
281
  * @param init optional init data
282
282
  * @returns provider
283
283
  */
284
- provider(address: Address, init?: {
285
- code: Cell;
286
- data: Cell;
287
- } | null): ContractProvider;
284
+ provider(address: Address, init?: StateInit | null): ContractProvider;
288
285
  /**
289
286
  * Create provider at specified block number
290
287
  * @param block block number
@@ -292,10 +289,7 @@ export declare class TonClient4 {
292
289
  * @param init optional init data
293
290
  * @returns provider
294
291
  */
295
- providerAt(block: number, address: Address, init?: {
296
- code: Cell;
297
- data: Cell;
298
- } | null): ContractProvider;
292
+ providerAt(block: number, address: Address, init?: StateInit | null): ContractProvider;
299
293
  }
300
294
  declare const blocksCodec: z.ZodArray<z.ZodObject<{
301
295
  workchain: z.ZodNumber;
@@ -259,7 +259,7 @@ class TonClient4 {
259
259
  * @returns provider
260
260
  */
261
261
  provider(address, init) {
262
- return createProvider(this, null, address, init ? init : null);
262
+ return createProvider(this, null, address, init ?? null);
263
263
  }
264
264
  /**
265
265
  * Create provider at specified block number
@@ -269,7 +269,7 @@ class TonClient4 {
269
269
  * @returns provider
270
270
  */
271
271
  providerAt(block, address, init) {
272
- return createProvider(this, block, address, init ? init : null);
272
+ return createProvider(this, block, address, init ?? null);
273
273
  }
274
274
  }
275
275
  exports.TonClient4 = TonClient4;
@@ -340,7 +340,7 @@ function createProvider(client, block, address, init) {
340
340
  // Send with state init
341
341
  const ext = (0, core_1.external)({
342
342
  to: address,
343
- init: neededInit ? { code: neededInit.code, data: neededInit.data } : null,
343
+ init: neededInit,
344
344
  body: message
345
345
  });
346
346
  let pkg = (0, core_1.beginCell)()
@@ -387,6 +387,44 @@ function createProvider(client, block, address, init) {
387
387
  init: neededInit,
388
388
  body
389
389
  });
390
+ },
391
+ open(contract) {
392
+ return (0, core_1.openContract)(contract, (args) => createProvider(client, block, args.address, args.init ?? null));
393
+ },
394
+ async getTransactions(address, lt, hash, limit) {
395
+ // Resolve last
396
+ const useLimit = typeof limit === 'number';
397
+ if (useLimit && limit <= 0) {
398
+ return [];
399
+ }
400
+ // Load transactions
401
+ let transactions = [];
402
+ do {
403
+ const txs = await client.getAccountTransactions(address, lt, hash);
404
+ const firstTx = txs[0].tx;
405
+ const [firstLt, firstHash] = [firstTx.lt, firstTx.hash()];
406
+ const needSkipFirst = transactions.length > 0 && firstLt === lt && firstHash.equals(hash);
407
+ if (needSkipFirst) {
408
+ txs.shift();
409
+ }
410
+ if (txs.length === 0) {
411
+ break;
412
+ }
413
+ const lastTx = txs[txs.length - 1].tx;
414
+ const [lastLt, lastHash] = [lastTx.lt, lastTx.hash()];
415
+ if (lastLt === lt && lastHash.equals(hash)) {
416
+ break;
417
+ }
418
+ transactions.push(...txs.map(tx => tx.tx));
419
+ lt = lastLt;
420
+ hash = lastHash;
421
+ } while (useLimit && transactions.length < limit);
422
+ // Apply limit
423
+ if (useLimit) {
424
+ transactions = transactions.slice(0, limit);
425
+ }
426
+ // Return transactions
427
+ return transactions;
390
428
  }
391
429
  };
392
430
  }
@@ -644,6 +644,120 @@ export declare class HttpApi {
644
644
  fwd_fee: number;
645
645
  };
646
646
  }>;
647
+ tryLocateResultTx(source: Address, destination: Address, created_lt: string): Promise<{
648
+ data: string;
649
+ storage_fee: string;
650
+ utime: number;
651
+ transaction_id: {
652
+ lt: string;
653
+ hash: string;
654
+ };
655
+ fee: string;
656
+ other_fee: string;
657
+ out_msgs: {
658
+ value: string;
659
+ message: string;
660
+ fwd_fee: string;
661
+ source: string;
662
+ destination: string;
663
+ ihr_fee: string;
664
+ created_lt: string;
665
+ body_hash: string;
666
+ msg_data: {
667
+ '@type': "msg.dataRaw";
668
+ body: string;
669
+ } | {
670
+ '@type': "msg.dataText";
671
+ text: string;
672
+ } | {
673
+ '@type': "msg.dataDecryptedText";
674
+ text: string;
675
+ } | {
676
+ '@type': "msg.dataEncryptedText";
677
+ text: string;
678
+ };
679
+ }[];
680
+ in_msg?: {
681
+ value: string;
682
+ message: string;
683
+ fwd_fee: string;
684
+ source: string;
685
+ destination: string;
686
+ ihr_fee: string;
687
+ created_lt: string;
688
+ body_hash: string;
689
+ msg_data: {
690
+ '@type': "msg.dataRaw";
691
+ body: string;
692
+ } | {
693
+ '@type': "msg.dataText";
694
+ text: string;
695
+ } | {
696
+ '@type': "msg.dataDecryptedText";
697
+ text: string;
698
+ } | {
699
+ '@type': "msg.dataEncryptedText";
700
+ text: string;
701
+ };
702
+ } | undefined;
703
+ }>;
704
+ tryLocateSourceTx(source: Address, destination: Address, created_lt: string): Promise<{
705
+ data: string;
706
+ storage_fee: string;
707
+ utime: number;
708
+ transaction_id: {
709
+ lt: string;
710
+ hash: string;
711
+ };
712
+ fee: string;
713
+ other_fee: string;
714
+ out_msgs: {
715
+ value: string;
716
+ message: string;
717
+ fwd_fee: string;
718
+ source: string;
719
+ destination: string;
720
+ ihr_fee: string;
721
+ created_lt: string;
722
+ body_hash: string;
723
+ msg_data: {
724
+ '@type': "msg.dataRaw";
725
+ body: string;
726
+ } | {
727
+ '@type': "msg.dataText";
728
+ text: string;
729
+ } | {
730
+ '@type': "msg.dataDecryptedText";
731
+ text: string;
732
+ } | {
733
+ '@type': "msg.dataEncryptedText";
734
+ text: string;
735
+ };
736
+ }[];
737
+ in_msg?: {
738
+ value: string;
739
+ message: string;
740
+ fwd_fee: string;
741
+ source: string;
742
+ destination: string;
743
+ ihr_fee: string;
744
+ created_lt: string;
745
+ body_hash: string;
746
+ msg_data: {
747
+ '@type': "msg.dataRaw";
748
+ body: string;
749
+ } | {
750
+ '@type': "msg.dataText";
751
+ text: string;
752
+ } | {
753
+ '@type': "msg.dataDecryptedText";
754
+ text: string;
755
+ } | {
756
+ '@type': "msg.dataEncryptedText";
757
+ text: string;
758
+ };
759
+ } | undefined;
760
+ }>;
647
761
  private doCall;
648
762
  }
649
763
  export {};
@@ -246,6 +246,12 @@ class HttpApi {
246
246
  ignore_chksig: args.ignoreSignature
247
247
  }, feeResponse);
248
248
  }
249
+ async tryLocateResultTx(source, destination, created_lt) {
250
+ return await this.doCall('tryLocateResultTx', { source: source.toString(), destination: destination.toString(), created_lt }, transaction);
251
+ }
252
+ async tryLocateSourceTx(source, destination, created_lt) {
253
+ return await this.doCall('tryLocateSourceTx', { source: source.toString(), destination: destination.toString(), created_lt }, transaction);
254
+ }
249
255
  async doCall(method, body, codec) {
250
256
  let headers = {
251
257
  'Content-Type': 'application/json',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ton/ton",
3
- "version": "13.9.0",
3
+ "version": "13.11.0",
4
4
  "repository": "https://github.com/ton-org/ton.git",
5
5
  "author": "Whales Corp. <developers@whalescorp.com>",
6
6
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "devDependencies": {
18
18
  "@release-it/keep-a-changelog": "^3.1.0",
19
- "@ton/core": "^0.53.0",
19
+ "@ton/core": "^0.56.0",
20
20
  "@ton/crypto": "3.2.0",
21
21
  "@ton/emulator": "^2.1.1",
22
22
  "@types/jest": "^27.0.1",
@@ -47,7 +47,7 @@
47
47
  "zod": "^3.21.4"
48
48
  },
49
49
  "peerDependencies": {
50
- "@ton/core": ">=0.53.0",
50
+ "@ton/core": ">=0.56.0",
51
51
  "@ton/crypto": ">=3.2.0"
52
52
  },
53
53
  "publishConfig": {