Skip to content
Snippets Groups Projects
Commit 6c8fa3d1 authored by Éloïs's avatar Éloïs
Browse files

feat(runtime): add param FirstIssuableOn

parent 163cb9d3
No related branches found
No related tags found
1 merge request!18Several things
......@@ -30,7 +30,7 @@ pub use types::*;
use crate::traits::*;
use codec::Codec;
use frame_support::traits::{Instance, StorageVersion};
use frame_support::traits::StorageVersion;
use sp_runtime::traits::AtLeast32BitUnsigned;
use sp_std::{fmt::Debug, vec::Vec};
......@@ -390,19 +390,19 @@ pub mod pallet {
Self::remove_cert_inner(issuer, receiver, None);
Ok(().into())
}
}
// PUBLIC FUNCTIONS //
impl<T: Config<I>, I: Instance> Pallet<T, I> {
pub fn on_idty_removed(idty_index: T::IdtyIndex) -> Weight {
let mut total_weight: Weight = 0;
#[pallet::weight(0)]
pub fn remove_all_certs_received_by(
origin: OriginFor<T>,
idty_index: T::IdtyIndex,
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
if let Ok(issuers) = <StorageCertsByReceiver<T, I>>::try_get(idty_index) {
for issuer in issuers {
total_weight += Self::remove_cert_inner(issuer, idty_index, None);
Self::remove_cert_inner(issuer, idty_index, None);
}
}
total_weight
Ok(().into())
}
}
......@@ -491,3 +491,16 @@ impl<T: Config<I>, I: 'static> IsIdtyAllowedToCreateCert<T::IdtyIndex> for Palle
}
}
}
impl<T: Config<I>, I: 'static> SetNextIssuableOn<T::BlockNumber, T::IdtyIndex> for Pallet<T, I> {
fn set_next_issuable_on(
idty_index: T::IdtyIndex,
next_issuable_on: T::BlockNumber,
) -> frame_support::pallet_prelude::Weight {
<StorageIdtyCertMeta<T, I>>::mutate_exists(idty_index, |cert_meta_opt| {
let cert_meta = cert_meta_opt.get_or_insert(IdtyCertMeta::default());
cert_meta.next_issuable_on = next_issuable_on;
});
0
}
}
......@@ -57,3 +57,10 @@ impl<IdtyIndex> OnRemovedCert<IdtyIndex> for () {
0
}
}
pub trait SetNextIssuableOn<BlockNumber, IdtyIndex> {
fn set_next_issuable_on(
idty_index: IdtyIndex,
next_issuable_on: BlockNumber,
) -> frame_support::dispatch::Weight;
}
......@@ -15,7 +15,9 @@
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use crate::entities::IdtyRight;
use crate::BlockNumber;
use frame_support::instances::Instance1;
use frame_support::pallet_prelude::Get;
use frame_support::weights::Weight;
use pallet_identity::traits::IdtyEvent;
......@@ -72,17 +74,28 @@ impl<
}
pub struct OnNewStrongCertHandler<
FirstIssuableOn,
Runtime,
SetNextIssuableOnImpl,
const MIN_STRONG_CERT_FOR_UD: u32,
const MIN_STRONG_CERT_FOR_STRONG_CERT: u32,
>(core::marker::PhantomData<Runtime>);
>(core::marker::PhantomData<(FirstIssuableOn, Runtime, SetNextIssuableOnImpl)>);
impl<
IdtyIndex,
Runtime: pallet_identity::Config<IdtyIndex = IdtyIndex, IdtyRight = IdtyRight>,
FirstIssuableOn: Get<BlockNumber>,
IdtyIndex: Copy,
Runtime: frame_system::Config<BlockNumber = BlockNumber>
+ pallet_identity::Config<IdtyIndex = IdtyIndex, IdtyRight = IdtyRight>,
SetNextIssuableOnImpl: pallet_certification::traits::SetNextIssuableOn<BlockNumber, IdtyIndex>,
const MIN_STRONG_CERT_FOR_UD: u32,
const MIN_STRONG_CERT_FOR_STRONG_CERT: u32,
> pallet_certification::traits::OnNewcert<IdtyIndex>
for OnNewStrongCertHandler<Runtime, MIN_STRONG_CERT_FOR_UD, MIN_STRONG_CERT_FOR_STRONG_CERT>
for OnNewStrongCertHandler<
FirstIssuableOn,
Runtime,
SetNextIssuableOnImpl,
MIN_STRONG_CERT_FOR_UD,
MIN_STRONG_CERT_FOR_STRONG_CERT,
>
{
fn on_new_cert(
_issuer: IdtyIndex,
......@@ -105,6 +118,10 @@ impl<
receiver,
IdtyRight::StrongCert,
);
let _ = SetNextIssuableOnImpl::set_next_issuable_on(
receiver,
frame_system::Pallet::<Runtime>::block_number() + FirstIssuableOn::get(),
);
}
total_weight
}
......
......@@ -212,7 +212,7 @@ macro_rules! pallets_config {
type IdtyIndex = IdtyIndex;
type MaxByIssuer = MaxByIssuer;
type OnNewcert =
OnNewStrongCertHandler<Runtime, MIN_STRONG_CERT_FOR_UD, MIN_STRONG_CERT_FOR_STRONG_CERT>;
OnNewStrongCertHandler<FirstIssuableOn, Runtime, StrongCert, MIN_STRONG_CERT_FOR_UD, MIN_STRONG_CERT_FOR_STRONG_CERT>;
type OnRemovedCert = OnRemovedStrongCertHandler<Runtime, MIN_STRONG_CERT_FOR_UD>;
type CertRenewablePeriod = StrongCertRenewablePeriod;
type ValidityPeriod = ValidityPeriod;
......
......@@ -96,9 +96,10 @@ parameter_types! {
pub const IDTY_CREATE_PERIOD: BlockNumber = 100;
frame_support::parameter_types! {
pub const ConfirmPeriod: BlockNumber = 3 * DAYS;
pub const FirstIssuableOn: BlockNumber = 30* DAYS;
pub const IdtyRenewablePeriod: BlockNumber = 6 * MONTHS;
pub const MaxInactivityPeriod: BlockNumber = YEARS;
pub const MaxNoRightPeriod: BlockNumber = YEARS;
pub const IdtyRenewablePeriod: BlockNumber = 6 * MONTHS;
pub const ValidationPeriod: BlockNumber = YEARS;
}
......
......@@ -199,15 +199,6 @@ common_runtime::runtime_apis! {
impl sp_consensus_babe::BabeApi<Block> for Runtime {
fn configuration() -> sp_consensus_babe::BabeGenesisConfiguration {
unimplemented!()
// TODO: we should return a value or see how can force the client to not call this API
/*sp_consensus_babe::BabeGenesisConfiguration {
slot_duration: 0,
epoch_length: 0,
c: BABE_GENESIS_EPOCH_CONFIG.c,
genesis_authorities: vec![],
randomness: Babe::randomness(),
allowed_slots: BABE_GENESIS_EPOCH_CONFIG.allowed_slots,
}*/
}
fn current_epoch_start() -> sp_consensus_babe::Slot {
......
......@@ -50,9 +50,10 @@ frame_support::parameter_types! {
pub const IDTY_CREATE_PERIOD: BlockNumber = 100;
frame_support::parameter_types! {
pub const ConfirmPeriod: BlockNumber = 12 * HOURS;
pub const FirstIssuableOn: BlockNumber = 10;
pub const IdtyRenewablePeriod: BlockNumber = 6 * MONTHS;
pub const MaxInactivityPeriod: BlockNumber = YEARS;
pub const MaxNoRightPeriod: BlockNumber = YEARS;
pub const IdtyRenewablePeriod: BlockNumber = 6 * MONTHS;
pub const ValidationPeriod: BlockNumber = 2 * MONTHS;
}
......
......@@ -95,9 +95,10 @@ parameter_types! {
pub const IDTY_CREATE_PERIOD: BlockNumber = 100;
frame_support::parameter_types! {
pub const ConfirmPeriod: BlockNumber = DAYS;
pub const FirstIssuableOn: BlockNumber = DAYS;
pub const IdtyRenewablePeriod: BlockNumber = 12 * DAYS;
pub const MaxInactivityPeriod: BlockNumber = 73 * DAYS;
pub const MaxNoRightPeriod: BlockNumber = 73 * DAYS;
pub const IdtyRenewablePeriod: BlockNumber = 12 * DAYS;
pub const ValidationPeriod: BlockNumber = 73 * DAYS;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment