1
1
// Standard library for Tolk (LGPL licence).
2
2
// It contains common functions that are available out of the box, the user doesn't have to import anything.
3
3
// More specific functions are required to be imported explicitly, like "@stdlib/tvm-dicts".
4
- tolk 0.9
4
+ tolk 0.10
5
5
6
6
/**
7
7
Tuple manipulation primitives.
@@ -54,6 +54,13 @@ fun tupleLast<T>(self: tuple): T
54
54
Mathematical primitives.
55
55
*/
56
56
57
+ /// Converts a constant floating-point string to nanotoncoins.
58
+ /// Example: `ton("0.05")` is equal to 50000000.
59
+ /// Note, that `ton()` requires a constant string; `ton(some_var)` is an error
60
+ @pure
61
+ fun ton(floatString: slice): coins
62
+ builtin;
63
+
57
64
/// Computes the minimum of two integers.
58
65
@pure
59
66
fun min(x: int, y: int): int
@@ -187,6 +194,42 @@ fun commitContractDataAndActions(): void
187
194
Signature checks, hashing, cryptography.
188
195
*/
189
196
197
+ /// Compile-time function that calculates crc32 of a constant string.
198
+ /// Example: `const op = stringCrc32("some_str")` = 4013618352 = 0xEF3AF4B0
199
+ /// Note: stringCrc32(slice_var) does not work! It accepts a constant string and works at compile-time.
200
+ @pure
201
+ fun stringCrc32(constString: slice): int
202
+ builtin;
203
+
204
+ /// Compile-time function that calculates crc16 (XMODEM) of a constant string.
205
+ /// Example: `const op = stringCrc16("some_str")` = 53407 = 0xD09F
206
+ /// Note: stringCrc16(slice_var) does not work! It accepts a constant string and works at compile-time.
207
+ @pure
208
+ fun stringCrc16(constString: slice): int
209
+ builtin;
210
+
211
+ /// Compile-time function that calculates sha256 of a constant string and returns 256-bit integer.
212
+ /// Example: `const hash = stringSha256("some_crypto_key")`
213
+ /// Note: it's a compile-time function, `stringSha256(slice_var)` does not work.
214
+ /// Use `sliceBitsHash` or `sliceHash` (declared below) to hash a slice without/with its refs at runtime.
215
+ @pure
216
+ fun stringSha256(constString: slice): int
217
+ builtin;
218
+
219
+ /// Compile-time function that calculates sha256 of a constant string and takes the first 32 bits.
220
+ /// Example: `const minihash = stringSha256_32("some_crypto_key")`
221
+ /// Note: stringSha256_32(slice_var) does not work! It accepts a constant string and works at compile-time.
222
+ @pure
223
+ fun stringSha256_32(constString: slice): int
224
+ builtin;
225
+
226
+ /// Compile-time function that takes N-chars ascii string and interprets it as a number in base 256.
227
+ /// Example: `const value = stringToBase256("AB")` = 16706 (65*256 + 66)
228
+ /// Note: stringToBase256(slice_var) does not work! It accepts a constant string and works at compile-time.
229
+ @pure
230
+ fun stringToBase256(constString: slice): int
231
+ builtin;
232
+
190
233
/// Computes the representation hash of a `cell` [c] and returns it as a 256-bit unsigned integer `x`.
191
234
/// Useful for signing and checking signatures of arbitrary entities represented by a tree of cells.
192
235
@pure
@@ -203,7 +246,7 @@ fun sliceHash(s: slice): int
203
246
/// Computes sha256 of the data bits of `slice` [s]. If the bit length of `s` is not divisible by eight,
204
247
/// throws a cell underflow exception. The hash value is returned as a 256-bit unsigned integer `x`.
205
248
@pure
206
- fun stringHash (s: slice): int
249
+ fun sliceBitsHash (s: slice): int
207
250
asm "SHA256U";
208
251
209
252
/// Checks the Ed25519-`signature` of a `hash` (a 256-bit unsigned integer, usually computed as the hash of some data)
@@ -333,6 +376,22 @@ fun debugDumpStack(): void
333
376
When you _preload_ some data, you just get the result without mutating the slice.
334
377
*/
335
378
379
+ /// Compile-time function that converts a constant string to TL-encoded MsgAddressInt (TVM slice).
380
+ /// Example: stringAddressToSlice("EQCRDM9h4k3UJdOePPuyX40mCgA4vxge5Dc5vjBR8djbEKC5")
381
+ /// Example: stringAddressToSlice("0:527964d55cfa6eb731f4bfc07e9d025098097ef8505519e853986279bd8400d8")
382
+ /// Note: it's a compile-time function, `stringAddressToSlice(slice_var)` does not work.
383
+ /// Use `parseStandardAddress` to decode a slice at runtime into workchain and hash.
384
+ @pure
385
+ fun stringAddressToSlice(constStringAddress: slice): slice
386
+ builtin;
387
+
388
+ /// Compile-time function that converts a constant hex-encoded string to N/2 bytes.
389
+ /// Example: `const v = stringHexToSlice("abcdef")` = slice with 3 bytes `[ 0xAB, 0xCD, 0xEF ]`
390
+ /// Note: stringHexToSlice(slice_var) does not work! It accepts a constant string and works at compile-time.
391
+ @pure
392
+ fun stringHexToSlice(constStringBytesHex: slice): slice
393
+ builtin;
394
+
336
395
/// Converts a `cell` [c] into a `slice`. Notice that [c] must be either an ordinary cell,
337
396
/// or an exotic cell (see [TVM.pdf](https://ton-blockchain.github.io/docs/tvm.pdf), 3.1.2)
338
397
/// which is automatically loaded to yield an ordinary cell `c'`, converted into a `slice` afterwards.
@@ -386,7 +445,7 @@ fun preloadBits(self: slice, len: int): slice
386
445
387
446
/// Loads serialized amount of Toncoins (any unsigned integer up to `2^120 - 1`).
388
447
@pure
389
- fun loadCoins(mutate self: slice): int
448
+ fun loadCoins(mutate self: slice): coins
390
449
asm( -> 1 0) "LDGRAMS";
391
450
392
451
/// Loads bool (-1 or 0) from a slice
@@ -485,7 +544,7 @@ fun storeSlice(mutate self: builder, s: slice): self
485
544
486
545
/// Stores amount of Toncoins into a builder.
487
546
@pure
488
- fun storeCoins(mutate self: builder, x: int ): self
547
+ fun storeCoins(mutate self: builder, x: coins ): self
489
548
asm "STGRAMS";
490
549
491
550
/// Stores bool (-1 or 0) into a builder.
0 commit comments