1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use std::result;
use std::convert::From;
use std::str;
use base64;
use bigdecimal;
use serde_xdr;

/// The Errors that can occur.
#[derive(Debug)]
pub enum Error {
    /// Error that can occur when parsing a key.
    InvalidStrKey,
    /// Invalid version byte in key.
    InvalidStrKeyVersionByte,
    /// Invalid checksum in key.
    InvalidStrKeyChecksum,
    /// Invalid keypair seed.
    InvalidSeed,
    /// Invalid Asset code.
    InvalidAssetCode,
    /// Invalid signature.
    InvalidSignature,
    /// Invalid memo text: too long.
    InvalidMemoText,
    /// Error that can occur when parsing amounts from stroops.
    InvalidStroopsAmount,
    /// Error that can occur when converting an amount with more than 7 digits.
    InvalidAmountScale,
    /// Invalid network id: too long.
    InvalidNetworkId,
    /// Invalid public key.
    InvalidPublicKey,
    /// Error that can occur when interpreting a sequence of `u8` as utf-8.
    Utf8Error(str::Utf8Error),
    /// Error that can occour when decoding base64 encoded data.
    DecodeError(base64::DecodeError),
    /// Error that can occur when parsing amounts.
    ParseAmountError(bigdecimal::ParseBigDecimalError),
    /// Error that can occur when serializing to XDR.
    SerializationError(serde_xdr::CompatSerializationError),
    /// Error that can occur when deserializing from XDR.
    DeserializationError(serde_xdr::CompatDeserializationError),
}

/// A `Result` alias where `Error` is a `shuttle_core::Error`.
pub type Result<T> = result::Result<T, Error>;

impl From<str::Utf8Error> for Error {
    fn from(err: str::Utf8Error) -> Self {
        Error::Utf8Error(err)
    }
}

impl From<base64::DecodeError> for Error {
    fn from(err: base64::DecodeError) -> Self {
        Error::DecodeError(err)
    }
}

impl From<bigdecimal::ParseBigDecimalError> for Error {
    fn from(err: bigdecimal::ParseBigDecimalError) -> Self {
        Error::ParseAmountError(err)
    }
}

impl From<serde_xdr::CompatDeserializationError> for Error {
    fn from(err: serde_xdr::CompatDeserializationError) -> Self {
        Error::DeserializationError(err)
    }
}

impl From<serde_xdr::CompatSerializationError> for Error {
    fn from(err: serde_xdr::CompatSerializationError) -> Self {
        Error::SerializationError(err)
    }
}