Correct derives on errors

This commit is contained in:
Luke Parker
2022-12-09 09:50:00 -05:00
parent d32c865c9a
commit 9e82416e7d
7 changed files with 62 additions and 62 deletions

View File

@@ -33,10 +33,10 @@ lazy_static! {
}
/// Errors returned when CLSAG signing fails.
#[derive(Clone, Error, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, Debug, Error)]
pub enum ClsagError {
#[error("internal error ({0})")]
InternalError(String),
InternalError(&'static str),
#[error("invalid ring")]
InvalidRing,
#[error("invalid ring member (member {0}, ring size {1})")]
@@ -66,7 +66,7 @@ impl ClsagInput {
pub fn new(commitment: Commitment, decoys: Decoys) -> Result<ClsagInput, ClsagError> {
let n = decoys.len();
if n > u8::MAX.into() {
Err(ClsagError::InternalError("max ring size in this library is u8 max".to_string()))?;
Err(ClsagError::InternalError("max ring size in this library is u8 max"))?;
}
let n = u8::try_from(n).unwrap();
if decoys.i >= n {

View File

@@ -38,10 +38,10 @@ struct TransactionsResponse {
txs: Vec<TransactionResponse>,
}
#[derive(Clone, Error, Debug)]
#[derive(Clone, PartialEq, Eq, Debug, Error)]
pub enum RpcError {
#[error("internal error ({0})")]
InternalError(String),
InternalError(&'static str),
#[error("connection error")]
ConnectionError,
#[error("invalid node")]
@@ -184,10 +184,10 @@ impl Rpc {
Ok(if !method.ends_with(".bin") {
serde_json::from_str(&res.text().await.map_err(|_| RpcError::ConnectionError)?)
.map_err(|_| RpcError::InternalError("Failed to parse JSON response".to_string()))?
.map_err(|_| RpcError::InternalError("Failed to parse JSON response"))?
} else {
monero_epee_bin_serde::from_bytes(&res.bytes().await.map_err(|_| RpcError::ConnectionError)?)
.map_err(|_| RpcError::InternalError("Failed to parse binary response".to_string()))?
.map_err(|_| RpcError::InternalError("Failed to parse binary response"))?
})
}

View File

@@ -81,7 +81,7 @@ impl<B: AddressBytes> Zeroize for AddressMeta<B> {
}
/// Error when decoding an address.
#[derive(Clone, Error, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, Debug, Error)]
pub enum AddressError {
#[error("invalid address byte")]
InvalidByte,

View File

@@ -47,7 +47,7 @@ async fn select_n<R: RngCore + CryptoRng>(
iters += 1;
// This is cheap and on fresh chains, thousands of rounds may be needed
if iters == 10000 {
Err(RpcError::InternalError("not enough decoy candidates".to_string()))?;
Err(RpcError::InternalError("not enough decoy candidates"))?;
}
// Use a gamma distribution
@@ -178,7 +178,7 @@ impl Decoys {
// TODO: Simply create a TX with less than the target amount
if (high - MATURITY) < u64::try_from(inputs.len() * ring_len).unwrap() {
Err(RpcError::InternalError("not enough decoy candidates".to_string()))?;
Err(RpcError::InternalError("not enough decoy candidates"))?;
}
// Select all decoys for this transaction, assuming we generate a sane transaction

View File

@@ -79,7 +79,7 @@ impl SendOutput {
}
}
#[derive(Clone, Error, Debug)]
#[derive(Clone, PartialEq, Eq, Debug, Error)]
pub enum TransactionError {
#[error("multiple addresses with payment IDs")]
MultiplePaymentIds,