Skip to main content

torvyon_core/
error.rs

1/// Result type for this crate.
2pub type Result<T> = std::result::Result<T, Error>;
3
4/// Everything that can go wrong. Messages match the node's error text where
5/// the node has an equivalent check.
6#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
7#[non_exhaustive]
8pub enum Error {
9    /// ML-DSA-65 key material has an invalid length or encoding.
10    #[error("invalid ML-DSA-65 key")]
11    InvalidPQKey,
12    /// ML-DSA-65 signature has an invalid length or encoding.
13    #[error("invalid ML-DSA-65 signature")]
14    InvalidPQSignature,
15    /// Not a valid secp256k1 private key.
16    #[error("invalid private key")]
17    InvalidPrivateKey,
18    /// Public key is not 32 bytes or not a valid curve point.
19    #[error("invalid public key length")]
20    InvalidPublicKey,
21    /// Recovery phrase is not a valid 24-word BIP39 phrase for a valid key.
22    #[error("invalid recovery phrase")]
23    InvalidMnemonic,
24    /// Address has the wrong length.
25    #[error("invalid address length")]
26    AddressLength,
27    /// Address does not start with `bt1`.
28    #[error("invalid address prefix")]
29    AddressPrefix,
30    /// Address payload is not hex.
31    #[error("invalid address payload")]
32    AddressPayload,
33    /// Address checksum does not match.
34    #[error("invalid address checksum")]
35    AddressChecksum,
36    /// Signature is malformed or does not verify.
37    #[error("invalid signature")]
38    InvalidSignature,
39    /// Transaction has no chain ID.
40    #[error("missing chain id")]
41    MissingChainId,
42    /// UTXO transaction has no inputs.
43    #[error("utxo transaction has no inputs")]
44    NoInputs,
45    /// UTXO transaction has no outputs.
46    #[error("utxo transaction has no outputs")]
47    NoOutputs,
48    /// Data payload is larger than [`tx::MAX_DATA_SIZE`](crate::tx::MAX_DATA_SIZE).
49    #[error("data payload is {0} bytes, max is 512")]
50    DataTooLarge(usize),
51    /// Output has no script.
52    #[error("utxo output {0} missing script_pub_key")]
53    MissingScript(usize),
54    /// Output script fails canonicalization.
55    #[error("utxo output {0} has an invalid script_pub_key")]
56    InvalidScript(usize),
57    /// Spending condition is malformed or exceeds consensus limits.
58    #[error("invalid condition: {0}")]
59    InvalidCondition(String),
60    /// Atomic swap parameters are unsafe or invalid.
61    #[error("invalid atomic swap: {0}")]
62    InvalidSwap(String),
63    /// Output value is zero.
64    #[error("utxo output {0} has zero value")]
65    ZeroValue(usize),
66    /// `from` is not the address of the public key.
67    #[error("from address does not match public key")]
68    FromMismatch,
69    /// Signature scheme is not supported.
70    #[error("unknown signature scheme")]
71    UnknownScheme,
72    /// Transaction version is not 0, 2 or 3.
73    #[error("unsupported transaction version: {0}")]
74    UnsupportedVersion(u32),
75    /// Spendable UTXOs do not cover amount + fee.
76    #[error("insufficient funds: need {need}, have {have}")]
77    InsufficientFunds {
78        /// Amount + fee in nibbles.
79        need: u64,
80        /// Total of all spendable UTXOs in nibbles.
81        have: u64,
82    },
83    /// Covering the amount would need more than [`tx::MAX_INPUTS`](crate::tx::MAX_INPUTS) inputs.
84    #[error("payment needs more than {0} inputs; consolidate UTXOs first")]
85    TooManyInputs(usize),
86    /// Arithmetic overflow on amounts.
87    #[error("amount overflow")]
88    AmountOverflow,
89    /// Amount string could not be parsed.
90    #[error("invalid amount")]
91    InvalidAmount,
92    /// Network name is not supported.
93    #[error("invalid network")]
94    InvalidNetwork,
95    /// Wire JSON could not be decoded.
96    #[error("invalid transaction json: {0}")]
97    Json(String),
98}