-
Notifications
You must be signed in to change notification settings - Fork 9
/
elector_response.fc
68 lines (64 loc) · 3.59 KB
/
elector_response.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
() process_elector_response (int flags, slice in_msg, int msg_value, slice used_proxy) impure {
if( flags & 1) {
;; Should we process bounced (that is errors) responses somehow?
return ();
}
int incoming_op = in_msg~load_uint(32);
int query_id = in_msg~load_uint(64);
(slice _1, int _2, int _3, int _4, int _5, int _6, int _7, cell nominators, cell requests, cell transfers, cell proxies) = load_data();
(cell request_cell, int found) = requests~udict_delete_get_ref?(64, query_id);
throw_unless(201, found);
slice request = request_cell.begin_parse();
int stored_op = request~load_uint(32);
(int time, int response_query_id, slice s_addr) = (request~load_uint(32),request~load_uint(64),request~load_msg_addr());
int receipt_attachment = 10000000;
if ( stored_op == 0x47657424) {
;; Refund stake processing
;; If stake returns correctly op = 0xf96f7324, else 0xfffffffe
;; https://github.com/newton-blockchain/ton/blob/master/crypto/smartcont/elector-code.fc#L403-426
if(incoming_op == 0xf96f7324) {
;; also unoccupy proxy
update_reward_on_stake_return(_1, _2, _3, _4, _5, _6, _7, nominators, requests, transfers, proxies, msg_value, used_proxy);
;; notify sender about success
return send_receipt_message(s_addr, stored_op + 0x10000000, response_query_id, 0, receipt_attachment, 1);
}
save_data(_1, _2, _3, _4, _5, _6, _7, nominators, requests, transfers, proxies);
if(incoming_op == 0xfffffffe) {
return send_receipt_message(s_addr, stored_op + 0x20000000, response_query_id, 0, receipt_attachment, 1);
}
return send_receipt_message(s_addr, stored_op + 0x0000f000, response_query_id, incoming_op, receipt_attachment, 1);
}
if ( stored_op == 0x4e73744b) {
;; New stake processing
;; Possible answers 0xf374484c (on success) and 0xee6f454c (on error)
;; https://github.com/newton-blockchain/ton/blob/master/crypto/smartcont/elector-code.fc#L173
if(incoming_op == 0xf374484c) {
int amount = request~load_grams();
transfers~udict_add_builder?(32, now(), begin_cell().store_grams(amount));
proxies~occupy_proxy(used_proxy);
save_data(_1, _2, _3, _4, _5, _6, _7, nominators, requests, transfers, proxies);
return send_receipt_message(s_addr, stored_op + 0x10000000, response_query_id, 0, receipt_attachment, 1);
}
save_data(_1, _2, _3, _4, _5, _6, _7, nominators, requests, transfers, proxies);
if(incoming_op == 0xee6f454c) {
int error_code = in_msg~load_uint(32);
return send_receipt_message(s_addr, stored_op + 0x20000000, response_query_id, error_code, receipt_attachment, 1);
}
return send_receipt_message(s_addr, stored_op + 0x0000f000, response_query_id, incoming_op, receipt_attachment, 1);
}
if ( stored_op == 0x56744370) {
;; Vote for validator complaint
;; Possible answers are 0xd6745240 + [-3: 2]
;; https://github.com/newton-blockchain/ton/blob/master/crypto/smartcont/elector-code.fc#L581
int base_op = 0xd6745240;
save_data(_1, _2, _3, _4, _5, _6, _7, nominators, requests, transfers, proxies);
if ( (incoming_op == base_op + 1) | (incoming_op == (base_op + 1)) ) {
return send_receipt_message(s_addr, stored_op + 0x10000000, response_query_id, incoming_op - base_op, receipt_attachment, 1);
}
if ( (incoming_op <= base_op) & (incoming_op >= (base_op - 3) )) {
return send_receipt_message(s_addr, stored_op + 0x20000000, response_query_id, base_op - incoming_op, receipt_attachment, 1);
}
return send_receipt_message(s_addr, stored_op + 0x0000f000, response_query_id, incoming_op, receipt_attachment, 1);
}
return ();
}