-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutils.func
More file actions
59 lines (46 loc) · 1.4 KB
/
utils.func
File metadata and controls
59 lines (46 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{-
utils.func
Utility library for FunC.
-}
;; private
#include "stdlib.fc";
(int) _::utils::mod(int x, int y) asm "MOD";
(slice) utils::get_contract_address(int workchain, cell state_init) inline {
return begin_cell()
.store_uint(4, 3)
.store_int(workchain, 8)
.store_uint(cell_hash(state_init), 256)
.end_cell().begin_parse();
}
(int) utils::to_ton(int amount) inline {
return amount * 1000000000;
}
(int) utils::from_ton(int amount) inline {
return amount / 1000000000;
}
(int) utils::get_workchain(slice address) inline {
(int wc, _) = parse_var_addr(address);
return wc;
}
;; () utils::force_chain(int workchain, slice address, int error_code) impure inline {
;; (int wc) = get_workchain(address);
;; throw_unless(error_code, wc == workchain);
;; }
(int) utils::get_query_id() inline {
return now() + _::utils::mod(cur_lt(), 4294967296);
}
(slice) utils::get_serialized_address(int workchain, int address) inline {
return (begin_cell()
.store_uint(2, 2) ;; Is std address
.store_uint(0, 1) ;; Non-unicast
.store_uint(workchain, 8) ;; Basic workchain
.store_uint(address, 256) ;; Address hash
).end_cell().begin_parse();
}
_ ~console_log(slice str) impure inline_ref {
slice log = begin_cell()
.store_slice(str)
.end_cell()
.begin_parse();
~strdump_basic(log);
}