-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathconfig_params.rs
3637 lines (3244 loc) · 115 KB
/
config_params.rs
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2019-2024 EverX. All Rights Reserved.
*
* Licensed under the SOFTWARE EVALUATION License (the "License"); you may not use
* this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific EVERX DEV software governing permissions and
* limitations under the License.
*/
use crate::{
define_HashmapE,
error::BlockError,
dictionary::hashmapaug::HashmapAugType,
shard::ShardIdent,
shard_accounts::ShardAccounts,
signature::{CryptoSignature, SigPubKey},
types::{ChildCell, ExtraCurrencyCollection, Grams, Number8, Number12, Number16, Number13, Number32},
validators::{ValidatorDescr, ValidatorSet},
Serializable, Deserializable,
BuilderData, Cell, error, fail, BlockIdExt,
HashmapE, HashmapType, IBitstring, Result, SliceData, UInt256, HashmapIterator,
};
#[cfg(test)]
#[path = "tests/test_config_params.rs"]
mod tests;
/*
1.6.3. Quick access through the header of masterchain blocks
_ config_addr:uint256
config:^(Hashmap 32 ^Cell) = ConfigParams;
*/
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ConfigParams {
pub config_addr: UInt256,
pub config_params: HashmapE // <u32, SliceData>
}
impl Default for ConfigParams {
fn default() -> ConfigParams {
Self {
config_addr: UInt256::default(),
config_params: HashmapE::with_bit_len(32)
}
}
}
impl ConfigParams {
/// create new instance ConfigParams
pub fn new() -> Self { Self::default() }
}
impl ConfigParams {
pub const fn with_root(data: Cell) -> Self {
Self {
config_addr: UInt256::ZERO,
config_params: HashmapE::with_hashmap(32, Some(data))
}
}
pub const fn with_address_and_root(config_addr: UInt256, data: Cell) -> Self {
Self {
config_addr,
config_params: HashmapE::with_hashmap(32, Some(data))
}
}
pub const fn with_address_and_params(config_addr: UInt256, data: Option<Cell>) -> Self {
Self {
config_addr,
config_params: HashmapE::with_hashmap(32, data)
}
}
/// get config by index
pub fn config(&self, index: u32) -> Result<Option<ConfigParamEnum>> {
let key = index.write_to_bitstring()?;
if let Some(slice) = self.config_params.get(key)? {
if let Some(cell) = slice.reference_opt(0) {
return Ok(Some(ConfigParamEnum::construct_from_slice_and_number(&mut SliceData::load_cell(cell)?, index)?));
}
}
Ok(None)
}
/// get config by index
pub fn config_present(&self, index: u32) -> Result<bool> {
let key = index.write_to_bitstring()?;
if let Some(slice) = self.config_params.get(key)? {
if slice.remaining_references() != 0 {
return Ok(true)
}
}
Ok(false)
}
/// set config
pub fn set_config(&mut self, config: ConfigParamEnum) -> Result<()> {
let mut value = BuilderData::new();
let index = config.write_to_cell(&mut value)?;
let key = index.write_to_bitstring()?;
self.config_params.set_builder(key, &value)?;
Ok(())
}
pub fn get_smc_tick_tock(&self, smc_addr: &UInt256, accounts: &ShardAccounts) -> Result<usize> {
let account = match accounts.get(smc_addr)? {
Some(shard_account) => shard_account.read_account()?,
None => fail!("Tick-tock smartcontract not found")
};
Ok(account.get_tick_tock().map(|tick_tock| tick_tock.as_usize()).unwrap_or_default())
}
pub fn special_ticktock_smartcontracts(&self, tick_tock: usize, accounts: &ShardAccounts) -> Result<Vec<(UInt256, usize)>> {
let mut vec = Vec::new();
self.fundamental_smc_addr()?.iterate_keys(|key: UInt256| {
let tt = self.get_smc_tick_tock(&key, accounts)?;
if (tick_tock & tt) != 0 {
vec.push((key, tt))
}
Ok(true)
})?;
Ok(vec)
}
//
// Wrappers
//
pub fn config_address(&self) -> Result<UInt256> {
match self.config(0)? {
Some(ConfigParamEnum::ConfigParam0(param)) => Ok(param.config_addr),
_ => fail!("no config smc address in config")
}
}
pub fn elector_address(&self) -> Result<UInt256> {
match self.config(1)? {
Some(ConfigParamEnum::ConfigParam1(param)) => Ok(param.elector_addr),
_ => fail!("no elector address in config")
}
}
pub fn minter_address(&self) -> Result<UInt256> {
let addr = match self.config(2)? {
Some(ConfigParamEnum::ConfigParam2(param)) => param.minter_addr,
_ => match self.config(0)? {
Some(ConfigParamEnum::ConfigParam0(param)) => param.config_addr,
_ => fail!("no minter address in config")
}
};
Ok(addr)
}
pub fn fee_collector_address(&self) -> Result<UInt256> {
let addr = match self.config(3)? {
Some(ConfigParamEnum::ConfigParam3(param)) => param.fee_collector_addr,
_ => match self.config(1)? {
Some(ConfigParamEnum::ConfigParam1(param)) => param.elector_addr,
_ => fail!("no fee collector address in config")
}
};
Ok(addr)
}
// TODO 4 dns_root_addr
pub fn mint_prices(&self) -> Result<ConfigParam6> {
match self.config(6)? {
Some(ConfigParamEnum::ConfigParam6(cp)) => Ok(cp),
_ => fail!("no config 6 (mint prices)")
}
}
pub fn to_mint(&self) -> Result<ExtraCurrencyCollection> {
match self.config(7)? {
Some(ConfigParamEnum::ConfigParam7(cp)) => Ok(cp.to_mint),
_ => fail!("no config 7 (to mint)")
}
}
pub fn get_global_version(&self) -> Result<GlobalVersion> {
match self.config(8)? {
Some(ConfigParamEnum::ConfigParam8(gb)) => Ok(gb.global_version),
_ => fail!("no global version in config")
}
}
pub fn mandatory_params(&self) -> Result<MandatoryParams> {
match self.config(9)? {
Some(ConfigParamEnum::ConfigParam9(mp)) => Ok(mp.mandatory_params),
_ => fail!("no mandatory params in config")
}
}
// TODO 11 ConfigVotingSetup
pub fn workchains(&self) -> Result<Workchains> {
match self.config(12)? {
Some(ConfigParamEnum::ConfigParam12(param)) => Ok(param.workchains),
_ => fail!("Workchains not found in config")
}
}
// TODO 13 compliant #
pub fn block_create_fees(&self, masterchain: bool) -> Result<Grams> {
match self.config(14)? {
Some(ConfigParamEnum::ConfigParam14(param)) => if masterchain {
Ok(param.block_create_fees.masterchain_block_fee)
} else {
Ok(param.block_create_fees.basechain_block_fee)
}
_ => fail!("no block create fee parameter")
}
}
pub fn elector_params(&self) -> Result<ConfigParam15> {
match self.config(15)? {
Some(ConfigParamEnum::ConfigParam15(param)) => Ok(param),
_ => fail!("no elector params in config")
}
}
pub fn validators_count(&self) -> Result<ConfigParam16> {
match self.config(16)? {
Some(ConfigParamEnum::ConfigParam16(param)) => Ok(param),
_ => fail!("no elector params in config")
}
}
pub fn stakes_config(&self) -> Result<ConfigParam17> {
match self.config(17)? {
Some(ConfigParamEnum::ConfigParam17(param)) => Ok(param),
_ => fail!("no stakes params in config")
}
}
// TODO 16 validators count
// TODO 17 stakes config
pub fn storage_prices(&self) -> Result<ConfigParam18> {
match self.config(18)? {
Some(ConfigParamEnum::ConfigParam18(param)) => Ok(param),
_ => fail!("Storage prices not found")
}
}
pub fn gas_prices(&self, is_masterchain: bool) -> Result<GasLimitsPrices> {
if is_masterchain {
if let Some(ConfigParamEnum::ConfigParam20(param)) = self.config(20)? {
return Ok(param)
}
} else if let Some(ConfigParamEnum::ConfigParam21(param)) = self.config(21)? {
return Ok(param)
}
fail!("Gas prices not found")
}
pub fn block_limits(&self, masterchain: bool) -> Result<BlockLimits> {
if masterchain {
if let Some(ConfigParamEnum::ConfigParam22(param)) = self.config(22)? {
return Ok(param)
}
} else if let Some(ConfigParamEnum::ConfigParam23(param)) = self.config(23)? {
return Ok(param)
}
fail!("BlockLimits not found")
}
pub fn fwd_prices(&self, is_masterchain: bool) -> Result<MsgForwardPrices> {
if is_masterchain {
if let Some(ConfigParamEnum::ConfigParam24(param)) = self.config(24)? {
return Ok(param)
}
} else if let Some(ConfigParamEnum::ConfigParam25(param)) = self.config(25)? {
return Ok(param)
}
fail!("Forward prices not found")
}
pub fn catchain_config(&self) -> Result<CatchainConfig> {
match self.config(28)? {
Some(ConfigParamEnum::ConfigParam28(ccc)) => Ok(ccc),
_ => fail!("no CatchainConfig in config_params")
}
}
pub fn consensus_config(&self) -> Result<ConsensusConfig> {
match self.config(29)? {
Some(ConfigParamEnum::ConfigParam29(ConfigParam29{ consensus_config})) => Ok(consensus_config),
_ => fail!("no ConsensusConfig in config_params")
}
}
// TODO 29 consensus config
pub fn fundamental_smc_addr(&self) -> Result<FundamentalSmcAddresses> {
match self.config(31)? {
Some(ConfigParamEnum::ConfigParam31(param)) => Ok(param.fundamental_smc_addr),
_ => fail!("fundamental_smc_addr not found in config")
}
}
pub fn delector_parameters(&self) -> Result<DelectorParams> {
match self.config(30)? {
Some(ConfigParamEnum::ConfigParam30(param)) => Ok(param),
_ => fail!("delector parameters not found in config")
}
}
pub fn prev_validator_set(&self) -> Result<ValidatorSet> {
let vset = match self.config(33)? {
Some(ConfigParamEnum::ConfigParam33(param)) => param.prev_temp_validators,
_ => match self.config(32)? {
Some(ConfigParamEnum::ConfigParam32(param)) => param.prev_validators,
_ => ValidatorSet::default()
}
};
Ok(vset)
}
pub fn prev_validator_set_present(&self) -> Result<bool> {
Ok(self.config_present(33)? || self.config_present(32)?)
}
pub fn validator_set(&self) -> Result<ValidatorSet> {
let vset = match self.config(35)? {
Some(ConfigParamEnum::ConfigParam35(param)) => param.cur_temp_validators,
_ => match self.config(34)? {
Some(ConfigParamEnum::ConfigParam34(param)) => param.cur_validators,
_ => fail!("no validator set in config")
}
};
Ok(vset)
}
pub fn next_validator_set(&self) -> Result<ValidatorSet> {
let vset = match self.config(37)? {
Some(ConfigParamEnum::ConfigParam37(param)) => param.next_temp_validators,
_ => match self.config(36)? {
Some(ConfigParamEnum::ConfigParam36(param)) => param.next_validators,
_ => ValidatorSet::default()
}
};
Ok(vset)
}
pub fn next_validator_set_present(&self) -> Result<bool> {
Ok(self.config_present(37)? || self.config_present(36)?)
}
pub fn read_cur_validator_set_and_cc_conf(&self) -> Result<(ValidatorSet, CatchainConfig)> {
Ok((
self.validator_set()?,
self.catchain_config()?
))
}
pub fn copyleft_config(&self) -> Result<ConfigCopyleft> {
match self.config(42)? {
Some(ConfigParamEnum::ConfigParam42(cp)) => Ok(cp),
_ => fail!("no config 42 (copyleft)")
}
}
pub fn suspended_addresses(&self) -> Result<Option<SuspendedAddresses>> {
match self.config(44)? {
Some(ConfigParamEnum::ConfigParam44(sa)) => Ok(Some(sa)),
None => Ok(None),
_ => fail!("wrong config 44 (suspended addresses)")
}
}
// TODO 39 validator signed temp keys
// ConfigParam58(MeshConfig),
pub fn mesh_config(&self) -> Result<Option<MeshConfig>> {
match self.config(58)? {
Some(ConfigParamEnum::ConfigParam58(mc)) => Ok(Some(mc)),
None => Ok(None),
_ => fail!("wrong config 58 (mesh config)")
}
}
pub fn mesh_config_for(&self, nw_id: i32) -> Result<ConnectedNwConfig> {
self.mesh_config()?
.ok_or_else(|| error!("no mesh config"))?
.get(&nw_id)?
.ok_or_else(|| error!("no mesh config for {}", nw_id))
}
pub fn fast_finality_config(&self) -> Result<FastFinalityConfig> {
match self.config(61)? {
Some(ConfigParamEnum::ConfigParam61(ff)) => Ok(ff),
_ => fail!("no fast finality config")
}
}
// ConfigParam62(SmftConfig)
pub fn smft_parameters(&self) -> Result<SmftParams> {
match self.config(62)? {
Some(ConfigParamEnum::ConfigParam62(param)) => Ok(param),
_ => fail!("smft parameters not found in config")
}
}
}
#[derive(Clone, Copy, Debug)]
#[repr(u64)]
pub enum GlobalCapabilities {
CapNone = 0,
CapIhrEnabled = 0x0000_0000_0001,
CapCreateStatsEnabled = 0x0000_0000_0002,
CapBounceMsgBody = 0x0000_0000_0004,
CapReportVersion = 0x0000_0000_0008,
CapSplitMergeTransactions = 0x0000_0000_0010,
CapShortDequeue = 0x0000_0000_0020,
CapMbppEnabled = 0x0000_0000_0040,
CapFastStorageStat = 0x0000_0000_0080,
CapInitCodeHash = 0x0000_0000_0100,
CapOffHypercube = 0x0000_0000_0200,
CapMycode = 0x0000_0000_0400,
CapSetLibCode = 0x0000_0000_0800,
CapFixTupleIndexBug = 0x0000_0000_1000,
CapRemp = 0x0000_0000_2000,
CapDelections = 0x0000_0000_4000,
CapFullBodyInBounced = 0x0000_0001_0000,
CapStorageFeeToTvm = 0x0000_0002_0000,
CapCopyleft = 0x0000_0004_0000,
CapIndexAccounts = 0x0000_0008_0000,
#[cfg(feature = "gosh")]
CapDiff = 0x0000_0010_0000,
CapsTvmBugfixes2022 = 0x0000_0020_0000, // popsave, exception handler, loops
CapWorkchains = 0x0000_0040_0000,
CapStcontNewFormat = 0x0000_0080_0000, // support old format continuation serialization
CapFastStorageStatBugfix = 0x0000_0100_0000, // calc cell datasize using fast storage stat
CapResolveMerkleCell = 0x0000_0200_0000,
#[cfg(feature = "signature_with_id")]
CapSignatureWithId = 0x0000_0400_0000, // use some predefined id during signature check
CapBounceAfterFailedAction= 0x0000_0800_0000,
#[cfg(feature = "groth")]
CapGroth16 = 0x0000_1000_0000,
CapFeeInGasUnits = 0x0000_2000_0000, // all fees in config are in gas units
CapBigCells = 0x0000_4000_0000,
CapSuspendedList = 0x0000_8000_0000,
CapFastFinality = 0x0001_0000_0000,
CapTvmV19 = 0x0002_0000_0000, // TVM v1.9.x improvemements
CapSmft = 0x0004_0000_0000,
CapNoSplitOutQueue = 0x0008_0000_0000, // Don't split out queue on shard splitting
CapUndeletableAccounts = 0x0010_0000_0000, // Don't delete frozen accounts
CapTvmV20 = 0x0020_0000_0000, // BLS instructions
CapDuePaymentFix = 0x0040_0000_0000, // No due payments on credit phase and add payed dues to storage fee in TVM
CapCommonMessage = 0x0080_0000_0000,
CapPipeline = 0x0100_0000_0000,
}
impl ConfigParams {
pub fn get_lt_align(&self) -> u64 {
1_000_000
}
pub fn get_max_lt_growth_fast_finality(&self) -> u64 {
100 * self.get_lt_align() - 1
}
pub fn get_max_lt_growth(&self) -> u64 {
10 * self.get_lt_align() - 1
}
pub fn get_next_block_lt(&self, prev_block_lt: u64) -> u64 {
(prev_block_lt / self.get_lt_align() + 1) * self.get_lt_align()
}
pub fn has_capabilities(&self) -> bool {
self.get_global_version().map_or(false, |gb| gb.capabilities != 0)
}
pub fn has_capability(&self, capability: GlobalCapabilities) -> bool {
self.get_global_version().map_or(false, |gb| gb.has_capability(capability))
}
pub fn capabilities(&self) -> u64 {
self.get_global_version().map_or(0, |gb| gb.capabilities)
}
pub fn global_version(&self) -> u32 {
self.get_global_version().map_or(0, |gb| gb.version)
}
}
impl ConfigParams {
pub fn compute_validator_set_cc(&self, shard: &ShardIdent, at: u32, cc_seqno: u32, cc_seqno_delta: &mut u32) -> Result<Vec<ValidatorDescr>> {
let (vset, ccc) = self.read_cur_validator_set_and_cc_conf()?;
if (*cc_seqno_delta & 0xfffffffe) != 0 {
fail!("seqno_delta>1 is not implemented yet");
}
*cc_seqno_delta += cc_seqno;
vset.calc_subset(&ccc, shard.shard_prefix_with_tag(), shard.workchain_id(), *cc_seqno_delta, at.into())
.map(|(set, _hash)| {
set
})
}
pub fn compute_validator_set(&self, shard: &ShardIdent, _at: u32, cc_seqno: u32) -> Result<Vec<ValidatorDescr>> {
let (vset, ccc) = self.read_cur_validator_set_and_cc_conf()?;
vset.calc_subset(&ccc, shard.shard_prefix_with_tag(), shard.workchain_id(), cc_seqno, _at.into())
.map(|(set, _seq_no)| set)
}
}
const MANDATORY_CONFIG_PARAMS: [u32; 9] = [18, 20, 21, 22, 23, 24, 25, 28, 34];
impl ConfigParams {
pub fn valid_config_data(&self, relax_par0: bool, mparams: Option<MandatoryParams>) -> Result<bool> {
if !relax_par0 {
match self.config(0) {
Ok(Some(ConfigParamEnum::ConfigParam0(param))) if param.config_addr == self.config_addr => (),
_ => return Ok(false)
}
}
// porting from Durov's code
// previously was not 9 parameter in config params
for index in &MANDATORY_CONFIG_PARAMS {
if self.config(*index)?.is_none() {
log::error!(target: "block", "configuration parameter #{} \
(hardcoded as mandatory) is missing)", index);
return Ok(false)
}
}
let result = match self.config(9) {
Ok(Some(ConfigParamEnum::ConfigParam9(param))) => self.config_params_present(Some(param.mandatory_params))?,
_ => {
log::error!(target: "block", "invalid mandatory parameters dictionary while checking \
existence of all mandatory configuration parameters");
false
}
};
Ok(result && self.config_params_present(mparams)?)
}
fn config_params_present(&self, params: Option<MandatoryParams>) -> Result<bool> {
match params {
Some(params) => params.iterate_keys(|index: u32| match self.config(index) {
Ok(Some(_)) => Ok(true),
_ => {
log::error!(target: "block", "configuration parameter #{} \
(declared as mandatory in configuration parameter #9) is missing)", index);
Ok(false)
}
}),
None => Ok(true)
}
}
// when these parameters change, the block must be marked as a key block
pub fn important_config_parameters_changed(&self, other: &ConfigParams, coarse: bool) -> Result<bool> {
if self.config_params == other.config_params {
return Ok(false)
}
if coarse {
return Ok(true)
}
// for now, all parameters are "important"
// at least the parameters affecting the computations of validator sets must be considered important
// ...
Ok(true)
}
}
impl Deserializable for ConfigParams {
fn read_from(&mut self, cell: &mut SliceData) -> Result<()> {
self.config_addr.read_from(cell)?;
*self.config_params.data_mut() = Some(cell.checked_drain_reference()?);
Ok(())
}
}
impl Serializable for ConfigParams {
fn write_to(&self, cell: &mut BuilderData) -> Result<()> {
cell.checked_append_reference(self.config_params.data().cloned().unwrap_or_default())?;
self.config_addr.write_to(cell)?;
Ok(())
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ConfigParamEnum {
ConfigParam0(ConfigParam0),
ConfigParam1(ConfigParam1),
ConfigParam2(ConfigParam2),
ConfigParam3(ConfigParam3),
ConfigParam4(ConfigParam4),
ConfigParam5(ConfigParam5),
ConfigParam6(ConfigParam6),
ConfigParam7(ConfigParam7),
ConfigParam8(ConfigParam8),
ConfigParam9(ConfigParam9),
ConfigParam10(ConfigParam10),
ConfigParam11(ConfigParam11),
ConfigParam12(ConfigParam12),
ConfigParam13(ConfigParam13),
ConfigParam14(ConfigParam14),
ConfigParam15(ConfigParam15),
ConfigParam16(ConfigParam16),
ConfigParam17(ConfigParam17),
ConfigParam18(ConfigParam18),
ConfigParam20(GasLimitsPrices),
ConfigParam21(GasLimitsPrices),
ConfigParam22(ConfigParam22),
ConfigParam23(ConfigParam23),
ConfigParam24(MsgForwardPrices),
ConfigParam25(MsgForwardPrices),
ConfigParam28(CatchainConfig),
ConfigParam29(ConfigParam29),
ConfigParam30(DelectorParams),
ConfigParam31(ConfigParam31),
ConfigParam32(ConfigParam32),
ConfigParam33(ConfigParam33),
ConfigParam34(ConfigParam34),
ConfigParam35(ConfigParam35),
ConfigParam36(ConfigParam36),
ConfigParam37(ConfigParam37),
ConfigParam39(ConfigParam39),
ConfigParam40(ConfigParam40),
ConfigParam42(ConfigCopyleft),
ConfigParam44(SuspendedAddresses),
ConfigParam58(MeshConfig),
ConfigParam61(FastFinalityConfig),
ConfigParam62(SmftParams),
ConfigParamAny(u32, SliceData),
}
macro_rules! read_config {
( $cpname:ident, $cname:ident, $slice:expr ) => {
{
let c = $cname::construct_from($slice)?;
Ok(ConfigParamEnum::$cpname(c))
}
}
}
impl ConfigParamEnum {
pub fn construct_from_cell_and_number(cell: Cell, index: u32) -> Result<ConfigParamEnum> {
Self::construct_from_slice_and_number(&mut SliceData::load_cell(cell)?, index)
}
/// read config from cell
pub fn construct_from_slice_and_number(slice: &mut SliceData, index: u32) -> Result<ConfigParamEnum> {
match index {
0 => { read_config!(ConfigParam0, ConfigParam0, slice) },
1 => { read_config!(ConfigParam1, ConfigParam1, slice) },
2 => { read_config!(ConfigParam2, ConfigParam2, slice) },
3 => { read_config!(ConfigParam3, ConfigParam3, slice) },
4 => { read_config!(ConfigParam4, ConfigParam4, slice) },
5 => { read_config!(ConfigParam5, ConfigParam5, slice) },
6 => { read_config!(ConfigParam6, ConfigParam6, slice) },
7 => { read_config!(ConfigParam7, ConfigParam7, slice) },
8 => { read_config!(ConfigParam8, ConfigParam8, slice) },
9 => { read_config!(ConfigParam9, ConfigParam9, slice) },
10 => { read_config!(ConfigParam10, ConfigParam10, slice) },
11 => { read_config!(ConfigParam11, ConfigParam11, slice) },
12 => { read_config!(ConfigParam12, ConfigParam12, slice) },
13 => { read_config!(ConfigParam13, ConfigParam13, slice) },
14 => { read_config!(ConfigParam14, ConfigParam14, slice) },
15 => { read_config!(ConfigParam15, ConfigParam15, slice) },
16 => { read_config!(ConfigParam16, ConfigParam16, slice) },
17 => { read_config!(ConfigParam17, ConfigParam17, slice) },
18 => { read_config!(ConfigParam18, ConfigParam18, slice) },
20 => { read_config!(ConfigParam20, GasLimitsPrices, slice) },
21 => { read_config!(ConfigParam21, GasLimitsPrices, slice) },
22 => { read_config!(ConfigParam22, ConfigParam22, slice) },
23 => { read_config!(ConfigParam23, ConfigParam23, slice) },
24 => { read_config!(ConfigParam24, MsgForwardPrices, slice) },
25 => { read_config!(ConfigParam25, MsgForwardPrices, slice) },
28 => { read_config!(ConfigParam28, CatchainConfig, slice) },
29 => { read_config!(ConfigParam29, ConfigParam29, slice) },
30 => { read_config!(ConfigParam30, DelectorParams, slice) },
31 => { read_config!(ConfigParam31, ConfigParam31, slice) },
32 => { read_config!(ConfigParam32, ConfigParam32, slice) },
33 => { read_config!(ConfigParam33, ConfigParam33, slice) },
34 => { read_config!(ConfigParam34, ConfigParam34, slice) },
35 => { read_config!(ConfigParam35, ConfigParam35, slice) },
36 => { read_config!(ConfigParam36, ConfigParam36, slice) },
37 => { read_config!(ConfigParam37, ConfigParam37, slice) },
39 => { read_config!(ConfigParam39, ConfigParam39, slice) },
40 => { read_config!(ConfigParam40, ConfigParam40, slice) },
42 => { read_config!(ConfigParam42, ConfigCopyleft, slice) },
44 => { read_config!(ConfigParam44, SuspendedAddresses, slice) },
58 => { read_config!(ConfigParam58, MeshConfig, slice) },
61 => { read_config!(ConfigParam61, FastFinalityConfig, slice) },
62 => { read_config!(ConfigParam62, SmftParams, slice) },
index => Ok(ConfigParamEnum::ConfigParamAny(index, slice.clone())),
}
}
/// Save config to cell
pub fn write_to_cell(&self, cell: &mut BuilderData) -> Result<u32> {
match self {
ConfigParamEnum::ConfigParam0(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(0)},
ConfigParamEnum::ConfigParam1(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(1)},
ConfigParamEnum::ConfigParam2(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(2)},
ConfigParamEnum::ConfigParam3(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(3)},
ConfigParamEnum::ConfigParam4(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(4)},
ConfigParamEnum::ConfigParam5(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(5)},
ConfigParamEnum::ConfigParam6(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(6)},
ConfigParamEnum::ConfigParam7(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(7)},
ConfigParamEnum::ConfigParam8(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(8)},
ConfigParamEnum::ConfigParam9(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(9)},
ConfigParamEnum::ConfigParam10(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(10)},
ConfigParamEnum::ConfigParam11(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(11)},
ConfigParamEnum::ConfigParam12(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(12)},
ConfigParamEnum::ConfigParam13(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(13)},
ConfigParamEnum::ConfigParam14(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(14)},
ConfigParamEnum::ConfigParam15(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(15)},
ConfigParamEnum::ConfigParam16(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(16)},
ConfigParamEnum::ConfigParam17(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(17)},
ConfigParamEnum::ConfigParam18(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(18)},
ConfigParamEnum::ConfigParam20(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(20)},
ConfigParamEnum::ConfigParam21(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(21)},
ConfigParamEnum::ConfigParam22(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(22)},
ConfigParamEnum::ConfigParam23(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(23)},
ConfigParamEnum::ConfigParam24(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(24)},
ConfigParamEnum::ConfigParam25(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(25)},
ConfigParamEnum::ConfigParam28(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(28)},
ConfigParamEnum::ConfigParam29(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(29)},
ConfigParamEnum::ConfigParam30(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(30)},
ConfigParamEnum::ConfigParam31(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(31)},
ConfigParamEnum::ConfigParam32(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(32)},
ConfigParamEnum::ConfigParam33(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(33)},
ConfigParamEnum::ConfigParam34(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(34)},
ConfigParamEnum::ConfigParam35(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(35)},
ConfigParamEnum::ConfigParam36(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(36)},
ConfigParamEnum::ConfigParam37(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(37)},
ConfigParamEnum::ConfigParam39(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(39)},
ConfigParamEnum::ConfigParam40(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(40)},
ConfigParamEnum::ConfigParam42(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(42)},
ConfigParamEnum::ConfigParam44(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(44)},
ConfigParamEnum::ConfigParam58(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(58)},
ConfigParamEnum::ConfigParam61(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(61)},
ConfigParamEnum::ConfigParam62(ref c) => { cell.checked_append_reference(c.serialize()?)?; Ok(62)},
ConfigParamEnum::ConfigParamAny(index, slice) => {
cell.checked_append_reference(slice.clone().into_cell())?;
Ok(*index)
},
}
}
}
/*
_ config_addr:bits256 = ConfigParam 0;
*/
///
/// Config Param 0 structure
///
#[derive(Clone, Debug, Eq, PartialEq, Default)]
pub struct ConfigParam0 {
pub config_addr: UInt256,
}
impl ConfigParam0 {
pub fn new() -> Self { Self::default() }
}
impl Deserializable for ConfigParam0 {
fn read_from(&mut self, cell: &mut SliceData) -> Result<()> {
self.config_addr.read_from(cell)?;
Ok(())
}
}
impl Serializable for ConfigParam0 {
fn write_to(&self, cell: &mut BuilderData) -> Result<()> {
self.config_addr.write_to(cell)?;
Ok(())
}
}
/*
_ elector_addr:bits256 = ConfigParam 1;
*/
///
/// Config Param 1 structure
///
#[derive(Clone, Debug, Eq, PartialEq, Default)]
pub struct ConfigParam1 {
pub elector_addr: UInt256,
}
impl ConfigParam1 {
pub fn new() -> Self { Self::default() }
}
impl Deserializable for ConfigParam1 {
fn read_from(&mut self, cell: &mut SliceData) -> Result<()> {
self.elector_addr.read_from(cell)?;
Ok(())
}
}
impl Serializable for ConfigParam1 {
fn write_to(&self, cell: &mut BuilderData) -> Result<()> {
self.elector_addr.write_to(cell)?;
Ok(())
}
}
///
/// Config Param 2 structure
///
#[derive(Clone, Debug, Eq, PartialEq, Default)]
pub struct ConfigParam2 {
pub minter_addr: UInt256,
}
impl ConfigParam2 {
pub fn new() -> Self { Self::default() }
}
impl Deserializable for ConfigParam2 {
fn read_from(&mut self, cell: &mut SliceData) -> Result<()> {
self.minter_addr.read_from(cell)?;
Ok(())
}
}
impl Serializable for ConfigParam2 {
fn write_to(&self, cell: &mut BuilderData) -> Result<()> {
self.minter_addr.write_to(cell)?;
Ok(())
}
}
///
/// Config Param 3 structure
///
#[derive(Clone, Debug, Eq, PartialEq, Default)]
pub struct ConfigParam3 {
pub fee_collector_addr: UInt256,
}
impl ConfigParam3 {
pub fn new() -> Self { Self::default() }
}
impl Deserializable for ConfigParam3 {
fn read_from(&mut self, cell: &mut SliceData) -> Result<()> {
self.fee_collector_addr.read_from(cell)?;
Ok(())
}
}
impl Serializable for ConfigParam3 {
fn write_to(&self, cell: &mut BuilderData) -> Result<()> {
self.fee_collector_addr.write_to(cell)?;
Ok(())
}
}
///
/// Config Param 4 structure
///
#[derive(Clone, Debug, Eq, PartialEq, Default)]
pub struct ConfigParam4 {
pub dns_root_addr: UInt256,
}
impl ConfigParam4 {
pub fn new() -> Self { Self::default() }
}
impl Deserializable for ConfigParam4 {
fn read_from(&mut self, cell: &mut SliceData) -> Result<()> {
self.dns_root_addr.read_from(cell)?;
Ok(())
}
}
impl Serializable for ConfigParam4 {
fn write_to(&self, cell: &mut BuilderData) -> Result<()> {
self.dns_root_addr.write_to(cell)?;
Ok(())
}
}
///
/// Config Param 5 structure
///
#[derive(Clone, Debug, Eq, PartialEq, Default)]
pub struct ConfigParam5 {
pub owner_addr: UInt256,
}
impl Deserializable for ConfigParam5 {
fn construct_from(slice: &mut SliceData) -> Result<Self> {
let owner_addr = Deserializable::construct_from(slice)?;
Ok(ConfigParam5 { owner_addr })
}
}
impl Serializable for ConfigParam5 {
fn write_to(&self, cell: &mut BuilderData) -> Result<()> {
self.owner_addr.write_to(cell)?;
Ok(())
}
}
///
/// Config Param 6 structure
///
#[derive(Clone, Debug, Eq, PartialEq, Default)]
pub struct ConfigParam6 {
pub mint_new_price: Grams,
pub mint_add_price: Grams,
}
impl ConfigParam6 {
pub fn new() -> Self { Self::default() }
}
impl Deserializable for ConfigParam6 {
fn read_from(&mut self, cell: &mut SliceData) -> Result<()> {
self.mint_new_price.read_from(cell)?;
self.mint_add_price.read_from(cell)?;
Ok(())
}
}
impl Serializable for ConfigParam6 {
fn write_to(&self, cell: &mut BuilderData) -> Result<()> {
self.mint_new_price.write_to(cell)?;
self.mint_add_price.write_to(cell)?;
Ok(())
}
}
///
/// Config Param 7 structure
///
#[derive(Clone, Default, Debug, Eq, PartialEq)]
pub struct ConfigParam7 {
pub to_mint: ExtraCurrencyCollection,
}
impl ConfigParam7 {
pub fn new() -> Self { Self::default() }
}
impl Deserializable for ConfigParam7 {
fn read_from(&mut self, cell: &mut SliceData) -> Result<()> {
self.to_mint.read_from(cell)?;
Ok(())
}
}
impl Serializable for ConfigParam7 {
fn write_to(&self, cell: &mut BuilderData) -> Result<()> {
self.to_mint.write_to(cell)?;
Ok(())
}
}
///
/// Config Param 8 structure
///
// capabilities#c4 version:uint32 capabilities:uint64 = GlobalVersion;
// _ GlobalVersion = ConfigParam 8; // all zero if absent
#[derive(Clone, Debug, Eq, PartialEq, Default)]
pub struct GlobalVersion {
pub version: u32,
pub capabilities: u64,
}
impl GlobalVersion {
pub fn new() -> Self { Self::default() }
pub fn has_capability(&self, capability: GlobalCapabilities) -> bool {
(self.capabilities & (capability as u64)) != 0
}
}
const GLOBAL_VERSION_TAG: u8 = 0xC4;
impl Deserializable for GlobalVersion {
fn read_from(&mut self, cell: &mut SliceData) -> Result<()> {
let tag = cell.get_next_byte()?;
if tag != GLOBAL_VERSION_TAG {
fail!(
BlockError::InvalidConstructorTag {
t: tag as u32,
s: std::any::type_name::<Self>().to_string()
}
)
}
self.version.read_from(cell)?;
self.capabilities.read_from(cell)?;
Ok(())
}
}
impl Serializable for GlobalVersion {
fn write_to(&self, cell: &mut BuilderData) -> Result<()> {
cell.append_u8(GLOBAL_VERSION_TAG)?;
self.version.write_to(cell)?;
self.capabilities.write_to(cell)?;
Ok(())
}
}
#[derive(Clone, Debug, Eq, PartialEq, Default)]
pub struct ConfigParam8 {
pub global_version: GlobalVersion
}
impl ConfigParam8 {
pub fn new() -> Self { Self::default() }
}
impl Deserializable for ConfigParam8 {
fn read_from(&mut self, cell: &mut SliceData) -> Result<()> {
self.global_version.read_from(cell)?;
Ok(())
}
}
impl Serializable for ConfigParam8 {
fn write_to(&self, cell: &mut BuilderData) -> Result<()> {
self.global_version.write_to(cell)?;
Ok(())
}
}
// _ mandatory_params:(Hashmap 32 True) = ConfigParam 9;
define_HashmapE!{MandatoryParams, 32, ()}
///
/// Config Param 9 structure
///