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
use alloc::collections::BTreeSet;

use crate::common::IntermediateError;

use super::*;

impl<T: Config> Pallet<T> {
    pub(super) fn create_(
        AddStatusListCredential { id, credential }: AddStatusListCredential<T>,
        cred_opt: &mut Option<StatusListCredentialWithPolicy<T>>,
    ) -> Result<(), IntermediateError<T>> {
        credential.ensure_valid()?;

        ensure!(
            cred_opt.replace(credential).is_none(),
            IntermediateError::<T>::dispatch(Error::<T>::StatusListCredentialAlreadyExists)
        );

        deposit_indexed_event!(StatusListCredentialCreated(id));
        Ok(())
    }

    pub(super) fn update_(
        UpdateStatusListCredentialRaw { id, credential, .. }: UpdateStatusListCredentialRaw<T>,
        status_list_credential: &mut StatusListCredentialWithPolicy<T>,
        _: BTreeSet<PolicyExecutor>,
    ) -> DispatchResult {
        credential.ensure_valid()?;

        status_list_credential.status_list_credential = credential;

        deposit_indexed_event!(StatusListCredentialUpdated(id));
        Ok(())
    }

    pub(super) fn remove_(
        RemoveStatusListCredentialRaw { id, .. }: RemoveStatusListCredentialRaw<T>,
        status_list_credential: &mut Option<StatusListCredentialWithPolicy<T>>,
        _: BTreeSet<PolicyExecutor>,
    ) -> DispatchResult {
        status_list_credential
            .take()
            .ok_or(Error::<T>::StatusListCredentialDoesntExist)?;

        deposit_indexed_event!(StatusListCredentialRemoved(id));
        Ok(())
    }
}