1use crate::{
2 engine::deltas::InvariantViolated,
3 token_id::{TokenId, TokenIdError, nep171::Nep171TokenId},
4};
5use defuse_crypto::PublicKey;
6use near_sdk::{AccountId, FunctionError, serde_json};
7use thiserror::Error as ThisError;
8
9pub type Result<T, E = DefuseError> = ::core::result::Result<T, E>;
10
11#[derive(Debug, ThisError, FunctionError)]
12pub enum DefuseError {
13 #[error("account '{0}' not found")]
14 AccountNotFound(AccountId),
15
16 #[error("account '{0}' is locked")]
17 AccountLocked(AccountId),
18
19 #[error("authentication by PREDECESSOR_ID is disabled for account '{0}'")]
20 AuthByPredecessorIdDisabled(AccountId),
21
22 #[error("insufficient balance or overflow")]
23 BalanceOverflow,
24
25 #[error("deadline has expired")]
26 DeadlineExpired,
27
28 #[error("deadline is greater than nonce")]
29 DeadlineGreaterThanNonce,
30
31 #[error("gas overflow")]
32 GasOverflow,
33
34 #[error("invalid intent")]
35 InvalidIntent,
36
37 #[error("invalid signature")]
38 InvalidSignature,
39
40 #[error(
41 "invariant violated: {}",
42 serde_json::to_string(.0).unwrap_or_else(|_| unreachable!())
43 )]
44 InvariantViolated(InvariantViolated),
45
46 #[error("JSON: {0}")]
47 JSON(#[from] serde_json::Error),
48
49 #[error("NFT '{}' is already deposited", TokenId::Nep171(.0.clone()))]
50 NftAlreadyDeposited(Nep171TokenId),
51
52 #[error("nonce was already used")]
53 NonceUsed,
54
55 #[error("nonce was already expired")]
56 NonceExpired,
57
58 #[error("invalid nonce")]
59 InvalidNonce,
60
61 #[error("public key '{1}' already exists for account '{0}'")]
62 PublicKeyExists(AccountId, PublicKey),
63
64 #[error("public key '{1}' doesn't exist for account '{0}'")]
65 PublicKeyNotExist(AccountId, PublicKey),
66
67 #[error("token_id: {0}")]
68 ParseTokenId(#[from] TokenIdError),
69
70 #[error("wrong verifying_contract")]
71 WrongVerifyingContract,
72
73 #[error("invalid salt")]
74 InvalidSalt,
75
76 #[error("maximum attempts to generate a new salt reached")]
77 SaltGenerationFailed,
78}