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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#[cfg(feature = "approval")]
use crate::commons::models::approval::ApprovalEntity;
use crate::commons::models::request::TapleRequest;
use crate::commons::models::state::SubjectData;
use crate::identifier::DigestIdentifier;
use crate::signature::Signature;
use crate::signature::Signed;
use crate::{ApprovalState, Event, EventRequest, KeyDerivator, KeyIdentifier, ValidationProof};
use std::collections::HashSet;

mod api;

pub use api::Api;
pub(crate) use api::ApiManager;
pub use error::ApiError;

mod error;
mod inner_api;

#[derive(Debug, Clone)]
pub enum APICommands {
    GetSubjects(GetSubjects),
    GetSubjectByGovernance(GetSubjects, DigestIdentifier),
    GetGovernances(GetSubjects),
    GetSubject(GetSubject),
    GetEvent(DigestIdentifier, u64),
    GetEvents(GetEvents),
    #[cfg(feature = "approval")]
    VoteResolve(bool, DigestIdentifier),
    ExternalRequest(Signed<EventRequest>),
    #[cfg(feature = "approval")]
    GetPendingRequests,
    #[cfg(feature = "approval")]
    GetSingleRequest(DigestIdentifier),
    SetPreauthorizedSubject(DigestIdentifier, HashSet<KeyIdentifier>),
    GetAllPreauthorizedSubjects(GetAllowedSubjects),
    AddKeys(KeyDerivator),
    GetValidationProof(DigestIdentifier),
    GetRequest(DigestIdentifier),
    GetGovernanceSubjects(GetGovernanceSubjects),
    #[cfg(feature = "approval")]
    GetApproval(DigestIdentifier),
    #[cfg(feature = "approval")]
    GetApprovals(GetApprovals),
}

#[derive(Debug, Clone)]
pub enum ApiResponses {
    GetSubjects(Result<Vec<SubjectData>, ApiError>),
    GetSubjectByGovernance(Result<Vec<SubjectData>, ApiError>),
    GetGovernances(Result<Vec<SubjectData>, ApiError>),
    GetSubject(Result<SubjectData, ApiError>),
    GetEvents(Result<Vec<Signed<Event>>, ApiError>),
    HandleExternalRequest(Result<DigestIdentifier, ApiError>),
    #[cfg(feature = "approval")]
    VoteResolve(Result<ApprovalEntity, ApiError>),
    #[cfg(feature = "approval")]
    GetPendingRequests(Result<Vec<ApprovalEntity>, ApiError>),
    #[cfg(feature = "approval")]
    GetSingleRequest(Result<ApprovalEntity, ApiError>),
    GetEvent(Result<Signed<Event>, ApiError>),
    AddKeys(Result<KeyIdentifier, ApiError>),
    GetValidationProof(Result<(HashSet<Signature>, ValidationProof), ApiError>),
    GetRequest(Result<TapleRequest, ApiError>),
    GetGovernanceSubjects(Result<Vec<SubjectData>, ApiError>),
    #[cfg(feature = "approval")]
    GetApproval(Result<ApprovalEntity, ApiError>),
    #[cfg(feature = "approval")]
    GetApprovals(Result<Vec<ApprovalEntity>, ApiError>),
    SetPreauthorizedSubjectCompleted,
    GetAllPreauthorizedSubjects(Result<Vec<(DigestIdentifier, HashSet<KeyIdentifier>)>, ApiError>),
}

#[derive(Debug, Clone)]
pub struct GetApprovals {
    pub state: Option<ApprovalState>,
    pub from: Option<String>,
    pub quantity: Option<i64>,
}

#[derive(Debug, Clone)]
pub struct GetSubjects {
    pub namespace: String,
    pub from: Option<String>,
    pub quantity: Option<i64>,
}

#[derive(Debug, Clone)]
pub struct GetSubject {
    pub subject_id: DigestIdentifier,
}

#[derive(Debug, Clone)]
pub struct GetEvents {
    pub subject_id: DigestIdentifier,
    pub from: Option<i64>,
    pub quantity: Option<i64>,
}

#[derive(Debug, Clone)]
pub struct GetGovernanceSubjects {
    pub governance_id: DigestIdentifier,
    pub from: Option<String>,
    pub quantity: Option<i64>,
}

#[derive(Debug, Clone)]
pub struct GetAllowedSubjects {
    pub from: Option<String>,
    pub quantity: Option<i64>,
}