@ton/ton 16.1.0 → 16.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -11
- package/dist/client/TonClient.d.ts +6 -6
- package/dist/client/TonClient.js +105 -80
- package/dist/client/TonClient4.d.ts +1 -1
- package/dist/client/TonClient4.js +227 -138
- package/dist/client/api/HttpApi.d.ts +122 -122
- package/dist/client/api/HttpApi.js +103 -72
- package/dist/client/api/TonCache.js +3 -3
- package/dist/config/ConfigParser.js +133 -112
- package/dist/elector/ElectorContract.js +46 -20
- package/dist/index.d.ts +22 -22
- package/dist/jetton/JettonMaster.js +5 -3
- package/dist/jetton/JettonWallet.js +2 -2
- package/dist/multisig/MultisigOrder.d.ts +2 -2
- package/dist/multisig/MultisigOrder.js +1 -1
- package/dist/multisig/MultisigOrderBuilder.d.ts +2 -2
- package/dist/multisig/MultisigOrderBuilder.js +1 -1
- package/dist/multisig/MultisigWallet.d.ts +3 -3
- package/dist/multisig/MultisigWallet.js +8 -8
- package/dist/utils/createTestClient.d.ts +1 -1
- package/dist/utils/createTestClient.js +6 -2
- package/dist/utils/createTestClient4.d.ts +1 -1
- package/dist/utils/createTestClient4.js +5 -1
- package/dist/utils/fees.d.ts +2 -2
- package/dist/utils/fees.js +21 -6
- package/dist/utils/{randomTestKey.d.ts → testUtils.d.ts} +2 -0
- package/dist/utils/testUtils.js +21 -0
- package/dist/utils/testWallets.d.ts +10 -10
- package/dist/utils/time.js +5 -3
- package/dist/utils/toUrlSafe.js +6 -6
- package/dist/wallets/WalletContractV1R1.d.ts +1 -57
- package/dist/wallets/WalletContractV1R1.js +15 -99
- package/dist/wallets/WalletContractV1R2.d.ts +1 -57
- package/dist/wallets/WalletContractV1R2.js +15 -100
- package/dist/wallets/WalletContractV1R3.d.ts +1 -57
- package/dist/wallets/WalletContractV1R3.js +15 -99
- package/dist/wallets/WalletContractV2R1.d.ts +1 -59
- package/dist/wallets/WalletContractV2R1.js +15 -101
- package/dist/wallets/WalletContractV2R2.d.ts +1 -59
- package/dist/wallets/WalletContractV2R2.js +15 -101
- package/dist/wallets/WalletContractV3R1.d.ts +1 -56
- package/dist/wallets/WalletContractV3R1.js +15 -103
- package/dist/wallets/WalletContractV3R2.d.ts +1 -56
- package/dist/wallets/WalletContractV3R2.js +15 -103
- package/dist/wallets/WalletContractV4.d.ts +2 -2
- package/dist/wallets/WalletContractV5Beta.d.ts +3 -3
- package/dist/wallets/WalletContractV5R1.d.ts +3 -3
- package/dist/wallets/signing/createWalletTransfer.d.ts +11 -3
- package/dist/wallets/signing/createWalletTransfer.js +18 -15
- package/dist/wallets/signing/singer.d.ts +2 -1
- package/dist/wallets/signing/singer.js +11 -5
- package/dist/wallets/v1/r1.d.ts +59 -0
- package/dist/wallets/v1/r1.js +103 -0
- package/dist/wallets/v1/r2.d.ts +59 -0
- package/dist/wallets/v1/r2.js +104 -0
- package/dist/wallets/v1/r3.d.ts +59 -0
- package/dist/wallets/v1/r3.js +103 -0
- package/dist/wallets/v2/r1.d.ts +61 -0
- package/dist/wallets/v2/r1.js +107 -0
- package/dist/wallets/v2/r2.d.ts +61 -0
- package/dist/wallets/v2/r2.js +107 -0
- package/dist/wallets/v3/r1.d.ts +58 -0
- package/dist/wallets/v3/r1.js +109 -0
- package/dist/wallets/v3/r2.d.ts +58 -0
- package/dist/wallets/v3/r2.js +109 -0
- package/dist/wallets/v4/WalletContractV4.d.ts +4 -2
- package/dist/wallets/v4/WalletContractV4.js +36 -32
- package/dist/wallets/v4/WalletContractV4Actions.d.ts +4 -4
- package/dist/wallets/v4/WalletContractV4Actions.js +10 -10
- package/dist/wallets/v5beta/WalletContractV5Beta.d.ts +7 -5
- package/dist/wallets/v5beta/WalletContractV5Beta.js +44 -28
- package/dist/wallets/v5beta/WalletV5BetaActions.d.ts +1 -1
- package/dist/wallets/v5beta/WalletV5BetaActions.js +25 -18
- package/dist/wallets/v5beta/WalletV5BetaWalletId.d.ts +2 -2
- package/dist/wallets/v5beta/WalletV5BetaWalletId.js +6 -4
- package/dist/wallets/v5beta/WalletV5OutActions.d.ts +4 -4
- package/dist/wallets/v5beta/WalletV5OutActions.js +3 -1
- package/dist/wallets/v5r1/WalletContractV5R1.d.ts +10 -6
- package/dist/wallets/v5r1/WalletContractV5R1.js +55 -36
- package/dist/wallets/v5r1/WalletV5R1Actions.d.ts +3 -3
- package/dist/wallets/v5r1/WalletV5R1Actions.js +32 -25
- package/dist/wallets/v5r1/WalletV5R1WalletId.d.ts +2 -2
- package/dist/wallets/v5r1/WalletV5R1WalletId.js +16 -10
- package/package.json +62 -65
- package/dist/client/TonClient.spec.d.ts +0 -1
- package/dist/client/TonClient.spec.js +0 -59
- package/dist/client/TonClient4.spec.d.ts +0 -1
- package/dist/client/TonClient4.spec.js +0 -67
- package/dist/config/ConfigParser.spec.d.ts +0 -8
- package/dist/config/ConfigParser.spec.js +0 -247
- package/dist/elector/ElectorContract.spec.d.ts +0 -8
- package/dist/elector/ElectorContract.spec.js +0 -104
- package/dist/jetton/JettonMaster.spec.d.ts +0 -8
- package/dist/jetton/JettonMaster.spec.js +0 -27
- package/dist/multisig/MultisigOrder.spec.d.ts +0 -1
- package/dist/multisig/MultisigOrder.spec.js +0 -139
- package/dist/multisig/MultisigWallet.spec.d.ts +0 -1
- package/dist/multisig/MultisigWallet.spec.js +0 -248
- package/dist/utils/fees.spec.d.ts +0 -1
- package/dist/utils/fees.spec.js +0 -83
- package/dist/utils/randomTestKey.js +0 -23
- package/dist/wallets/WalletContractV1R1.spec.d.ts +0 -8
- package/dist/wallets/WalletContractV1R1.spec.js +0 -67
- package/dist/wallets/WalletContractV1R2.spec.d.ts +0 -8
- package/dist/wallets/WalletContractV1R2.spec.js +0 -67
- package/dist/wallets/WalletContractV1R3.spec.d.ts +0 -8
- package/dist/wallets/WalletContractV1R3.spec.js +0 -44
- package/dist/wallets/WalletContractV2R1.spec.d.ts +0 -8
- package/dist/wallets/WalletContractV2R1.spec.js +0 -67
- package/dist/wallets/WalletContractV2R2.spec.d.ts +0 -8
- package/dist/wallets/WalletContractV2R2.spec.js +0 -67
- package/dist/wallets/WalletContractV3R1.spec.d.ts +0 -8
- package/dist/wallets/WalletContractV3R1.spec.js +0 -67
- package/dist/wallets/WalletContractV3R2.spec.d.ts +0 -8
- package/dist/wallets/WalletContractV3R2.spec.js +0 -67
- package/dist/wallets/v4/WalletContractV4.spec.d.ts +0 -8
- package/dist/wallets/v4/WalletContractV4.spec.js +0 -157
- package/dist/wallets/v4/WalletContractV4Actions.spec.d.ts +0 -1
- package/dist/wallets/v4/WalletContractV4Actions.spec.js +0 -74
- package/dist/wallets/v5beta/WalletContractV5Beta.spec.d.ts +0 -8
- package/dist/wallets/v5beta/WalletContractV5Beta.spec.js +0 -317
- package/dist/wallets/v5beta/WalletV5BetaActions.spec.d.ts +0 -1
- package/dist/wallets/v5beta/WalletV5BetaActions.spec.js +0 -166
- package/dist/wallets/v5beta/WalletV5BetaWalletId.spec.d.ts +0 -1
- package/dist/wallets/v5beta/WalletV5BetaWalletId.spec.js +0 -68
- package/dist/wallets/v5r1/WalletContractV5R1.spec.d.ts +0 -8
- package/dist/wallets/v5r1/WalletContractV5R1.spec.js +0 -340
- package/dist/wallets/v5r1/WalletV5R1Actions.spec.d.ts +0 -1
- package/dist/wallets/v5r1/WalletV5R1Actions.spec.js +0 -262
- package/dist/wallets/v5r1/WalletV5R1WalletId.spec.d.ts +0 -1
- package/dist/wallets/v5r1/WalletV5R1WalletId.spec.js +0 -103
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ To use this library you need HTTP API endpoint, you can use one of the public en
|
|
|
30
30
|
- Mainnet: https://toncenter.com/api/v2/jsonRPC
|
|
31
31
|
- Testnet: https://testnet.toncenter.com/api/v2/jsonRPC
|
|
32
32
|
|
|
33
|
-
```
|
|
33
|
+
```ts
|
|
34
34
|
import { TonClient, WalletContractV4, internal } from "@ton/ton";
|
|
35
35
|
import { mnemonicNew, mnemonicToPrivateKey } from "@ton/crypto";
|
|
36
36
|
|
|
@@ -40,20 +40,22 @@ const client = new TonClient({
|
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
// Generate new key
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const mnemonic = await mnemonicNew();
|
|
44
|
+
const keyPair = await mnemonicToPrivateKey(mnemonic);
|
|
45
45
|
|
|
46
46
|
// Create wallet contract
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
const wallet = WalletContractV4.create({
|
|
48
|
+
workchain: 0, // basechain
|
|
49
|
+
publicKey: keyPair.publicKey,
|
|
50
|
+
});
|
|
51
|
+
const contract = client.open(wallet);
|
|
50
52
|
|
|
51
53
|
// Get balance
|
|
52
|
-
|
|
54
|
+
const balance = await contract.getBalance();
|
|
53
55
|
|
|
54
56
|
// Create a transfer
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
const seqno = await contract.getSeqno();
|
|
58
|
+
const transfer = await contract.createTransfer({
|
|
57
59
|
seqno,
|
|
58
60
|
secretKey: keyPair.secretKey,
|
|
59
61
|
messages: [internal({
|
|
@@ -62,12 +64,46 @@ let transfer = await contract.createTransfer({
|
|
|
62
64
|
body: 'Hello world',
|
|
63
65
|
})]
|
|
64
66
|
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Formatting
|
|
70
|
+
|
|
71
|
+
We use `biome` as our formatter. It's prettier compatible and fast
|
|
72
|
+
|
|
73
|
+
IDE Setup: [VSCode](https://marketplace.visualstudio.com/items?itemName=biomejs.biome), [Zed](https://biomejs.dev/reference/zed/)
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
yarn run format
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Testing
|
|
80
|
+
|
|
81
|
+
### Debugging in tests
|
|
82
|
+
|
|
83
|
+
By default tests are running using multiple worker threads. It's faster, but
|
|
84
|
+
undesirable during debugging. `SINGLETHREADED` env variable covers this case
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
SINGLETHREADED=1 yarn run test
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Coverage report
|
|
91
|
+
|
|
92
|
+
We use test coverage to eliminate blind spots in our tests.
|
|
93
|
+
|
|
94
|
+
#### How to?
|
|
95
|
+
|
|
96
|
+
The goal is to make all functions runned at least once
|
|
97
|
+
|
|
98
|
+
1. Build a coverage report
|
|
65
99
|
|
|
100
|
+
```sh
|
|
101
|
+
yarn run coverage
|
|
66
102
|
```
|
|
67
103
|
|
|
68
|
-
|
|
104
|
+
2. Coverage report is build to the `/coverage` directory
|
|
69
105
|
|
|
70
|
-
|
|
106
|
+
3. Open `/coverage/index.html` to check the report
|
|
71
107
|
|
|
72
108
|
## Acknowledgements
|
|
73
109
|
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
import { HttpApi } from "./api/HttpApi";
|
|
9
|
-
import { AxiosAdapter } from
|
|
10
|
-
import { Address, Cell, Contract, ContractProvider, Message, Transaction, TupleItem, TupleReader, StateInit, OpenedContract } from
|
|
9
|
+
import { AxiosAdapter } from "axios";
|
|
10
|
+
import { Address, Cell, Contract, ContractProvider, Message, Transaction, TupleItem, TupleReader, StateInit, OpenedContract } from "@ton/core";
|
|
11
11
|
export type TonClientParameters = {
|
|
12
12
|
/**
|
|
13
13
|
* API Endpoint
|
|
@@ -65,7 +65,7 @@ export declare class TonClient {
|
|
|
65
65
|
* @param name name of method
|
|
66
66
|
* @param params optional parameters
|
|
67
67
|
* @returns stack and gas_used field
|
|
68
|
-
|
|
68
|
+
*/
|
|
69
69
|
runMethodWithError(address: Address, name: string, params?: any[]): Promise<{
|
|
70
70
|
gas_used: number;
|
|
71
71
|
stack: TupleReader;
|
|
@@ -170,9 +170,9 @@ export declare class TonClient {
|
|
|
170
170
|
initData: Cell | null;
|
|
171
171
|
ignoreSignature: boolean;
|
|
172
172
|
}): Promise<{
|
|
173
|
-
|
|
173
|
+
"@type": "query.fees";
|
|
174
174
|
source_fees: {
|
|
175
|
-
|
|
175
|
+
"@type": "fees";
|
|
176
176
|
in_fwd_fee: number;
|
|
177
177
|
storage_fee: number;
|
|
178
178
|
gas_fee: number;
|
|
@@ -198,7 +198,7 @@ export declare class TonClient {
|
|
|
198
198
|
getContractState(address: Address): Promise<{
|
|
199
199
|
balance: bigint;
|
|
200
200
|
extra_currencies: {
|
|
201
|
-
|
|
201
|
+
"@type": "extraCurrency";
|
|
202
202
|
id: number;
|
|
203
203
|
amount: string;
|
|
204
204
|
}[] | undefined;
|
package/dist/client/TonClient.js
CHANGED
|
@@ -13,12 +13,12 @@ const core_1 = require("@ton/core");
|
|
|
13
13
|
class TonClient {
|
|
14
14
|
constructor(parameters) {
|
|
15
15
|
this.parameters = {
|
|
16
|
-
endpoint: parameters.endpoint
|
|
16
|
+
endpoint: parameters.endpoint,
|
|
17
17
|
};
|
|
18
18
|
this.api = new HttpApi_1.HttpApi(this.parameters.endpoint, {
|
|
19
19
|
timeout: parameters.timeout,
|
|
20
20
|
apiKey: parameters.apiKey,
|
|
21
|
-
adapter: parameters.httpAdapter
|
|
21
|
+
adapter: parameters.httpAdapter,
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
@@ -39,7 +39,7 @@ class TonClient {
|
|
|
39
39
|
async runMethod(address, name, stack = []) {
|
|
40
40
|
let res = await this.api.callGetMethod(address, name, stack);
|
|
41
41
|
if (res.exit_code !== 0) {
|
|
42
|
-
throw Error(
|
|
42
|
+
throw Error("Unable to execute get method. Got exit_code: " + res.exit_code);
|
|
43
43
|
}
|
|
44
44
|
return { gas_used: res.gas_used, stack: parseStack(res.stack) };
|
|
45
45
|
}
|
|
@@ -60,10 +60,14 @@ class TonClient {
|
|
|
60
60
|
* @param name name of method
|
|
61
61
|
* @param params optional parameters
|
|
62
62
|
* @returns stack and gas_used field
|
|
63
|
-
|
|
63
|
+
*/
|
|
64
64
|
async runMethodWithError(address, name, params = []) {
|
|
65
65
|
let res = await this.api.callGetMethod(address, name, params);
|
|
66
|
-
return {
|
|
66
|
+
return {
|
|
67
|
+
gas_used: res.gas_used,
|
|
68
|
+
stack: parseStack(res.stack),
|
|
69
|
+
exit_code: res.exit_code,
|
|
70
|
+
};
|
|
67
71
|
}
|
|
68
72
|
/**
|
|
69
73
|
* Invoke get method that returns error code instead of throwing error
|
|
@@ -85,7 +89,7 @@ class TonClient {
|
|
|
85
89
|
let tx = await this.api.getTransactions(address, opts);
|
|
86
90
|
let res = [];
|
|
87
91
|
for (let r of tx) {
|
|
88
|
-
res.push((0, core_1.loadTransaction)(core_1.Cell.fromBoc(Buffer.from(r.data,
|
|
92
|
+
res.push((0, core_1.loadTransaction)(core_1.Cell.fromBoc(Buffer.from(r.data, "base64"))[0].beginParse()));
|
|
89
93
|
}
|
|
90
94
|
return res;
|
|
91
95
|
}
|
|
@@ -99,7 +103,7 @@ class TonClient {
|
|
|
99
103
|
async getTransaction(address, lt, hash) {
|
|
100
104
|
let res = await this.api.getTransaction(address, lt, hash);
|
|
101
105
|
if (res) {
|
|
102
|
-
return (0, core_1.loadTransaction)(core_1.Cell.fromBoc(Buffer.from(res.data,
|
|
106
|
+
return (0, core_1.loadTransaction)(core_1.Cell.fromBoc(Buffer.from(res.data, "base64"))[0].beginParse());
|
|
103
107
|
}
|
|
104
108
|
else {
|
|
105
109
|
return null;
|
|
@@ -137,7 +141,7 @@ class TonClient {
|
|
|
137
141
|
workchain: r.init.workchain,
|
|
138
142
|
shard: r.last.shard,
|
|
139
143
|
initSeqno: r.init.seqno,
|
|
140
|
-
latestSeqno: r.last.seqno
|
|
144
|
+
latestSeqno: r.last.seqno,
|
|
141
145
|
};
|
|
142
146
|
}
|
|
143
147
|
/**
|
|
@@ -149,7 +153,7 @@ class TonClient {
|
|
|
149
153
|
return r.map((m) => ({
|
|
150
154
|
workchain: m.workchain,
|
|
151
155
|
shard: m.shard,
|
|
152
|
-
seqno: m.seqno
|
|
156
|
+
seqno: m.seqno,
|
|
153
157
|
}));
|
|
154
158
|
}
|
|
155
159
|
/**
|
|
@@ -161,12 +165,12 @@ class TonClient {
|
|
|
161
165
|
async getShardTransactions(workchain, seqno, shard) {
|
|
162
166
|
let tx = await this.api.getBlockTransactions(workchain, seqno, shard);
|
|
163
167
|
if (tx.incomplete) {
|
|
164
|
-
throw Error(
|
|
168
|
+
throw Error("Unsupported");
|
|
165
169
|
}
|
|
166
170
|
return tx.transactions.map((v) => ({
|
|
167
171
|
account: core_1.Address.parseRaw(v.account),
|
|
168
172
|
lt: v.lt,
|
|
169
|
-
hash: v.hash
|
|
173
|
+
hash: v.hash,
|
|
170
174
|
}));
|
|
171
175
|
}
|
|
172
176
|
/**
|
|
@@ -174,10 +178,7 @@ class TonClient {
|
|
|
174
178
|
* @param src source message
|
|
175
179
|
*/
|
|
176
180
|
async sendMessage(src) {
|
|
177
|
-
const boc = (0, core_1.beginCell)()
|
|
178
|
-
.store((0, core_1.storeMessage)(src))
|
|
179
|
-
.endCell()
|
|
180
|
-
.toBoc();
|
|
181
|
+
const boc = (0, core_1.beginCell)().store((0, core_1.storeMessage)(src)).endCell().toBoc();
|
|
181
182
|
await this.api.sendBoc(boc);
|
|
182
183
|
}
|
|
183
184
|
/**
|
|
@@ -193,7 +194,12 @@ class TonClient {
|
|
|
193
194
|
* @returns
|
|
194
195
|
*/
|
|
195
196
|
async estimateExternalMessageFee(address, args) {
|
|
196
|
-
return await this.api.estimateFee(address, {
|
|
197
|
+
return await this.api.estimateFee(address, {
|
|
198
|
+
body: args.body,
|
|
199
|
+
initCode: args.initCode,
|
|
200
|
+
initData: args.initData,
|
|
201
|
+
ignoreSignature: args.ignoreSignature,
|
|
202
|
+
});
|
|
197
203
|
}
|
|
198
204
|
/**
|
|
199
205
|
* Send external message to contract
|
|
@@ -201,10 +207,11 @@ class TonClient {
|
|
|
201
207
|
* @param src message body
|
|
202
208
|
*/
|
|
203
209
|
async sendExternalMessage(contract, src) {
|
|
204
|
-
if (await this.isContractDeployed(contract.address) ||
|
|
210
|
+
if ((await this.isContractDeployed(contract.address)) ||
|
|
211
|
+
!contract.init) {
|
|
205
212
|
const message = (0, core_1.external)({
|
|
206
213
|
to: contract.address,
|
|
207
|
-
body: src
|
|
214
|
+
body: src,
|
|
208
215
|
});
|
|
209
216
|
await this.sendMessage(message);
|
|
210
217
|
}
|
|
@@ -212,7 +219,7 @@ class TonClient {
|
|
|
212
219
|
const message = (0, core_1.external)({
|
|
213
220
|
to: contract.address,
|
|
214
221
|
init: contract.init,
|
|
215
|
-
body: src
|
|
222
|
+
body: src,
|
|
216
223
|
});
|
|
217
224
|
await this.sendMessage(message);
|
|
218
225
|
}
|
|
@@ -223,7 +230,7 @@ class TonClient {
|
|
|
223
230
|
* @returns true if contract is in active state
|
|
224
231
|
*/
|
|
225
232
|
async isContractDeployed(address) {
|
|
226
|
-
return (await this.getContractState(address)).state ===
|
|
233
|
+
return (await this.getContractState(address)).state === "active";
|
|
227
234
|
}
|
|
228
235
|
/**
|
|
229
236
|
* Resolves contract state
|
|
@@ -237,18 +244,20 @@ class TonClient {
|
|
|
237
244
|
balance,
|
|
238
245
|
extra_currencies: info.extra_currencies,
|
|
239
246
|
state,
|
|
240
|
-
code: info.code !==
|
|
241
|
-
data: info.data !==
|
|
242
|
-
lastTransaction: info.last_transaction_id.lt !==
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
247
|
+
code: info.code !== "" ? Buffer.from(info.code, "base64") : null,
|
|
248
|
+
data: info.data !== "" ? Buffer.from(info.data, "base64") : null,
|
|
249
|
+
lastTransaction: info.last_transaction_id.lt !== "0"
|
|
250
|
+
? {
|
|
251
|
+
lt: info.last_transaction_id.lt,
|
|
252
|
+
hash: info.last_transaction_id.hash,
|
|
253
|
+
}
|
|
254
|
+
: null,
|
|
246
255
|
blockId: {
|
|
247
256
|
workchain: info.block_id.workchain,
|
|
248
257
|
shard: info.block_id.shard,
|
|
249
|
-
seqno: info.block_id.seqno
|
|
258
|
+
seqno: info.block_id.seqno,
|
|
250
259
|
},
|
|
251
|
-
timestampt: info.sync_utime
|
|
260
|
+
timestampt: info.sync_utime,
|
|
252
261
|
};
|
|
253
262
|
}
|
|
254
263
|
/**
|
|
@@ -271,61 +280,70 @@ class TonClient {
|
|
|
271
280
|
}
|
|
272
281
|
exports.TonClient = TonClient;
|
|
273
282
|
function parseStackEntry(x) {
|
|
274
|
-
const typeName = x[
|
|
283
|
+
const typeName = x["@type"];
|
|
275
284
|
switch (typeName) {
|
|
276
|
-
case
|
|
277
|
-
case
|
|
285
|
+
case "tvm.list":
|
|
286
|
+
case "tvm.tuple":
|
|
278
287
|
return x.elements.map(parseStackEntry);
|
|
279
|
-
case
|
|
280
|
-
return core_1.Cell.fromBoc(Buffer.from(x.bytes,
|
|
281
|
-
case
|
|
282
|
-
return core_1.Cell.fromBoc(Buffer.from(x.bytes,
|
|
283
|
-
case
|
|
288
|
+
case "tvm.cell":
|
|
289
|
+
return core_1.Cell.fromBoc(Buffer.from(x.bytes, "base64"))[0];
|
|
290
|
+
case "tvm.slice":
|
|
291
|
+
return core_1.Cell.fromBoc(Buffer.from(x.bytes, "base64"))[0];
|
|
292
|
+
case "tvm.stackEntryCell":
|
|
284
293
|
return parseStackEntry(x.cell);
|
|
285
|
-
case
|
|
294
|
+
case "tvm.stackEntrySlice":
|
|
286
295
|
return parseStackEntry(x.slice);
|
|
287
|
-
case
|
|
296
|
+
case "tvm.stackEntryTuple":
|
|
288
297
|
return parseStackEntry(x.tuple);
|
|
289
|
-
case
|
|
298
|
+
case "tvm.stackEntryList":
|
|
290
299
|
return parseStackEntry(x.list);
|
|
291
|
-
case
|
|
300
|
+
case "tvm.stackEntryNumber":
|
|
292
301
|
return parseStackEntry(x.number);
|
|
293
|
-
case
|
|
302
|
+
case "tvm.numberDecimal":
|
|
294
303
|
return BigInt(x.number);
|
|
295
304
|
default:
|
|
296
|
-
throw Error(
|
|
305
|
+
throw Error("Unsupported item type: " + typeName);
|
|
297
306
|
}
|
|
298
307
|
}
|
|
299
308
|
function parseStackItem(s) {
|
|
300
|
-
if (s[0] ===
|
|
309
|
+
if (s[0] === "num") {
|
|
301
310
|
let val = s[1];
|
|
302
|
-
if (val.startsWith(
|
|
303
|
-
return { type:
|
|
311
|
+
if (val.startsWith("-")) {
|
|
312
|
+
return { type: "int", value: -BigInt(val.slice(1)) };
|
|
304
313
|
}
|
|
305
314
|
else {
|
|
306
|
-
return { type:
|
|
315
|
+
return { type: "int", value: BigInt(val) };
|
|
307
316
|
}
|
|
308
317
|
}
|
|
309
|
-
else if (s[0] ===
|
|
310
|
-
return { type:
|
|
318
|
+
else if (s[0] === "null") {
|
|
319
|
+
return { type: "null" };
|
|
311
320
|
}
|
|
312
|
-
else if (s[0] ===
|
|
313
|
-
return {
|
|
321
|
+
else if (s[0] === "cell") {
|
|
322
|
+
return {
|
|
323
|
+
type: "cell",
|
|
324
|
+
cell: core_1.Cell.fromBoc(Buffer.from(s[1].bytes, "base64"))[0],
|
|
325
|
+
};
|
|
314
326
|
}
|
|
315
|
-
else if (s[0] ===
|
|
316
|
-
return {
|
|
327
|
+
else if (s[0] === "slice") {
|
|
328
|
+
return {
|
|
329
|
+
type: "slice",
|
|
330
|
+
cell: core_1.Cell.fromBoc(Buffer.from(s[1].bytes, "base64"))[0],
|
|
331
|
+
};
|
|
317
332
|
}
|
|
318
|
-
else if (s[0] ===
|
|
319
|
-
return {
|
|
333
|
+
else if (s[0] === "builder") {
|
|
334
|
+
return {
|
|
335
|
+
type: "builder",
|
|
336
|
+
cell: core_1.Cell.fromBoc(Buffer.from(s[1].bytes, "base64"))[0],
|
|
337
|
+
};
|
|
320
338
|
}
|
|
321
|
-
else if (s[0] ===
|
|
339
|
+
else if (s[0] === "tuple" || s[0] === "list") {
|
|
322
340
|
if (s[1].elements.length === 0) {
|
|
323
|
-
return { type:
|
|
341
|
+
return { type: "null" };
|
|
324
342
|
}
|
|
325
|
-
return { type:
|
|
343
|
+
return { type: "tuple", items: s[1].elements.map(parseStackEntry) };
|
|
326
344
|
}
|
|
327
345
|
else {
|
|
328
|
-
throw Error(
|
|
346
|
+
throw Error("Unsupported stack item type: " + s[0]);
|
|
329
347
|
}
|
|
330
348
|
}
|
|
331
349
|
function parseStack(src) {
|
|
@@ -340,29 +358,34 @@ function createProvider(client, address, init) {
|
|
|
340
358
|
async getState() {
|
|
341
359
|
let state = await client.getContractState(address);
|
|
342
360
|
let balance = state.balance;
|
|
343
|
-
let last = state.lastTransaction
|
|
361
|
+
let last = state.lastTransaction
|
|
362
|
+
? {
|
|
363
|
+
lt: BigInt(state.lastTransaction.lt),
|
|
364
|
+
hash: Buffer.from(state.lastTransaction.hash, "base64"),
|
|
365
|
+
}
|
|
366
|
+
: null;
|
|
344
367
|
let ecMap = null;
|
|
345
368
|
let storage;
|
|
346
|
-
if (state.state ===
|
|
369
|
+
if (state.state === "active") {
|
|
347
370
|
storage = {
|
|
348
|
-
type:
|
|
371
|
+
type: "active",
|
|
349
372
|
code: state.code ? state.code : null,
|
|
350
373
|
data: state.data ? state.data : null,
|
|
351
374
|
};
|
|
352
375
|
}
|
|
353
|
-
else if (state.state ===
|
|
376
|
+
else if (state.state === "uninitialized") {
|
|
354
377
|
storage = {
|
|
355
|
-
type:
|
|
378
|
+
type: "uninit",
|
|
356
379
|
};
|
|
357
380
|
}
|
|
358
|
-
else if (state.state ===
|
|
381
|
+
else if (state.state === "frozen") {
|
|
359
382
|
storage = {
|
|
360
|
-
type:
|
|
383
|
+
type: "frozen",
|
|
361
384
|
stateHash: Buffer.alloc(0),
|
|
362
385
|
};
|
|
363
386
|
}
|
|
364
387
|
else {
|
|
365
|
-
throw Error(
|
|
388
|
+
throw Error("Unsupported state");
|
|
366
389
|
}
|
|
367
390
|
if (state.extra_currencies && state.extra_currencies.length > 0) {
|
|
368
391
|
ecMap = {};
|
|
@@ -378,8 +401,8 @@ function createProvider(client, address, init) {
|
|
|
378
401
|
};
|
|
379
402
|
},
|
|
380
403
|
async get(name, args) {
|
|
381
|
-
if (typeof name !==
|
|
382
|
-
throw new Error(
|
|
404
|
+
if (typeof name !== "string") {
|
|
405
|
+
throw new Error("Method name must be a string for TonClient provider");
|
|
383
406
|
}
|
|
384
407
|
let method = await client.runMethod(address, name, args);
|
|
385
408
|
return { stack: method.stack };
|
|
@@ -389,7 +412,7 @@ function createProvider(client, address, init) {
|
|
|
389
412
|
// Resolve init
|
|
390
413
|
//
|
|
391
414
|
let neededInit = null;
|
|
392
|
-
if (init && !await client.isContractDeployed(address)) {
|
|
415
|
+
if (init && !(await client.isContractDeployed(address))) {
|
|
393
416
|
neededInit = init;
|
|
394
417
|
}
|
|
395
418
|
//
|
|
@@ -398,18 +421,15 @@ function createProvider(client, address, init) {
|
|
|
398
421
|
const ext = (0, core_1.external)({
|
|
399
422
|
to: address,
|
|
400
423
|
init: neededInit,
|
|
401
|
-
body: message
|
|
424
|
+
body: message,
|
|
402
425
|
});
|
|
403
|
-
let boc = (0, core_1.beginCell)()
|
|
404
|
-
.store((0, core_1.storeMessage)(ext))
|
|
405
|
-
.endCell()
|
|
406
|
-
.toBoc();
|
|
426
|
+
let boc = (0, core_1.beginCell)().store((0, core_1.storeMessage)(ext)).endCell().toBoc();
|
|
407
427
|
await client.sendFile(boc);
|
|
408
428
|
},
|
|
409
429
|
async internal(via, message) {
|
|
410
430
|
// Resolve init
|
|
411
431
|
let neededInit = null;
|
|
412
|
-
if (init && (
|
|
432
|
+
if (init && !(await client.isContractDeployed(address))) {
|
|
413
433
|
neededInit = init;
|
|
414
434
|
}
|
|
415
435
|
// Resolve bounce
|
|
@@ -419,7 +439,7 @@ function createProvider(client, address, init) {
|
|
|
419
439
|
}
|
|
420
440
|
// Resolve value
|
|
421
441
|
let value;
|
|
422
|
-
if (typeof message.value ===
|
|
442
|
+
if (typeof message.value === "string") {
|
|
423
443
|
value = (0, core_1.toNano)(message.value);
|
|
424
444
|
}
|
|
425
445
|
else {
|
|
@@ -427,7 +447,7 @@ function createProvider(client, address, init) {
|
|
|
427
447
|
}
|
|
428
448
|
// Resolve body
|
|
429
449
|
let body = null;
|
|
430
|
-
if (typeof message.body ===
|
|
450
|
+
if (typeof message.body === "string") {
|
|
431
451
|
body = (0, core_1.comment)(message.body);
|
|
432
452
|
}
|
|
433
453
|
else if (message.body) {
|
|
@@ -441,14 +461,19 @@ function createProvider(client, address, init) {
|
|
|
441
461
|
sendMode: message.sendMode,
|
|
442
462
|
extracurrency: message.extracurrency,
|
|
443
463
|
init: neededInit,
|
|
444
|
-
body
|
|
464
|
+
body,
|
|
445
465
|
});
|
|
446
466
|
},
|
|
447
467
|
open(contract) {
|
|
448
468
|
return (0, core_1.openContract)(contract, (args) => createProvider(client, args.address, args.init ?? null));
|
|
449
469
|
},
|
|
450
470
|
getTransactions(address, lt, hash, limit) {
|
|
451
|
-
return client.getTransactions(address, {
|
|
452
|
-
|
|
471
|
+
return client.getTransactions(address, {
|
|
472
|
+
limit: limit ?? 100,
|
|
473
|
+
lt: lt.toString(),
|
|
474
|
+
hash: hash.toString("base64"),
|
|
475
|
+
inclusive: true,
|
|
476
|
+
});
|
|
477
|
+
},
|
|
453
478
|
};
|
|
454
479
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { AxiosAdapter, InternalAxiosRequestConfig } from "axios";
|
|
9
9
|
import { Address, Contract, ContractProvider, OpenedContract, StateInit, Transaction, TupleItem, TupleReader } from "@ton/core";
|
|
10
|
-
import { z } from
|
|
10
|
+
import { z } from "zod";
|
|
11
11
|
export type TonClient4Parameters = {
|
|
12
12
|
/**
|
|
13
13
|
* API endpoint
|