@ton/ton 13.9.0 → 13.10.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,6 +6,7 @@
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
11
  import { Address, Cell, Contract, ContractProvider, Message, Transaction, TupleItem, TupleReader } from '@ton/core';
11
12
  export declare type TonClientParameters = {
@@ -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
@@ -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
@@ -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 {
@@ -260,7 +269,6 @@ class TonClient {
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":
@@ -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
  });
@@ -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.10.0",
4
4
  "repository": "https://github.com/ton-org/ton.git",
5
5
  "author": "Whales Corp. <developers@whalescorp.com>",
6
6
  "license": "MIT",