@@ -13,9 +13,12 @@ use namada_governance::parameters::GovernanceParameters;
13
13
use namada_macros:: BorshDeserializer ;
14
14
#[ cfg( feature = "migrations" ) ]
15
15
use namada_migrations:: * ;
16
+ use namada_state:: { Result , StorageRead , StorageWrite } ;
16
17
use serde:: Serialize ;
17
18
use thiserror:: Error ;
18
19
20
+ use crate :: storage_key;
21
+
19
22
/// Proof-of-Stake system parameters. This includes parameters that are used in
20
23
/// PoS but are read from other accounts storage (governance).
21
24
#[ derive(
@@ -82,6 +85,343 @@ pub struct OwnedPosParams {
82
85
pub rewards_gain_d : Dec ,
83
86
}
84
87
88
+ /// Read "max_validator_slots" parameter
89
+ pub fn read_max_validator_slots_param < S > ( storage : & S ) -> Result < u64 >
90
+ where
91
+ S : StorageRead ,
92
+ {
93
+ Ok ( storage
94
+ . read ( & storage_key:: param_max_validator_slots_key ( ) ) ?
95
+ . expect ( "Required \" max_validator_slots\" param" ) )
96
+ }
97
+
98
+ /// Read "pipeline_len" parameter
99
+ pub fn read_pipeline_len_param < S > ( storage : & S ) -> Result < u64 >
100
+ where
101
+ S : StorageRead ,
102
+ {
103
+ Ok ( storage
104
+ . read ( & storage_key:: param_pipeline_len_key ( ) ) ?
105
+ . expect ( "Required \" pipeline_len\" param" ) )
106
+ }
107
+
108
+ /// Read "unbonding_len" parameter
109
+ pub fn read_unbonding_len_param < S > ( storage : & S ) -> Result < u64 >
110
+ where
111
+ S : StorageRead ,
112
+ {
113
+ Ok ( storage
114
+ . read ( & storage_key:: param_unbonding_len_key ( ) ) ?
115
+ . expect ( "Required \" unbonding_len\" param" ) )
116
+ }
117
+
118
+ /// Read "tm_votes_per_token" parameter
119
+ pub fn read_tm_votes_per_token_param < S > ( storage : & S ) -> Result < Dec >
120
+ where
121
+ S : StorageRead ,
122
+ {
123
+ Ok ( storage
124
+ . read ( & storage_key:: param_tm_votes_per_token_key ( ) ) ?
125
+ . expect ( "Required \" tm_votes_per_token\" param" ) )
126
+ }
127
+
128
+ /// Read "block_proposer_reward" parameter
129
+ pub fn read_block_proposer_reward_param < S > ( storage : & S ) -> Result < Dec >
130
+ where
131
+ S : StorageRead ,
132
+ {
133
+ Ok ( storage
134
+ . read ( & storage_key:: param_block_proposer_reward_key ( ) ) ?
135
+ . expect ( "Required \" block_proposer_reward\" param" ) )
136
+ }
137
+
138
+ /// Read "block_vote_reward" parameter
139
+ pub fn read_block_vote_reward_param < S > ( storage : & S ) -> Result < Dec >
140
+ where
141
+ S : StorageRead ,
142
+ {
143
+ Ok ( storage
144
+ . read ( & storage_key:: param_block_vote_reward_key ( ) ) ?
145
+ . expect ( "Required \" block_vote_reward\" param" ) )
146
+ }
147
+
148
+ /// Read "max_inflation_rate" parameter
149
+ pub fn read_max_inflation_rate_param < S > ( storage : & S ) -> Result < Dec >
150
+ where
151
+ S : StorageRead ,
152
+ {
153
+ Ok ( storage
154
+ . read ( & storage_key:: param_max_inflation_rate_key ( ) ) ?
155
+ . expect ( "Required \" max_inflation_rate\" param" ) )
156
+ }
157
+
158
+ /// Read "target_staked_ratio" parameter
159
+ pub fn read_target_staked_ratio_param < S > ( storage : & S ) -> Result < Dec >
160
+ where
161
+ S : StorageRead ,
162
+ {
163
+ Ok ( storage
164
+ . read ( & storage_key:: param_target_staked_ratio_key ( ) ) ?
165
+ . expect ( "Required \" target_staked_ratio\" param" ) )
166
+ }
167
+
168
+ /// Read "duplicate_vote_min_slash_rate" parameter
169
+ pub fn read_duplicate_vote_min_slash_rate_param < S > ( storage : & S ) -> Result < Dec >
170
+ where
171
+ S : StorageRead ,
172
+ {
173
+ Ok ( storage
174
+ . read ( & storage_key:: param_duplicate_vote_min_slash_rate_key ( ) ) ?
175
+ . expect ( "Required \" duplicate_vote_min_slash_rate\" param" ) )
176
+ }
177
+
178
+ /// Read "light_client_attack_min_slash_rate" parameter
179
+ pub fn read_light_client_attack_min_slash_rate_param < S > (
180
+ storage : & S ,
181
+ ) -> Result < Dec >
182
+ where
183
+ S : StorageRead ,
184
+ {
185
+ Ok ( storage
186
+ . read ( & storage_key:: param_light_client_attack_min_slash_rate_key ( ) ) ?
187
+ . expect ( "Required \" light_client_attack_min_slash_rate\" param" ) )
188
+ }
189
+
190
+ /// Read "cubic_slashing_window_length" parameter
191
+ pub fn read_cubic_slashing_window_length_param < S > ( storage : & S ) -> Result < u64 >
192
+ where
193
+ S : StorageRead ,
194
+ {
195
+ Ok ( storage
196
+ . read ( & storage_key:: param_cubic_slashing_window_length_key ( ) ) ?
197
+ . expect ( "Required \" cubic_slashing_window_length\" param" ) )
198
+ }
199
+
200
+ /// Read "validator_stake_threshold" parameter
201
+ pub fn read_validator_stake_threshold_param < S > (
202
+ storage : & S ,
203
+ ) -> Result < token:: Amount >
204
+ where
205
+ S : StorageRead ,
206
+ {
207
+ Ok ( storage
208
+ . read ( & storage_key:: param_validator_stake_threshold_key ( ) ) ?
209
+ . expect ( "Required \" validator_stake_threshold\" param" ) )
210
+ }
211
+
212
+ /// Read "liveness_window_check" parameter
213
+ pub fn read_liveness_window_check_param < S > ( storage : & S ) -> Result < u64 >
214
+ where
215
+ S : StorageRead ,
216
+ {
217
+ Ok ( storage
218
+ . read ( & storage_key:: param_liveness_window_check_key ( ) ) ?
219
+ . expect ( "Required \" liveness_window_check\" param" ) )
220
+ }
221
+
222
+ /// Read "liveness_threshold" parameter
223
+ pub fn read_liveness_threshold_param < S > ( storage : & S ) -> Result < Dec >
224
+ where
225
+ S : StorageRead ,
226
+ {
227
+ Ok ( storage
228
+ . read ( & storage_key:: param_liveness_threshold_key ( ) ) ?
229
+ . expect ( "Required \" liveness_threshold\" param" ) )
230
+ }
231
+
232
+ /// Read "rewards_gain_p" parameter
233
+ pub fn read_rewards_gain_p_param < S > ( storage : & S ) -> Result < Dec >
234
+ where
235
+ S : StorageRead ,
236
+ {
237
+ Ok ( storage
238
+ . read ( & storage_key:: param_rewards_gain_p_key ( ) ) ?
239
+ . expect ( "Required \" rewards_gain_p\" param" ) )
240
+ }
241
+
242
+ /// Read "rewards_gain_d" parameter
243
+ pub fn read_rewards_gain_d_param < S > ( storage : & S ) -> Result < Dec >
244
+ where
245
+ S : StorageRead ,
246
+ {
247
+ Ok ( storage
248
+ . read ( & storage_key:: param_rewards_gain_d_key ( ) ) ?
249
+ . expect ( "Required \" rewards_gain_d\" param" ) )
250
+ }
251
+
252
+ /// Write "max_validator_slots" parameter
253
+ pub fn write_max_validator_slots_param < S > (
254
+ storage : & mut S ,
255
+ value : u64 ,
256
+ ) -> Result < ( ) >
257
+ where
258
+ S : StorageWrite + StorageRead ,
259
+ {
260
+ storage. write ( & storage_key:: param_max_validator_slots_key ( ) , value)
261
+ }
262
+
263
+ /// Write "pipeline_len" parameter
264
+ pub fn write_pipeline_len_param < S > ( storage : & mut S , value : u64 ) -> Result < ( ) >
265
+ where
266
+ S : StorageWrite + StorageRead ,
267
+ {
268
+ storage. write ( & storage_key:: param_pipeline_len_key ( ) , value)
269
+ }
270
+
271
+ /// Write "unbonding_len" parameter
272
+ pub fn write_unbonding_len_param < S > ( storage : & mut S , value : u64 ) -> Result < ( ) >
273
+ where
274
+ S : StorageWrite + StorageRead ,
275
+ {
276
+ storage. write ( & storage_key:: param_unbonding_len_key ( ) , value)
277
+ }
278
+
279
+ /// Write "tm_votes_per_token" parameter
280
+ pub fn write_tm_votes_per_token_param < S > (
281
+ storage : & mut S ,
282
+ value : Dec ,
283
+ ) -> Result < ( ) >
284
+ where
285
+ S : StorageWrite + StorageRead ,
286
+ {
287
+ storage. write ( & storage_key:: param_tm_votes_per_token_key ( ) , value)
288
+ }
289
+
290
+ /// Write "block_proposer_reward" parameter
291
+ pub fn write_block_proposer_reward_param < S > (
292
+ storage : & mut S ,
293
+ value : Dec ,
294
+ ) -> Result < ( ) >
295
+ where
296
+ S : StorageWrite + StorageRead ,
297
+ {
298
+ storage. write ( & storage_key:: param_block_proposer_reward_key ( ) , value)
299
+ }
300
+
301
+ /// Write "block_vote_reward" parameter
302
+ pub fn write_block_vote_reward_param < S > (
303
+ storage : & mut S ,
304
+ value : Dec ,
305
+ ) -> Result < ( ) >
306
+ where
307
+ S : StorageWrite + StorageRead ,
308
+ {
309
+ storage. write ( & storage_key:: param_block_vote_reward_key ( ) , value)
310
+ }
311
+
312
+ /// Write "max_inflation_rate" parameter
313
+ pub fn write_max_inflation_rate_param < S > (
314
+ storage : & mut S ,
315
+ value : Dec ,
316
+ ) -> Result < ( ) >
317
+ where
318
+ S : StorageWrite + StorageRead ,
319
+ {
320
+ storage. write ( & storage_key:: param_max_inflation_rate_key ( ) , value)
321
+ }
322
+
323
+ /// Write "target_staked_ratio" parameter
324
+ pub fn write_target_staked_ratio_param < S > (
325
+ storage : & mut S ,
326
+ value : Dec ,
327
+ ) -> Result < ( ) >
328
+ where
329
+ S : StorageWrite + StorageRead ,
330
+ {
331
+ storage. write ( & storage_key:: param_target_staked_ratio_key ( ) , value)
332
+ }
333
+
334
+ /// Write "duplicate_vote_min_slash_rate" parameter
335
+ pub fn write_duplicate_vote_min_slash_rate_param < S > (
336
+ storage : & mut S ,
337
+ value : Dec ,
338
+ ) -> Result < ( ) >
339
+ where
340
+ S : StorageWrite + StorageRead ,
341
+ {
342
+ storage. write (
343
+ & storage_key:: param_duplicate_vote_min_slash_rate_key ( ) ,
344
+ value,
345
+ )
346
+ }
347
+
348
+ /// Write "light_client_attack_min_slash_rate" parameter
349
+ pub fn write_light_client_attack_min_slash_rate_param < S > (
350
+ storage : & mut S ,
351
+ value : Dec ,
352
+ ) -> Result < ( ) >
353
+ where
354
+ S : StorageWrite + StorageRead ,
355
+ {
356
+ storage. write (
357
+ & storage_key:: param_light_client_attack_min_slash_rate_key ( ) ,
358
+ value,
359
+ )
360
+ }
361
+
362
+ /// Write "cubic_slashing_window_length" parameter
363
+ pub fn write_cubic_slashing_window_length_param < S > (
364
+ storage : & mut S ,
365
+ value : u64 ,
366
+ ) -> Result < ( ) >
367
+ where
368
+ S : StorageWrite + StorageRead ,
369
+ {
370
+ storage. write (
371
+ & storage_key:: param_cubic_slashing_window_length_key ( ) ,
372
+ value,
373
+ )
374
+ }
375
+
376
+ /// Write "validator_stake_threshold" parameter
377
+ pub fn write_validator_stake_threshold_param < S > (
378
+ storage : & mut S ,
379
+ value : token:: Amount ,
380
+ ) -> Result < ( ) >
381
+ where
382
+ S : StorageWrite + StorageRead ,
383
+ {
384
+ storage. write ( & storage_key:: param_validator_stake_threshold_key ( ) , value)
385
+ }
386
+
387
+ /// Write "liveness_window_check" parameter
388
+ pub fn write_liveness_window_check_param < S > (
389
+ storage : & mut S ,
390
+ value : u64 ,
391
+ ) -> Result < ( ) >
392
+ where
393
+ S : StorageWrite + StorageRead ,
394
+ {
395
+ storage. write ( & storage_key:: param_liveness_window_check_key ( ) , value)
396
+ }
397
+
398
+ /// Write "liveness_threshold" parameter
399
+ pub fn write_liveness_threshold_param < S > (
400
+ storage : & mut S ,
401
+ value : Dec ,
402
+ ) -> Result < ( ) >
403
+ where
404
+ S : StorageWrite + StorageRead ,
405
+ {
406
+ storage. write ( & storage_key:: param_liveness_threshold_key ( ) , value)
407
+ }
408
+
409
+ /// Write "rewards_gain_p" parameter
410
+ pub fn write_rewards_gain_p_param < S > ( storage : & mut S , value : Dec ) -> Result < ( ) >
411
+ where
412
+ S : StorageWrite + StorageRead ,
413
+ {
414
+ storage. write ( & storage_key:: param_rewards_gain_p_key ( ) , value)
415
+ }
416
+
417
+ /// Write "rewards_gain_d" parameter
418
+ pub fn write_rewards_gain_d_param < S > ( storage : & mut S , value : Dec ) -> Result < ( ) >
419
+ where
420
+ S : StorageWrite + StorageRead ,
421
+ {
422
+ storage. write ( & storage_key:: param_rewards_gain_d_key ( ) , value)
423
+ }
424
+
85
425
impl Default for OwnedPosParams {
86
426
fn default ( ) -> Self {
87
427
Self {
0 commit comments