milestone 2

This commit is contained in:
scilio
2022-04-26 23:13:44 -04:00
parent 68929fd493
commit 115e0d2022
13 changed files with 760 additions and 1222 deletions
+9 -21
View File
@@ -10,13 +10,11 @@ pub struct Error {
}
pub type Result<T> = std::result::Result<T, Error>;
pub type StdResult<T, E> = std::result::Result<T, E>;
#[derive(Clone, Debug, Eq, Fail, PartialEq)]
/// MWixnet error types
pub enum ErrorKind {
/// Unsupported payload version
#[fail(display = "Unsupported Payload Version")]
UnsupportedPayload,
/// Error from secp256k1-zkp library
#[fail(display = "Secp Error")]
SecpError,
@@ -29,23 +27,9 @@ pub enum ErrorKind {
String,
io::ErrorKind,
),
/// Expected a given value that wasn't found
#[fail(display = "UnexpectedData")]
UnexpectedData {
/// What we wanted
expected: Vec<u8>,
/// What we got
received: Vec<u8>,
},
/// Data wasn't in a consumable format
#[fail(display = "CorruptedData")]
CorruptedData,
/// Incorrect number of elements (when deserializing a vec via read_multi say).
#[fail(display = "CountError")]
CountError,
/// When asked to read too much data
#[fail(display = "TooLargeReadErr")]
TooLargeReadErr,
/// Error from grin's api crate
#[fail(display = "GRIN API Error")]
GrinApiError,
@@ -85,6 +69,14 @@ impl From<io::ErrorKind> for Error {
}
}
impl From<grin_core::ser::Error> for Error {
fn from(_e: grin_core::ser::Error) -> Error {
Error {
inner: Context::new(ErrorKind::GrinCoreError),
}
}
}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Display::fmt(&self.inner, f)
@@ -98,10 +90,6 @@ impl Error {
}
}
pub fn kind(&self) -> ErrorKind {
self.inner.get_context().clone()
}
pub fn message(&self) -> String {
format!("{}", self).into()
}