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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
pub use indy_data_types::anoncreds::rev_reg_def::{
    IssuanceType, RegistryType, RevocationRegistryConfig, RevocationRegistryDefinition,
    RevocationRegistryDefinitionV1, RevocationRegistryDefinitionValue,
    RevocationRegistryDefinitionValuePublicKeys, CL_ACCUM,
};

use super::constants::{GET_REVOC_REG_DEF, REVOC_REG_DEF};
use super::identifiers::CredentialDefinitionId;
use super::identifiers::RevocationRegistryId;
use super::{ProtocolVersion, RequestType};
use crate::common::error::prelude::*;

#[derive(Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RevRegDefOperation {
    #[serde(rename = "type")]
    pub _type: String,
    pub id: RevocationRegistryId,
    #[serde(rename = "revocDefType")]
    pub type_: String,
    pub tag: String,
    pub cred_def_id: CredentialDefinitionId,
    pub value: RevocationRegistryDefinitionValue,
}

impl RevRegDefOperation {
    pub fn new(rev_reg_def: RevocationRegistryDefinitionV1) -> RevRegDefOperation {
        RevRegDefOperation {
            _type: Self::get_txn_type().to_string(),
            id: rev_reg_def.id,
            type_: rev_reg_def.revoc_def_type.to_str().to_string(),
            tag: rev_reg_def.tag,
            cred_def_id: rev_reg_def.cred_def_id,
            value: rev_reg_def.value,
        }
    }
}

impl RequestType for RevRegDefOperation {
    fn get_txn_type<'a>() -> &'a str {
        REVOC_REG_DEF
    }
}

#[derive(Serialize, PartialEq, Debug)]
#[serde(rename_all = "camelCase")]
pub struct GetRevRegDefOperation {
    #[serde(rename = "type")]
    pub _type: String,
    pub id: RevocationRegistryId,
}

impl GetRevRegDefOperation {
    pub fn new(id: &RevocationRegistryId) -> GetRevRegDefOperation {
        GetRevRegDefOperation {
            _type: Self::get_txn_type().to_string(),
            id: id.clone(),
        }
    }
}

impl RequestType for GetRevRegDefOperation {
    fn get_txn_type<'a>() -> &'a str {
        GET_REVOC_REG_DEF
    }

    fn get_sp_key(&self, _protocol_version: ProtocolVersion) -> VdrResult<Option<Vec<u8>>> {
        Ok(Some(self.id.as_bytes().to_vec()))
    }
}