mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 13:27:57 +00:00
Add arithmetic dispatch errors. (#8726)
* Add arithmetic dispatch errors. * Replace custom overflow errors. * Replace custom underflow and division by zero errors. * Replace overflow/underflow in token error. * Add token and arithmetic errors in dispatch error equality test. * Trigger CI.
This commit is contained in:
@@ -468,6 +468,8 @@ pub enum DispatchError {
|
||||
NoProviders,
|
||||
/// An error to do with tokens.
|
||||
Token(TokenError),
|
||||
/// An arithmetic error.
|
||||
Arithmetic(ArithmeticError),
|
||||
}
|
||||
|
||||
/// Result of a `Dispatchable` which contains the `DispatchResult` and additional information about
|
||||
@@ -542,10 +544,6 @@ pub enum TokenError {
|
||||
UnknownAsset,
|
||||
/// Funds exist but are frozen.
|
||||
Frozen,
|
||||
/// An underflow would occur.
|
||||
Underflow,
|
||||
/// An overflow would occur.
|
||||
Overflow,
|
||||
}
|
||||
|
||||
impl From<TokenError> for &'static str {
|
||||
@@ -557,8 +555,6 @@ impl From<TokenError> for &'static str {
|
||||
TokenError::CannotCreate => "Account cannot be created",
|
||||
TokenError::UnknownAsset => "The asset in question is unknown",
|
||||
TokenError::Frozen => "Funds exist but are frozen",
|
||||
TokenError::Underflow => "An underflow would occur",
|
||||
TokenError::Overflow => "An overflow would occur",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -569,6 +565,34 @@ impl From<TokenError> for DispatchError {
|
||||
}
|
||||
}
|
||||
|
||||
/// Arithmetic errors.
|
||||
#[derive(Eq, PartialEq, Clone, Copy, Encode, Decode, Debug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub enum ArithmeticError {
|
||||
/// Underflow.
|
||||
Underflow,
|
||||
/// Overflow.
|
||||
Overflow,
|
||||
/// Division by zero.
|
||||
DivisionByZero,
|
||||
}
|
||||
|
||||
impl From<ArithmeticError> for &'static str {
|
||||
fn from(e: ArithmeticError) -> &'static str {
|
||||
match e {
|
||||
ArithmeticError::Underflow => "An underflow would occur",
|
||||
ArithmeticError::Overflow => "An overflow would occur",
|
||||
ArithmeticError::DivisionByZero => "Division by zero",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ArithmeticError> for DispatchError {
|
||||
fn from(e: ArithmeticError) -> DispatchError {
|
||||
Self::Arithmetic(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'static str> for DispatchError {
|
||||
fn from(err: &'static str) -> DispatchError {
|
||||
Self::Other(err)
|
||||
@@ -585,6 +609,7 @@ impl From<DispatchError> for &'static str {
|
||||
DispatchError::ConsumerRemaining => "Consumer remaining",
|
||||
DispatchError::NoProviders => "No providers",
|
||||
DispatchError::Token(e) => e.into(),
|
||||
DispatchError::Arithmetic(e) => e.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -616,6 +641,10 @@ impl traits::Printable for DispatchError {
|
||||
Self::Token(e) => {
|
||||
"Token error: ".print();
|
||||
<&'static str>::from(*e).print();
|
||||
},
|
||||
Self::Arithmetic(e) => {
|
||||
"Arithmetic error: ".print();
|
||||
<&'static str>::from(*e).print();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -643,6 +672,7 @@ impl PartialEq for DispatchError {
|
||||
|
||||
(Token(l), Token(r)) => l == r,
|
||||
(Other(l), Other(r)) => l == r,
|
||||
(Arithmetic(l), Arithmetic(r)) => l == r,
|
||||
|
||||
(
|
||||
Module { index: index_l, error: error_l, .. },
|
||||
@@ -903,6 +933,15 @@ mod tests {
|
||||
Module { index: 2, error: 1, message: None },
|
||||
ConsumerRemaining,
|
||||
NoProviders,
|
||||
Token(TokenError::NoFunds),
|
||||
Token(TokenError::WouldDie),
|
||||
Token(TokenError::BelowMinimum),
|
||||
Token(TokenError::CannotCreate),
|
||||
Token(TokenError::UnknownAsset),
|
||||
Token(TokenError::Frozen),
|
||||
Arithmetic(ArithmeticError::Overflow),
|
||||
Arithmetic(ArithmeticError::Underflow),
|
||||
Arithmetic(ArithmeticError::DivisionByZero),
|
||||
];
|
||||
for (i, variant) in variants.iter().enumerate() {
|
||||
for (j, other_variant) in variants.iter().enumerate() {
|
||||
|
||||
Reference in New Issue
Block a user