1use crate::{
2 engine::deltas::InvariantViolated,
3 token_id::{TokenId, error::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("gas overflow")]
29 GasOverflow,
30
31 #[error("invalid intent")]
32 InvalidIntent,
33
34 #[error("invalid signature")]
35 InvalidSignature,
36
37 #[error(
38 "invariant violated: {}",
39 serde_json::to_string(.0).unwrap_or_else(|_| unreachable!())
40 )]
41 InvariantViolated(InvariantViolated),
42
43 #[error("JSON: {0}")]
44 JSON(#[from] serde_json::Error),
45
46 #[error("NFT '{}' is already deposited", TokenId::Nep171(.0.clone()))]
47 NftAlreadyDeposited(Nep171TokenId),
48
49 #[error("nonce was already used")]
50 NonceUsed,
51
52 #[error("public key '{1}' already exists for account '{0}'")]
53 PublicKeyExists(AccountId, PublicKey),
54
55 #[error("public key '{1}' doesn't exist for account '{0}'")]
56 PublicKeyNotExist(AccountId, PublicKey),
57
58 #[error("token_id: {0}")]
59 ParseTokenId(#[from] TokenIdError),
60
61 #[error("wrong verifying_contract")]
62 WrongVerifyingContract,
63}