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 */
1819use darkfi_sdk::error::ContractError;
2021#[derive(Debug, Clone, thiserror::Error)]
22pub enum DaoError {
23#[error("Invalid calls")]
24InvalidCalls,
2526#[error("DAO already exists")]
27DaoAlreadyExists,
2829#[error("Proposal inputs are empty")]
30ProposalInputsEmpty,
3132#[error("Invalid input Merkle root")]
33InvalidInputMerkleRoot,
3435#[error("Snapshoot roots do not match")]
36NonMatchingSnapshotRoots,
3738#[error("Snapshoot is past the cutoff limit")]
39SnapshotTooOld,
4041#[error("Failed to deserialize snapshot")]
42SnapshotDeserializationError,
4344#[error("Invalid DAO Merkle root")]
45InvalidDaoMerkleRoot,
4647#[error("Proposal already exists")]
48ProposalAlreadyExists,
4950#[error("Vote inputs are empty")]
51VoteInputsEmpty,
5253#[error("Proposal doesn't exist")]
54ProposalNonexistent,
5556#[error("Proposal ended")]
57ProposalEnded,
5859#[error("Coin is already spent")]
60CoinAlreadySpent,
6162#[error("Attempted double vote")]
63DoubleVote,
6465#[error("Exec calls len does not match auth spec")]
66ExecCallWrongChildCallsLen,
6768#[error("Child of exec call does not match proposal")]
69ExecCallWrongChildCall,
7071#[error("Exec call has invalid tx format")]
72ExecCallInvalidFormat,
7374#[error("Exec call value commitment mismatch")]
75ExecCallValueMismatch,
7677#[error("Vote commitments mismatch")]
78VoteCommitMismatch,
7980#[error("Sibling contract ID is not money::transfer()")]
81AuthXferSiblingWrongContractId,
8283#[error("Sibling function code is not money::transfer()")]
84AuthXferSiblingWrongFunctionCode,
8586#[error("Inputs with non-matching encrypted input user data")]
87AuthXferNonMatchingEncInputUserData,
8889#[error("Auth call not found in parent")]
90AuthXferCallNotFoundInParent,
9192#[error("Wrong number of outputs")]
93AuthXferWrongNumberOutputs,
9495#[error("Wrong output coin")]
96AuthXferWrongOutputCoin,
97}
9899impl From<DaoError> for ContractError {
100fn from(e: DaoError) -> Self {
101match 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}