Refactored the SafeMath errors

This commit is contained in:
James Towle
2019-06-17 10:57:33 -07:00
committed by Amir Bandeali
parent e916daf5fd
commit a46b13967a
6 changed files with 51 additions and 70 deletions

View File

@@ -3,27 +3,20 @@ import { RevertError } from './revert_error';
// tslint:disable:max-classes-per-file
export class Uint256OverflowError extends RevertError {
constructor(a?: BigNumber | number | string, b?: BigNumber | number | string) {
super('Uint256OverflowError', 'Uint256OverflowError(uint256 a, uint256 b)', {
export enum SafeMathErrorCodes {
Uint256AdditionOverflow,
Uint256MultiplicationOverflow,
Uint256SubtractionUnderflow,
}
export class SafeMathError extends RevertError {
constructor(error?: SafeMathErrorCodes, a?: BigNumber | number | string, b?: BigNumber | number | string) {
super('SafeMathError', 'SafeMathError(uint8 error, uint256 a, uint256 b)', {
error,
a,
b,
});
}
}
export class Uint256UnderflowError extends RevertError {
constructor(a?: BigNumber | number | string, b?: BigNumber | number | string) {
super('Uint256UnderflowError', 'Uint256UnderflowError(uint256 a, uint256 b)', {
a,
b,
});
}
}
const types = [Uint256OverflowError, Uint256UnderflowError];
// Register the types we've defined.
for (const type of types) {
RevertError.registerType(type);
}
RevertError.registerType(SafeMathError);