1use crate::model::TransactionData;
2use base64::DecodeError;
3use blake2::digest::{InvalidBufferSize, InvalidOutputSize};
4use ed25519_dalek::SignatureError;
5use hex::FromHexError;
6use prost::EncodeError;
7use std::result;
8use url::ParseError;
9
10pub type Result<T> = result::Result<T, Error>;
11
12#[derive(Debug, thiserror::Error)]
13#[allow(clippy::large_enum_variant)]
14pub enum Error {
15 #[error("node return error response (error: {error:?}, message: {message:?}))")]
16 NodeError { error: u32, message: String },
17 #[error("io error {0}")]
18 IoError(#[from] reqwest::Error),
19 #[error("failed to parse field: [{field:?}] from response {json:?}")]
20 JsonParseError { field: String, json: String },
21 #[error("base64 error {0}")]
22 Base64Error(#[from] DecodeError),
23 #[error("base58 error {0}")]
24 Base58Error(#[from] bs58::decode::Error),
25 #[error("blake error {0}")]
26 BlakeError(#[from] InvalidSizeError),
27 #[error("url parse error {0}")]
28 UrlParseError(#[from] ParseError),
29 #[error("wrong transaction type expected {expected_type:?} found {actual_type:?}")]
30 WrongTransactionType { expected_type: u8, actual_type: u8 },
31 #[error("failed to encode protobuf {0}")]
32 ProtobufEncodeError(#[from] EncodeError),
33 #[error("signature error {0}")]
34 SignatureError(#[from] SignatureError),
35 #[error("invalid bytes length expected {expected_len:?} actual {actual_len:?}")]
36 InvalidBytesLength {
37 expected_len: usize,
38 actual_len: usize,
39 },
40 #[error("failed to convert Montgomery Point to Edwards Point")]
41 MontgomeryPointConversionError,
42 #[error("failed to convert hex string to bytes")]
43 HexError(#[from] FromHexError),
44 #[error("unsupported operation: {0}")]
45 UnsupportedOperation(String),
46 #[error("failed to convert vector {0:?} to array")]
47 VectorToArrayConversionError(Vec<u8>),
48 #[error("alias must be {min_length:?} to {max_length:?} length of {alphabet:?} and may have a prefix \"{max_length:?}{chain_id:?}:\"")]
49 InvalidAliasName {
50 min_length: u8,
51 max_length: u8,
52 alphabet: String,
53 prefix: String,
54 chain_id: char,
55 },
56 #[error("unsupported order version")]
57 UnsupportedOrderVersion,
58 #[error(
59 "Unsupported transaction version {actual_version:?} for {tx_type:?} transaction. \
60 Use version {supported_version:?} or above"
61 )]
62 UnsupportedTransactionVersion {
63 actual_version: u8,
64 supported_version: u8,
65 tx_type: TransactionData,
66 },
67}
68
69#[derive(Debug, thiserror::Error)]
70pub enum InvalidSizeError {
71 #[error("invalid output size {0}")]
72 InvalidOutputSize(#[from] InvalidOutputSize),
73 #[error("invalid buffer size {0}")]
74 InvalidBufferSize(#[from] InvalidBufferSize),
75}
76
77pub struct WrongTransactionTypeError {}