-
Notifications
You must be signed in to change notification settings - Fork 9
/
text_utils.fc
104 lines (94 loc) · 3.42 KB
/
text_utils.fc
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
(slice, (int)) ~parse_text_command(slice in_msg) {
int op = 0;
;; 4 possible commands lock, stake, recover, withdraw
int first_char = in_msg~load_uint(8);
if( first_char == 108) { ;; l
throw_unless(505, in_msg~load_uint(24) == 7299947); ;; ock
op = 0x0c0010ff;
}
if( first_char == 114 ) { ;; r
throw_unless(505, in_msg~load_uint(48) == 111477746197874); ;; ecover
op = 0xdead10cc;
}
if( first_char == 115 ) { ;; s
throw_unless(505, in_msg~load_uint(32) == 1952541541); ;; take
op = 0xfeedc0de;
}
if( first_char == 119 ) { ;; w
throw_unless(505, in_msg~load_uint(56) == 29682864265257335); ;; ithdraw
op = 0x006e7bac;
}
return (in_msg, (op));
}
(int, int) encode_number_to_text(int number) {
int len = 0;
int value = 0;
int mult = 1;
do {
(number, int res) = number.divmod(10);
value = value + (res + 48) * mult;
mult = mult * 256;
len = len + 1;
} until (number == 0);
return (len, value);
}
builder store_grams_string(builder msg, int amount) {
(int ceil, int res) = divmod(amount, 1000000000);
(int cl, int cv) = encode_number_to_text(ceil);
msg = msg.store_uint(cv, cl * 8 );
msg = msg.store_uint(46, 8); ;; "."
(int rl, int rv) = encode_number_to_text(res);
repeat( 9 - rl ) {
msg = msg.store_uint(48, 8); ;; " "
}
return msg.store_uint(rv, rl * 8);
}
() send_text_stake_accept_message(slice addr, int stake, int value) impure {
;; int_msg_info$0 ihr_disabled:Bool bounce:Bool bounced:Bool src:MsgAddress -> 011000
var msg = begin_cell()
.store_uint(0x18, 6)
.store_slice(addr)
.store_grams(value)
.store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1)
.store_uint(0, 32)
.store_uint(126943687828768, 48) ;; "stake "
.store_grams_string(stake)
.store_uint(597313372290408539492, 72); ;; " accepted"
send_raw_message(msg.end_cell(), 0);
}
() send_text_lock_accept_message(slice addr, int locked) impure {
;; int_msg_info$0 ihr_disabled:Bool bounce:Bool bounced:Bool src:MsgAddress -> 011000
var msg = begin_cell()
.store_uint(0x18, 6)
.store_slice(addr)
.store_grams(0)
.store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1)
.store_uint(0, 32)
.store_uint(126943687828768, 48) ;; "stake "
.store_grams_string(locked)
.store_uint(9126424919893348, 56); ;; " locked"
send_raw_message(msg.end_cell(), 64);
}
() send_text_withdraw_message(slice addr, int value) impure {
;; int_msg_info$0 ihr_disabled:Bool bounce:Bool bounced:Bool src:MsgAddress -> 011000
var msg = begin_cell()
.store_uint(0x18, 6)
.store_slice(addr)
.store_grams(value)
.store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1)
.store_uint(0, 32)
.store_uint(210982622422653884098403377339833676834051106906582061058449761145002618732, 248); ;; "withdrawal from nomination pool"
send_raw_message(msg.end_cell(), 64);
}
() send_text_withdrawal_not_ready_message(slice addr) impure {
;; int_msg_info$0 ihr_disabled:Bool bounce:Bool bounced:Bool src:MsgAddress -> 011000
var msg = begin_cell()
.store_uint(0x18, 6)
.store_slice(addr)
.store_grams(0)
.store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1)
.store_uint(0, 32)
.store_uint(824150868838491734735072179807152868346860070936417144702106238939065376, 240) ;; "withdraw not ready: wait till "
.store_uint(2461921300960164965008949227431845016418741860, 152); ;; "next elector refund"
send_raw_message(msg.end_cell(), 64);
}