Skip to content
Snippets Groups Projects
Commit 1e75d56f authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

fix(#109): handle certification renewal

parent 6f8b8825
No related branches found
No related tags found
1 merge request!159Fix certification renewal
Pipeline #19613 failed
...@@ -406,10 +406,17 @@ pub mod pallet { ...@@ -406,10 +406,17 @@ pub mod pallet {
let mut created = false; let mut created = false;
CertsByReceiver::<T, I>::mutate_exists(receiver, |maybe_issuers| { CertsByReceiver::<T, I>::mutate_exists(receiver, |maybe_issuers| {
let issuers = maybe_issuers.get_or_insert(Vec::with_capacity(0)); let issuers = maybe_issuers.get_or_insert(Vec::with_capacity(0));
if let Err(index) = issuers.binary_search_by(|(issuer_, _)| issuer.cmp(issuer_)) { match issuers.binary_search_by(|(issuer_, _)| issuer_.cmp(&issuer)) {
// cert exists, must be renewed
Ok(index) => {
issuers[index] = (issuer, removable_on);
}
// cert does not exist, must be created
Err(index) => {
issuers.insert(index, (issuer, removable_on)); issuers.insert(index, (issuer, removable_on));
created = true; created = true;
} }
}
}); });
if created { if created {
...@@ -462,6 +469,7 @@ pub mod pallet { ...@@ -462,6 +469,7 @@ pub mod pallet {
total_weight total_weight
} }
/// perform the certification removal /// perform the certification removal
/// if block number is given only remove cert if still set to expire at this block number
fn remove_cert_inner( fn remove_cert_inner(
issuer: T::IdtyIndex, issuer: T::IdtyIndex,
receiver: T::IdtyIndex, receiver: T::IdtyIndex,
...@@ -474,6 +482,7 @@ pub mod pallet { ...@@ -474,6 +482,7 @@ pub mod pallet {
if let Ok(index) = issuers.binary_search_by(|(issuer_, _)| issuer_.cmp(&issuer)) { if let Ok(index) = issuers.binary_search_by(|(issuer_, _)| issuer_.cmp(&issuer)) {
if let Some(block_number) = block_number_opt { if let Some(block_number) = block_number_opt {
if let Some((_, removable_on)) = issuers.get(index) { if let Some((_, removable_on)) = issuers.get(index) {
// only remove cert if block number is matching
if *removable_on == block_number { if *removable_on == block_number {
issuers.remove(index); issuers.remove(index);
removed = true; removed = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment