darkfi_dao_contract/
error.rs

1/* This file is part of DarkFi (https://dark.fi)
2 *
3 * Copyright (C) 2020-2025 Dyne.org foundation
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18
19use darkfi_sdk::error::ContractError;
20
21#[derive(Debug, Clone, thiserror::Error)]
22pub enum DaoError {
23    #[error("Invalid calls")]
24    InvalidCalls,
25
26    #[error("DAO already exists")]
27    DaoAlreadyExists,
28
29    #[error("Proposal inputs are empty")]
30    ProposalInputsEmpty,
31
32    #[error("Invalid input Merkle root")]
33    InvalidInputMerkleRoot,
34
35    #[error("Snapshoot roots do not match")]
36    NonMatchingSnapshotRoots,
37
38    #[error("Snapshoot is past the cutoff limit")]
39    SnapshotTooOld,
40
41    #[error("Failed to deserialize snapshot")]
42    SnapshotDeserializationError,
43
44    #[error("Invalid DAO Merkle root")]
45    InvalidDaoMerkleRoot,
46
47    #[error("Proposal already exists")]
48    ProposalAlreadyExists,
49
50    #[error("Vote inputs are empty")]
51    VoteInputsEmpty,
52
53    #[error("Proposal doesn't exist")]
54    ProposalNonexistent,
55
56    #[error("Proposal ended")]
57    ProposalEnded,
58
59    #[error("Coin is already spent")]
60    CoinAlreadySpent,
61
62    #[error("Attempted double vote")]
63    DoubleVote,
64
65    #[error("Exec calls len does not match auth spec")]
66    ExecCallWrongChildCallsLen,
67
68    #[error("Child of exec call does not match proposal")]
69    ExecCallWrongChildCall,
70
71    #[error("Exec call has invalid tx format")]
72    ExecCallInvalidFormat,
73
74    #[error("Exec call value commitment mismatch")]
75    ExecCallValueMismatch,
76
77    #[error("Vote commitments mismatch")]
78    VoteCommitMismatch,
79
80    #[error("Sibling contract ID is not money::transfer()")]
81    AuthXferSiblingWrongContractId,
82
83    #[error("Sibling function code is not money::transfer()")]
84    AuthXferSiblingWrongFunctionCode,
85
86    #[error("Inputs with non-matching encrypted input user data")]
87    AuthXferNonMatchingEncInputUserData,
88
89    #[error("Auth call not found in parent")]
90    AuthXferCallNotFoundInParent,
91
92    #[error("Wrong number of outputs")]
93    AuthXferWrongNumberOutputs,
94
95    #[error("Wrong output coin")]
96    AuthXferWrongOutputCoin,
97}
98
99impl From<DaoError> for ContractError {
100    fn from(e: DaoError) -> Self {
101        match e {
102            DaoError::InvalidCalls => Self::Custom(1),
103            DaoError::DaoAlreadyExists => Self::Custom(2),
104            DaoError::ProposalInputsEmpty => Self::Custom(3),
105            DaoError::InvalidInputMerkleRoot => Self::Custom(4),
106            DaoError::NonMatchingSnapshotRoots => Self::Custom(5),
107            DaoError::SnapshotTooOld => Self::Custom(6),
108            DaoError::SnapshotDeserializationError => Self::Custom(7),
109            DaoError::InvalidDaoMerkleRoot => Self::Custom(8),
110            DaoError::ProposalAlreadyExists => Self::Custom(9),
111            DaoError::VoteInputsEmpty => Self::Custom(10),
112            DaoError::ProposalNonexistent => Self::Custom(11),
113            DaoError::ProposalEnded => Self::Custom(12),
114            DaoError::CoinAlreadySpent => Self::Custom(13),
115            DaoError::DoubleVote => Self::Custom(14),
116            DaoError::ExecCallWrongChildCallsLen => Self::Custom(15),
117            DaoError::ExecCallWrongChildCall => Self::Custom(16),
118            DaoError::ExecCallInvalidFormat => Self::Custom(17),
119            DaoError::ExecCallValueMismatch => Self::Custom(18),
120            DaoError::VoteCommitMismatch => Self::Custom(19),
121            DaoError::AuthXferSiblingWrongContractId => Self::Custom(20),
122            DaoError::AuthXferSiblingWrongFunctionCode => Self::Custom(21),
123            DaoError::AuthXferNonMatchingEncInputUserData => Self::Custom(22),
124            DaoError::AuthXferCallNotFoundInParent => Self::Custom(23),
125            DaoError::AuthXferWrongNumberOutputs => Self::Custom(24),
126            DaoError::AuthXferWrongOutputCoin => Self::Custom(25),
127        }
128    }
129}