Skip to content

Commit d46adfa

Browse files
authored
Merge branch 'main' into pmakhnev/fix-ts-wrapper-with-init
2 parents 2eb5331 + 7f3bb27 commit d46adfa

16 files changed

+279
-7
lines changed

dev-docs/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7878
- Combine all generated FunC code into a single file: PR [#1698](https://github.com/tact-lang/tact/pull/1698)
7979
- Runtime `sha256` now work for arbitrary strings with length >= 128: PR [#1626](https://github.com/tact-lang/tact/pull/1626)
8080
- Generated code in TypeScript wrappers for contract with `init(init: Init)`: PR [#1709](https://github.com/tact-lang/tact/pull/1709)
81+
- Error message for comment (text) receivers with 124 bytes or more: PR [#1711](https://github.com/tact-lang/tact/pull/1711)
8182

8283
### Docs
8384

@@ -113,6 +114,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
113114
- Improved Chinese localization of the documentation: PR [#1642](https://github.com/tact-lang/tact/pull/1642)
114115
- Removed the notion of the non-standard TL-B syntax `remainder<X>`: PR [#1599](https://github.com/tact-lang/tact/pull/1599)
115116
- Added description of `.boc`, `.ts`, `.abi`, `.pkg` files and completed Compilation page: PR [#1676](https://github.com/tact-lang/tact/pull/1676)
117+
- Marked gas-expensive functions and expressions: PR [#1703](https://github.com/tact-lang/tact/pull/1703)
116118

117119
### Release contributors
118120

docs/src/content/docs/book/expressions.mdx

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Expressions
33
description: "This page lists all the expressions in Tact"
44
---
55

6+
import { Badge } from '@astrojs/starlight/components';
7+
68
Every operator in Tact forms an expression, but there's much more to uncover as Tact offers a wide range of expressive options to choose from.
79

810
:::note
@@ -252,6 +254,8 @@ contract ExampleContract {
252254

253255
## `initOf`
254256

257+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
258+
255259
Expression `initOf{:tact}` computes initial state, i.e. `StateInit{:tact}` of a [contract](/book/contracts):
256260

257261
```tact

docs/src/content/docs/book/maps.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ if (fizz == null) {
359359

360360
### Compare with `.deepEquals()` {#deepequals}
361361

362+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/>
362363
<Badge text="Available since Tact 1.5" variant="tip" size="medium"/><p/>
363364

364365
```tact

docs/src/content/docs/book/receive.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ To receive a message of the required type, you need to declare a receiver functi
1515
There are several receiver functions. All receiver functions are processed in the order they are listed below:
1616

1717
* `receive(){:tact}` - called when an empty message is sent to the contract
18-
* `receive("message"){:tact}` - called when a text message with a specific comment is sent to the contract
18+
* `receive("message"){:tact}` - called when a text message with a specific comment is sent to the contract (maximum `"message"{:tact}` length is 123 bytes)
1919
* `receive(str: String){:tact}` - called when an arbitrary text message is sent to the contract
2020
* `receive(msg: MyMessage){:tact}` - called when a binary message of type `MyMessage` is sent to the contract
2121
* `receive(msg: Slice){:tact}` - called when binary message of unknown type is sent to the contract

docs/src/content/docs/ref/core-advanced.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ Attempts to queue more than $255$ messages throw an exception with an [exit code
444444

445445
## nativeSendMessageReturnForwardFee
446446

447+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/>
447448
<Badge text="Available since Tact 1.5" variant="tip" size="medium"/><p/>
448449

449450
```tact

docs/src/content/docs/ref/core-cells.mdx

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ let fizz: Builder = beginCell();
3535

3636
## emptyCell
3737

38+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
39+
3840
```tact
3941
fun emptyCell(): Cell;
4042
```
@@ -52,6 +54,8 @@ fizz == buzz; // true
5254

5355
## emptySlice
5456

57+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
58+
5559
```tact
5660
fun emptySlice(): Slice;
5761
```
@@ -128,6 +132,8 @@ A section to group all extension and extension mutation functions for the [`Buil
128132

129133
### Builder.endCell
130134

135+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
136+
131137
```tact
132138
extends fun endCell(self: Builder): Cell;
133139
```
@@ -1035,6 +1041,8 @@ try {
10351041

10361042
### Slice.hash
10371043

1044+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
1045+
10381046
```tact
10391047
extends fun hash(self: Slice): Int;
10401048
```
@@ -1052,6 +1060,8 @@ let fizz: Int = s.hash();
10521060

10531061
### Slice.asCell
10541062

1063+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
1064+
10551065
```tact
10561066
extends fun asCell(self: Slice): Cell;
10571067
```

docs/src/content/docs/ref/core-common.mdx

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Common
33
description: "Commonly used global static functions from the Core library of Tact"
44
---
55

6+
import { Badge } from '@astrojs/starlight/components';
7+
68
List of the most commonly used built-in [global static functions](/book/functions#global-static-functions).
79

810
## Contextual
@@ -117,6 +119,8 @@ require(ctx.value != 68 + 1, "Invalid amount of nanoToncoins, bye!");
117119

118120
### newAddress
119121

122+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
123+
120124
```tact
121125
fun newAddress(chain: Int, hash: Int): Address;
122126
```
@@ -152,6 +156,8 @@ let oldTonFoundationAddr: Address =
152156

153157
### contractAddress
154158

159+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
160+
155161
```tact
156162
fun contractAddress(s: StateInit): Address;
157163
```
@@ -166,6 +172,8 @@ let foundMeSome: Address = contractAddress(initOf SomeContract());
166172

167173
### contractAddressExt
168174

175+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
176+
169177
```tact
170178
fun contractAddressExt(chain: Int, code: Cell, data: Cell): Address;
171179
```
@@ -196,6 +204,8 @@ let hereBeDragons: Address = contractAddressExt(0, initPkg.code, initPkg.data);
196204

197205
### send
198206

207+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
208+
199209
```tact
200210
fun send(params: SendParameters);
201211
```
@@ -224,6 +234,8 @@ send(SendParameters{
224234

225235
### emit
226236

237+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
238+
227239
```tact
228240
fun emit(body: Cell);
229241
```

docs/src/content/docs/ref/core-debug.mdx

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Debug
33
description: "Various debugging functions from the Core library of Tact"
44
---
55

6+
import { Badge } from '@astrojs/starlight/components';
7+
68
List of functions commonly used for debugging smart contracts in Tact.
79

810
Read more about debugging on the dedicated page: [Debugging](/book/debug).
@@ -40,6 +42,8 @@ try {
4042

4143
## dump
4244

45+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
46+
4347
```tact
4448
fun dump(arg);
4549
```
@@ -102,6 +106,8 @@ dump(emit("msg".asComment())); // As emit() function doesn't return a value, dum
102106

103107
## dumpStack
104108

109+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
110+
105111
```tact
106112
fun dumpStack();
107113
```

docs/src/content/docs/ref/core-math.mdx

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Math
33
description: "Various math helper functions from the Core library of Tact"
44
---
55

6+
import { Badge } from '@astrojs/starlight/components';
7+
68
Various math helper functions.
79

810
## min
@@ -191,6 +193,8 @@ contract Example {
191193

192194
## checkSignature
193195

196+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
197+
194198
```tact
195199
fun checkSignature(hash: Int, signature: Slice, public_key: Int): Bool;
196200
```
@@ -232,6 +236,8 @@ contract Showcase {
232236

233237
## checkDataSignature
234238

239+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
240+
235241
```tact
236242
fun checkDataSignature(data: Slice, signature: Slice, public_key: Int): Bool;
237243
```

docs/src/content/docs/ref/core-strings.mdx

+18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Strings and StringBuilders
33
description: "Various String and StringBuilder functions from the Core library of Tact"
44
---
55

6+
import { Badge } from '@astrojs/starlight/components';
7+
68
Strings are immutable sequences of characters, which means that once a [`String{:tact}`][p] is created, it cannot be changed. Strings are useful to store text, and so they can be converted to [`Cell{:tact}`][cell] type to be used as message bodies.
79

810
To be able to concatenate strings in a gas-efficient way, use a [`StringBuilder{:tact}`][p].
@@ -105,6 +107,8 @@ let fizz: StringBuilder = beginString()
105107

106108
## StringBuilder.toString
107109

110+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
111+
108112
```tact
109113
extends fun toString(self: StringBuilder): String;
110114
```
@@ -122,6 +126,8 @@ let buzz: String = fizz.toString();
122126

123127
## StringBuilder.toCell
124128

129+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
130+
125131
```tact
126132
extends fun toCell(self: StringBuilder): Cell;
127133
```
@@ -139,6 +145,8 @@ let buzz: Cell = fizz.toCell();
139145

140146
## StringBuilder.toSlice
141147

148+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
149+
142150
```tact
143151
extends fun toSlice(self: StringBuilder): Slice;
144152
```
@@ -187,6 +195,8 @@ fizz == buzz; // true, but be careful as it's not always the case
187195

188196
## String.asComment
189197

198+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
199+
190200
```tact
191201
extends fun asComment(self: String): Cell;
192202
```
@@ -277,6 +287,8 @@ let fizz: Slice = s.fromBase64();
277287

278288
## Int.toString
279289

290+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
291+
280292
```tact
281293
extends fun toString(self: Int): String;
282294
```
@@ -293,6 +305,8 @@ let fizz: String = (84 - 42).toString();
293305

294306
## Int.toFloatString
295307

308+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
309+
296310
```tact
297311
extends fun toFloatString(self: Int, digits: Int): String;
298312
```
@@ -311,6 +325,8 @@ let fizz: String = (42).toFloatString(9); // "0.000000042"
311325

312326
## Int.toCoinsString
313327

328+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
329+
314330
```tact
315331
extends fun toCoinsString(self: Int): String;
316332
```
@@ -333,6 +349,8 @@ fizz == buzz; // true, both store "0.000000042"
333349

334350
## Address.toString
335351

352+
<Badge text="Gas-expensive" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>
353+
336354
```tact
337355
extends fun toString(self: Address): String;
338356
```

src/generator/writers/writeRouter.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,21 @@ import { ops } from "./ops";
77
import { resolveFuncType } from "./resolveFuncType";
88
import { resolveFuncTypeUnpack } from "./resolveFuncTypeUnpack";
99
import { writeStatement } from "./writeFunction";
10-
import { AstNumber } from "../../ast/ast";
10+
import { AstNumber, AstReceiver } from "../../ast/ast";
11+
import { throwCompilationError } from "../../error/errors";
12+
13+
export function commentPseudoOpcode(comment: string, ast: AstReceiver): string {
14+
const buffer = Buffer.from(comment, "utf8");
15+
if (buffer.length > 123) {
16+
throwCompilationError(
17+
`receiver message is too long, max length is 123 bytes, but given ${buffer.length}`,
18+
ast.loc,
19+
);
20+
}
1121

12-
export function commentPseudoOpcode(comment: string): string {
1322
return beginCell()
1423
.storeUint(0, 32)
15-
.storeBuffer(Buffer.from(comment, "utf8"))
24+
.storeBuffer(buffer)
1625
.endCell()
1726
.hash()
1827
.toString("hex", 0, 64);
@@ -206,7 +215,10 @@ export function writeRouter(
206215
selector.kind ===
207216
(internal ? "internal-comment" : "external-comment")
208217
) {
209-
const hash = commentPseudoOpcode(selector.comment);
218+
const hash = commentPseudoOpcode(
219+
selector.comment,
220+
r.ast,
221+
);
210222
ctx.append();
211223
ctx.append(
212224
`;; Receive "${selector.comment}" message`,
@@ -365,7 +377,7 @@ export function writeReceiver(
365377
selector.kind === "internal-comment" ||
366378
selector.kind === "external-comment"
367379
) {
368-
const hash = commentPseudoOpcode(selector.comment);
380+
const hash = commentPseudoOpcode(selector.comment, f.ast);
369381
ctx.append(
370382
`(${selfType}, ()) ${ops.receiveText(self.name, selector.kind === "internal-comment" ? "internal" : "external", hash)}(${selfType + " " + funcIdOf("self")}) impure inline {`,
371383
);

0 commit comments

Comments
 (0)