Newer
Older
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
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Substrate-Libre-Currency is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
#![cfg_attr(not(feature = "std"), no_std)]
pub use pallet::*;
pub use types::*;
pub mod types {
use super::{Config, Pallet};
use codec::{Decode, Encode};
use frame_support::pallet_prelude::*;
use pallet_duniter_test_parameters_macro::generate_fields_getters;
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
#[generate_fields_getters]
#[cfg_attr(feature = "std", derive(Deserialize, Serialize))]
#[derive(Encode, Decode, Default, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo)]
pub struct Parameters<
BlockNumber: Default + Parameter,
CertCount: Default + Parameter,
PeriodCount: Default + Parameter,
> {
pub cert_period: BlockNumber,
pub cert_max_by_issuer: CertCount,
pub cert_renewable_period: BlockNumber,
pub cert_validity_period: BlockNumber,
pub idty_confirm_period: BlockNumber,
pub idty_creation_period: BlockNumber,
pub idty_max_no_right_period: BlockNumber,
pub membership_period: BlockNumber,
pub membership_renewable_period: BlockNumber,
pub pending_membership_period: BlockNumber,
pub ud_creation_period: BlockNumber,
pub ud_first_reeval: BlockNumber,
pub ud_reeval_period: PeriodCount,
pub ud_reeval_period_in_blocks: BlockNumber,
pub wot_first_cert_issuable_on: BlockNumber,
pub wot_min_cert_for_ud_right: CertCount,
pub wot_min_cert_for_cert_right: CertCount,
pub wot_min_cert_for_create_idty_right: CertCount,
}
}
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_support::traits::StorageVersion;
/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);
// CONFIG //
#[pallet::config]
pub trait Config: frame_system::Config {
type CertCount: Default + MaybeSerializeDeserialize + Parameter;
type PeriodCount: Default + MaybeSerializeDeserialize + Parameter;
}
// STORAGE //
#[pallet::storage]
#[pallet::getter(fn parameters)]
pub type ParametersStorage<T: Config> =
StorageValue<_, Parameters<T::BlockNumber, T::CertCount, T::PeriodCount>, ValueQuery>;
// GENESIS
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub parameters: Parameters<T::BlockNumber, T::CertCount, T::PeriodCount>,
}
#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self {
parameters: Default::default(),
}
}
}
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {
<ParametersStorage<T>>::put(self.parameters.clone());
}
}
}