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
use std::collections::HashSet;

use crate::{
    commons::{
        identifier::{DigestIdentifier, KeyIdentifier},
        models::event::Metadata,
        schema_handler::gov_models::Contract,
    },
    ValueWrapper,
};
pub mod error;
pub mod governance;
pub mod inner_governance;
pub mod stage;

pub use governance::{GovernanceAPI, GovernanceInterface};

use error::RequestError;

use self::stage::ValidationStage;

#[derive(Debug, Clone)]
pub struct GovernanceMember {
    pub id: String,
    pub namespace: String,
    pub description: String,
    pub key: KeyIdentifier,
}

#[derive(Debug, Clone)]
pub struct SingleGovernance {
    pub quorum: f32,
    pub members: Vec<GovernanceMember>,
    pub schemas: Vec<()>,
}

#[derive(Debug, Clone)]
pub enum GovernanceMessage {
    GetInitState {
        governance_id: DigestIdentifier,
        schema_id: String,
        governance_version: u64,
    },
    GetSchema {
        governance_id: DigestIdentifier,
        schema_id: String,
        governance_version: u64,
    },
    GetSigners {
        metadata: Metadata,
        stage: ValidationStage,
    },
    GetQuorum {
        metadata: Metadata,
        stage: ValidationStage,
    },
    GetInvokeInfo {
        metadata: Metadata,
        stage: ValidationStage,
        invoker: KeyIdentifier,
    },
    GetContracts {
        governance_id: DigestIdentifier,
        governance_version: u64,
    },
    GetGovernanceVersion {
        governance_id: DigestIdentifier,
        subject_id: DigestIdentifier,
    },
    IsGovernance {
        subject_id: DigestIdentifier,
    },
    GovernanceUpdated {
        governance_id: DigestIdentifier,
        governance_version: u64,
    },
}

#[derive(Debug, Clone)]
pub enum GovernanceResponse {
    GetInitState(Result<ValueWrapper, RequestError>),
    GetSchema(Result<ValueWrapper, RequestError>),
    GetSigners(Result<HashSet<KeyIdentifier>, RequestError>),
    GetQuorum(Result<u32, RequestError>),
    GetInvokeInfo(Result<bool, RequestError>),
    GetContracts(Result<Vec<(Contract, String)>, RequestError>),
    GetGovernanceVersion(Result<u64, RequestError>),
    IsGovernance(Result<bool, RequestError>),
    NoResponse,
}

#[derive(Debug, Clone)]
pub enum GovernanceUpdatedMessage {
    GovernanceUpdated {
        governance_id: DigestIdentifier,
        governance_version: u64,
    },
}