forked from EmelyanenkoK/nominator_pool
-
Notifications
You must be signed in to change notification settings - Fork 3
/
storage.fc
88 lines (82 loc) · 3.42 KB
/
storage.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
;; TLB Storage scheme
;; Note address bits in pseudoaddress is sum of address and workchain,
;; chances of collision and overflow are negligible. -1:00..000 has no ability to
;; stake in pool
;; psevdoAddress#_ address:bits256 = PsevdoAddressInt;
;; nominator_data#_ active_amount:Grams locked_amount:Grams paid_reward_per_gram:Grams = NominatorData;
;; nominators_data#_ dict:(HashmapE PsevdoAddressInt NominatorData) = Nominators;
;;
;; query_id#_ id:uint64 = QueryId;
;; recover_stake_request#47657424 time:uint32 response_query_id:uint64 s_addr:MsgAddressInt = RequestBody;
;; new_stake_request#47657424 time:uint32 response_query_id:uint64 s_addr:MsgAddressInt amount:Grams = RequestBody;
;; requests#_ dict:(HashmapE QueryId ^RequestBody) = Requests;
;;
;; timestamp#_ time:uint32: Timestamp;
;; transfers#_ recent_outgoing:(HashmapE Timestamp Grams) = RecentTransfers;
;;
;; storage#_
;; validator:MsgAddressInt
;; total_active:Grams
;; total_locked:Grams
;; reward_per_gram:int48 ;; NB! not "Grams" since can be negative
;; undistributed_reward:int48
;; validator_reward_share:uint16
;; nominators: Nominators
;; requests: Requests;
;; transfers: (HashmapE Timestamp Grams);
(slice, int, int, int, int, int, cell, cell, cell) load_data () inline {
var ds = get_data().begin_parse();
return (
ds~load_msg_addr(),
ds~load_grams(),
ds~load_grams(),
ds~load_int(48),
ds~load_int(48),
ds~load_uint(16),
ds~load_dict(),
ds~load_dict(),
ds~load_dict()
);
}
() save_data (
slice validator,
int total_active,
int total_locked,
int reward_per_gram,
int undistributed_reward,
int validator_reward_share,
cell nominators,
cell requests,
cell transfers) impure inline {
var st = begin_cell().store_slice(validator)
.store_grams(total_active)
.store_grams(total_locked)
.store_int(reward_per_gram, 48)
.store_int(undistributed_reward, 48)
.store_uint(validator_reward_share, 16)
.store_dict(nominators)
.store_dict(requests)
.store_dict(transfers)
.end_cell();
set_data(st);
}
(int, int, int) get_nominator_data (cell nominators, int workchain, int address_hash, int reward_per_gram) {
int key = workchain + address_hash;
(slice nominator, int found) = nominators.udict_get?(256, key);
if( ~ found) {
return (0, 0, reward_per_gram);
}
return (nominator~load_grams(), nominator~load_grams(), nominator~load_grams());
}
(cell, ()) ~set_nominator_data (cell nominators,
int workchain, int address_hash,
int active, int locked, int paid_reward_per_gram) {
int key = workchain + address_hash;
nominators~udict_set_builder(256, key, begin_cell().store_grams(active)
.store_grams(locked)
.store_grams(paid_reward_per_gram));
return (nominators, ());
}
(cell, ()) ~register_request(cell requests, int query_id, cell request_data) {
return (requests.udict_set_ref(64, query_id, request_data), ());
}