-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade registrations and unregister (#254)
* make unregistering generic * implement registration upgrading * implement unregistering * add benchmarks and weights * use .ok_or * move _unregister to storage_helper * use register_participant extrinsic in tests * introduce is_registering_or_attesting * use ok_or * estend tests Co-authored-by: clangenb <37865735+clangenb@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
681 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use codec::{Decode, EncodeLike}; | ||
use encointer_primitives::{ | ||
ceremonies::{CommunityCeremony, ParticipantIndexType}, | ||
communities::CommunityIdentifier, | ||
scheduler::CeremonyIndexType, | ||
}; | ||
pub fn remove_participant_from_registry<Index, Registry, Count, AccountId>( | ||
cid: CommunityIdentifier, | ||
cindex: CeremonyIndexType, | ||
participant: &AccountId, | ||
) where | ||
Index: frame_support::StorageDoubleMap< | ||
CommunityCeremony, | ||
AccountId, | ||
ParticipantIndexType, | ||
Query = ParticipantIndexType, | ||
>, | ||
Registry: frame_support::StorageDoubleMap< | ||
CommunityCeremony, | ||
ParticipantIndexType, | ||
AccountId, | ||
Query = Option<AccountId>, | ||
>, | ||
Count: frame_support::StorageMap< | ||
CommunityCeremony, | ||
ParticipantIndexType, | ||
Query = ParticipantIndexType, | ||
>, | ||
AccountId: EncodeLike + Decode, | ||
{ | ||
let participant_count = Count::get((cid, cindex)); | ||
let participant_index = Index::get((cid, cindex), &participant); | ||
let maybe_last_participant = Registry::get((cid, cindex), participant_count); | ||
|
||
if let Some(last_participant) = maybe_last_participant { | ||
Registry::insert((cid, cindex), participant_index, &last_participant); | ||
Index::insert((cid, cindex), last_participant, participant_index); | ||
|
||
Registry::remove((cid, cindex), participant_count); | ||
Index::remove((cid, cindex), &participant); | ||
|
||
Count::insert((cid, cindex), participant_count.saturating_sub(1)); | ||
} | ||
} |
Oops, something went wrong.