Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • nodes/rust/duniter-v2s
  • llaq/lc-core-substrate
  • pini-gh/duniter-v2s
  • vincentux/duniter-v2s
  • mildred/duniter-v2s
  • d0p1/duniter-v2s
  • bgallois/duniter-v2s
  • Nicolas80/duniter-v2s
8 results
Show changes
Showing
with 171 additions and 163 deletions
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
// This file is part of Duniter-v2S.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// Duniter-v2S 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,
// Duniter-v2S 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/>.
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::pallet_prelude::*;
......
......@@ -2,7 +2,7 @@
authors = ['librelois <c@elo.tf>']
description = 'Duniter test parameters.'
edition = "2021"
homepage = 'https://substrate.dev'
homepage = 'https://duniter.org'
license = 'AGPL-3.0'
name = 'pallet-duniter-test-parameters'
repository = 'https://git.duniter.org/nodes/rust/duniter-v2s'
......
......@@ -2,7 +2,7 @@
authors = ['librelois <c@elo.tf>']
description = 'Duniter test parameters macro.'
edition = "2021"
homepage = 'https://substrate.dev'
homepage = 'https://duniter.org'
license = 'AGPL-3.0'
name = 'pallet-duniter-test-parameters-macro'
repository = 'https://git.duniter.org/nodes/rust/duniter-v2s'
......
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
// This file is part of Duniter-v2S.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// Duniter-v2S 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,
// Duniter-v2S 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/>.
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![crate_type = "proc-macro"]
extern crate proc_macro;
......
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
// This file is part of Duniter-v2S.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// Duniter-v2S 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,
// Duniter-v2S 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/>.
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![cfg_attr(not(feature = "std"), no_std)]
......
......@@ -2,7 +2,7 @@
authors = ['librelois <c@elo.tf>']
description = 'FRAME pallet duniter wot.'
edition = "2021"
homepage = 'https://substrate.dev'
homepage = 'https://duniter.org'
license = 'AGPL-3.0'
name = 'pallet-duniter-wot'
readme = 'README.md'
......
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
// This file is part of Duniter-v2S.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// Duniter-v2S 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,
// Duniter-v2S 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/>.
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::type_complexity)]
......
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
// This file is part of Duniter-v2S.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// Duniter-v2S 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,
// Duniter-v2S 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/>.
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use super::*;
use crate::{self as pallet_duniter_wot};
......@@ -139,7 +139,6 @@ impl pallet_identity::Config for Test {
parameter_types! {
pub const MembershipPeriod: u64 = 8;
pub const PendingMembershipPeriod: u64 = 3;
pub const RevocationPeriod: u64 = 4;
}
impl pallet_membership::Config<Instance1> for Test {
......@@ -153,7 +152,6 @@ impl pallet_membership::Config<Instance1> for Test {
type MetaData = ();
type OnEvent = DuniterWot;
type PendingMembershipPeriod = PendingMembershipPeriod;
type RevocationPeriod = RevocationPeriod;
}
// Cert
......@@ -195,7 +193,6 @@ impl pallet_duniter_wot::Config<Instance2> for Test {
parameter_types! {
pub const SmithsMembershipPeriod: u64 = 20;
pub const SmithsPendingMembershipPeriod: u64 = 3;
pub const SmithsRevocationPeriod: u64 = 4;
}
impl pallet_membership::Config<Instance2> for Test {
......@@ -209,7 +206,6 @@ impl pallet_membership::Config<Instance2> for Test {
type MetaData = ();
type OnEvent = SmithsSubWot;
type PendingMembershipPeriod = SmithsPendingMembershipPeriod;
type RevocationPeriod = SmithsRevocationPeriod;
}
// SmithsCert
......@@ -347,7 +343,7 @@ pub fn run_to_block(n: u64) {
fn clique_wot(
initial_identities_len: usize,
cert_validity_period: u64,
) -> BTreeMap<IdtyIndex, BTreeMap<IdtyIndex, u64>> {
) -> BTreeMap<IdtyIndex, BTreeMap<IdtyIndex, Option<u64>>> {
let mut certs_by_issuer = BTreeMap::new();
for i in 1..=initial_identities_len {
certs_by_issuer.insert(
......@@ -355,7 +351,7 @@ fn clique_wot(
(1..=initial_identities_len)
.filter_map(|j| {
if i != j {
Some((j as IdtyIndex, cert_validity_period))
Some((j as IdtyIndex, Some(cert_validity_period)))
} else {
None
}
......
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
// This file is part of Duniter-v2S.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// Duniter-v2S 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,
// Duniter-v2S 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/>.
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use crate::mock::*;
use crate::mock::{Identity, System};
......@@ -143,33 +143,6 @@ fn test_smith_member_cant_revoke_its_idty() {
});
}
#[test]
fn test_revoke_smiths_them_rejoin() {
new_test_ext(5, 4).execute_with(|| {
run_to_block(2);
// Dave shoud be able to revoke his smith membership
assert_ok!(SmithsMembership::revoke_membership(
Origin::signed(4),
Some(4)
));
// Dave should not be able to re-request membership before the RevocationPeriod end
run_to_block(3);
assert_noop!(
SmithsMembership::request_membership(Origin::signed(4), ()),
pallet_membership::Error::<Test, crate::Instance2>::MembershipRevokedRecently
);
// At block #6, Dave shoud be able to request smith membership
run_to_block(6);
assert_ok!(SmithsMembership::request_membership(Origin::signed(4), ()));
// Then, Alice should be able to send a smith cert to Dave
assert_ok!(SmithsCert::add_cert(Origin::signed(1), 1, 4));
});
}
#[test]
fn test_create_idty_ok() {
new_test_ext(5, 2).execute_with(|| {
......
......@@ -2,7 +2,7 @@
authors = ['librelois <c@elo.tf>']
description = 'FRAME pallet identity.'
edition = "2021"
homepage = 'https://substrate.dev'
homepage = 'https://duniter.org'
license = 'AGPL-3.0'
name = 'pallet-identity'
readme = 'README.md'
......
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
// This file is part of Duniter-v2S.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// Duniter-v2S 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,
// Duniter-v2S 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/>.
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::type_complexity)]
......@@ -495,8 +495,11 @@ pub mod pallet {
let idty_value = Identities::<T>::get(idty_index).ok_or(Error::<T>::IdtyNotFound)?;
ensure!(
if let Some((ref old_owner_key, _)) = idty_value.old_owner_key {
revocation_key == idty_value.owner_key || &revocation_key == old_owner_key
if let Some((ref old_owner_key, last_change)) = idty_value.old_owner_key {
revocation_key == idty_value.owner_key
|| (&revocation_key == old_owner_key
&& frame_system::Pallet::<T>::block_number()
< last_change + T::ChangeOwnerKeyPeriod::get())
} else {
revocation_key == idty_value.owner_key
},
......@@ -516,7 +519,7 @@ pub mod pallet {
ensure!(
(REVOCATION_PAYLOAD_PREFIX, revocation_payload)
.using_encoded(|bytes| revocation_sig.verify(bytes, &idty_value.owner_key)),
.using_encoded(|bytes| revocation_sig.verify(bytes, &revocation_key)),
Error::<T>::InvalidRevocationSig
);
......
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
// This file is part of Duniter-v2S.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// Duniter-v2S 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,
// Duniter-v2S 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/>.
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use super::*;
use crate::{self as pallet_identity};
......
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
// This file is part of Duniter-v2S.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// Duniter-v2S 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,
// Duniter-v2S 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/>.
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use crate::mock::*;
use crate::{
......@@ -20,8 +20,7 @@ use crate::{
NEW_OWNER_KEY_PAYLOAD_PREFIX, REVOCATION_PAYLOAD_PREFIX,
};
use codec::Encode;
//use frame_support::assert_noop;
use frame_support::{assert_err, assert_ok};
use frame_support::{assert_noop, assert_ok};
use frame_system::{EventRecord, Phase};
use sp_runtime::testing::TestSignature;
......@@ -212,7 +211,7 @@ fn test_change_owner_key() {
assert_eq!(System::sufficients(&10), 0);
// Caller should have an associated identity
assert_err!(
assert_noop!(
Identity::change_owner_key(
Origin::signed(42),
10,
......@@ -222,7 +221,7 @@ fn test_change_owner_key() {
);
// Payload must be signed by the new key
assert_err!(
assert_noop!(
Identity::change_owner_key(
Origin::signed(1),
10,
......@@ -232,7 +231,7 @@ fn test_change_owner_key() {
);
// Payload must be prefixed
assert_err!(
assert_noop!(
Identity::change_owner_key(
Origin::signed(1),
10,
......@@ -242,7 +241,7 @@ fn test_change_owner_key() {
);
// New owner key should not be used by another identity
assert_err!(
assert_noop!(
Identity::change_owner_key(
Origin::signed(1),
2,
......@@ -277,7 +276,7 @@ fn test_change_owner_key() {
// Alice can't re-change her owner key too early
new_key_payload.old_owner_key = &10;
assert_err!(
assert_noop!(
Identity::change_owner_key(
Origin::signed(10),
100,
......@@ -330,6 +329,95 @@ fn test_change_owner_key() {
});
}
#[test]
fn test_idty_revocation_with_old_key() {
new_test_ext(IdentityConfig {
identities: vec![alice()],
})
.execute_with(|| {
let genesis_hash = System::block_hash(0);
let new_key_payload = NewOwnerKeyPayload {
genesis_hash: &genesis_hash,
idty_index: 1u64,
old_owner_key: &1u64,
};
let revocation_payload = RevocationPayload {
idty_index: 1u64,
genesis_hash,
};
// We need to initialize at least one block before any call
run_to_block(1);
// Change alice owner key
assert_ok!(Identity::change_owner_key(
Origin::signed(1),
10,
TestSignature(10, (NEW_OWNER_KEY_PAYLOAD_PREFIX, new_key_payload).encode())
));
assert!(Identity::identity(&1).is_some());
let idty_val = Identity::identity(&1).unwrap();
assert_eq!(idty_val.owner_key, 10);
assert_eq!(idty_val.old_owner_key, Some((1, 1)));
// We should be able to revoke Alice identity with old key
run_to_block(2);
assert_ok!(Identity::revoke_identity(
Origin::signed(42),
1,
1,
TestSignature(1, (REVOCATION_PAYLOAD_PREFIX, revocation_payload).encode())
));
//run_to_block(2 + <Test as crate::Config>::ChangeOwnerKeyPeriod::get());
});
}
#[test]
fn test_idty_revocation_with_old_key_after_old_key_expiration() {
new_test_ext(IdentityConfig {
identities: vec![alice()],
})
.execute_with(|| {
let genesis_hash = System::block_hash(0);
let new_key_payload = NewOwnerKeyPayload {
genesis_hash: &genesis_hash,
idty_index: 1u64,
old_owner_key: &1u64,
};
let revocation_payload = RevocationPayload {
idty_index: 1u64,
genesis_hash,
};
// We need to initialize at least one block before any call
run_to_block(1);
// Change alice owner key
assert_ok!(Identity::change_owner_key(
Origin::signed(1),
10,
TestSignature(10, (NEW_OWNER_KEY_PAYLOAD_PREFIX, new_key_payload).encode())
));
assert!(Identity::identity(&1).is_some());
let idty_val = Identity::identity(&1).unwrap();
assert_eq!(idty_val.owner_key, 10);
assert_eq!(idty_val.old_owner_key, Some((1, 1)));
// We should not be able to revoke Alice identity with old key after ChangeOwnerKeyPeriod
run_to_block(2 + <Test as crate::Config>::ChangeOwnerKeyPeriod::get());
assert_noop!(
Identity::revoke_identity(
Origin::signed(42),
1,
1,
TestSignature(1, (REVOCATION_PAYLOAD_PREFIX, revocation_payload).encode())
),
Error::<Test>::InvalidRevocationKey
);
});
}
#[test]
fn test_idty_revocation() {
new_test_ext(IdentityConfig {
......
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
// This file is part of Duniter-v2S.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// Duniter-v2S 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,
// Duniter-v2S 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/>.
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
use frame_support::pallet_prelude::*;
......
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
// This file is part of Duniter-v2S.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// Duniter-v2S 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,
// Duniter-v2S 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/>.
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
//! Various basic types for use in the identity pallet.
......
......@@ -2,7 +2,7 @@
authors = ['librelois <c@elo.tf>']
description = 'FRAME pallet membership.'
edition = "2021"
homepage = 'https://substrate.dev'
homepage = 'https://duniter.org'
license = 'AGPL-3.0'
name = 'pallet-membership'
readme = 'README.md'
......
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
// This file is part of Duniter-v2S.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// Duniter-v2S 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,
// Duniter-v2S 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/>.
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::type_complexity)]
......@@ -81,9 +81,6 @@ pub mod pallet {
#[pallet::constant]
/// Maximum period (in number of blocks), where an identity can remain pending subscription.
type PendingMembershipPeriod: Get<Self::BlockNumber>;
#[pallet::constant]
/// Minimum duration (in number of blocks between a revocation and a new entry request
type RevocationPeriod: Get<Self::BlockNumber>;
}
// GENESIS STUFF //
......@@ -134,16 +131,6 @@ pub mod pallet {
pub type PendingMembershipsExpireOn<T: Config<I>, I: 'static = ()> =
StorageMap<_, Twox64Concat, T::BlockNumber, Vec<T::IdtyId>, ValueQuery>;
#[pallet::storage]
#[pallet::getter(fn revoked_membership)]
pub type RevokedMembership<T: Config<I>, I: 'static = ()> =
StorageMap<_, Twox64Concat, T::IdtyId, (), OptionQuery>;
#[pallet::storage]
#[pallet::getter(fn revoked_memberships_pruned_on)]
pub type RevokedMembershipsPrunedOn<T: Config<I>, I: 'static = ()> =
StorageMap<_, Twox64Concat, T::BlockNumber, Vec<T::IdtyId>, OptionQuery>;
// EVENTS //
#[pallet::event]
......@@ -193,8 +180,6 @@ pub mod pallet {
OriginNotAllowedToUseIdty,
/// Membership request not found
MembershipRequestNotFound,
/// Membership revoked recently
MembershipRevokedRecently,
}
// HOOKS //
......@@ -203,9 +188,7 @@ pub mod pallet {
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
fn on_initialize(n: T::BlockNumber) -> Weight {
if n > T::BlockNumber::zero() {
Self::expire_pending_memberships(n)
+ Self::expire_memberships(n)
+ Self::prune_revoked_memberships(n)
Self::expire_pending_memberships(n) + Self::expire_memberships(n)
} else {
0
}
......@@ -307,7 +290,10 @@ pub mod pallet {
let idty_id = Self::ensure_origin_and_get_idty_id(origin, maybe_idty_id)?;
// Apply phase
let _ = Self::do_revoke_membership(idty_id);
if Self::remove_membership(&idty_id) {
Self::deposit_event(Event::MembershipRevoked(idty_id));
T::OnEvent::on_event(&sp_membership::Event::MembershipRevoked(idty_id));
}
Ok(().into())
}
......@@ -340,9 +326,6 @@ pub mod pallet {
if Membership::<T, I>::contains_key(&idty_id) {
return Err(Error::<T, I>::MembershipAlreadyAcquired.into());
}
if RevokedMembership::<T, I>::contains_key(&idty_id) {
return Err(Error::<T, I>::MembershipRevokedRecently.into());
}
let block_number = frame_system::pallet::Pallet::<T>::block_number();
let expire_on = block_number + T::PendingMembershipPeriod::get();
......@@ -354,21 +337,6 @@ pub mod pallet {
Ok(().into())
}
pub(super) fn do_revoke_membership(idty_id: T::IdtyId) -> Weight {
if Self::remove_membership(&idty_id) {
if T::RevocationPeriod::get() > Zero::zero() {
let block_number = frame_system::pallet::Pallet::<T>::block_number();
let pruned_on = block_number + T::RevocationPeriod::get();
RevokedMembership::<T, I>::insert(idty_id, ());
RevokedMembershipsPrunedOn::<T, I>::append(pruned_on, idty_id);
}
Self::deposit_event(Event::MembershipRevoked(idty_id));
T::OnEvent::on_event(&sp_membership::Event::MembershipRevoked(idty_id));
}
0
}
fn ensure_origin_and_get_idty_id(
origin: OriginFor<T>,
maybe_idty_id: Option<T::IdtyId>,
......@@ -412,17 +380,6 @@ pub mod pallet {
total_weight
}
fn prune_revoked_memberships(block_number: T::BlockNumber) -> Weight {
let total_weight: Weight = 0;
if let Some(identities_ids) = RevokedMembershipsPrunedOn::<T, I>::take(block_number) {
for idty_id in identities_ids {
RevokedMembership::<T, I>::remove(idty_id);
}
}
total_weight
}
pub(super) fn is_member_inner(idty_id: &T::IdtyId) -> bool {
Membership::<T, I>::contains_key(idty_id)
......
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
// This file is part of Duniter-v2S.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// Duniter-v2S 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,
// Duniter-v2S 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/>.
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use crate::{self as pallet_membership};
use frame_support::{
......@@ -80,7 +80,6 @@ impl system::Config for Test {
parameter_types! {
pub const MembershipPeriod: BlockNumber = 5;
pub const PendingMembershipPeriod: BlockNumber = 3;
pub const RevocationPeriod: BlockNumber = 4;
}
impl pallet_membership::Config for Test {
......@@ -94,7 +93,6 @@ impl pallet_membership::Config for Test {
type MetaData = ();
type OnEvent = ();
type PendingMembershipPeriod = PendingMembershipPeriod;
type RevocationPeriod = RevocationPeriod;
}
// Build genesis storage according to the mock runtime.
......
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
// This file is part of Duniter-v2S.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// Duniter-v2S 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,
// Duniter-v2S 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/>.
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use crate::mock::Event as RuntimeEvent;
use crate::mock::*;
......@@ -113,14 +113,7 @@ fn test_membership_revocation() {
RuntimeEvent::DefaultMembership(Event::MembershipRevoked(0))
);
// Membership 0 can't request membership before the end of RevokePeriod (1 + 4 = 5)
run_to_block(2);
assert_eq!(
DefaultMembership::request_membership(Origin::signed(0), ()),
Err(Error::<Test, _>::MembershipRevokedRecently.into())
);
// Membership 0 can request membership after the end of RevokePeriod (1 + 4 = 5)
// Membership 0 can re-request membership
run_to_block(5);
assert_ok!(DefaultMembership::request_membership(Origin::signed(0), ()),);
assert_eq!(
......
......@@ -2,7 +2,7 @@
authors = ['librelois <c@elo.tf>']
description = 'FRAME pallet oneshot account.'
edition = '2018'
homepage = 'https://substrate.dev'
homepage = 'https://duniter.org'
license = 'AGPL-3.0'
name = 'pallet-oneshot-account'
readme = 'README.md'
......