Skip to main content

defuse_core/
error.rs

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