UNPKG

5.65 kBTypeScriptView Raw
1/// <reference types="node" />
2import { ObjectMap } from '@0x/types';
3import { DataItem, RevertErrorAbi } from 'ethereum-types';
4import { BigNumber } from './configured_bignumber';
5declare type ArgTypes = string | BigNumber | number | boolean | RevertError | BigNumber[] | string[] | number[] | boolean[] | Array<BigNumber | number | string>;
6declare type ValueMap = ObjectMap<ArgTypes | undefined>;
7interface RevertErrorType {
8 new (): RevertError;
9}
10/**
11 * Register a RevertError type so that it can be decoded by
12 * `decodeRevertError`.
13 * @param revertClass A class that inherits from RevertError.
14 * @param force Allow overwriting registered types.
15 */
16export declare function registerRevertErrorType(revertClass: RevertErrorType, force?: boolean): void;
17/**
18 * Decode an ABI encoded revert error.
19 * Throws if the data cannot be decoded as a known RevertError type.
20 * @param bytes The ABI encoded revert error. Either a hex string or a Buffer.
21 * @param coerce Coerce unknown selectors into a `RawRevertError` type.
22 * @return A RevertError object.
23 */
24export declare function decodeBytesAsRevertError(bytes: string | Buffer, coerce?: boolean): RevertError;
25/**
26 * Decode a thrown error.
27 * Throws if the data cannot be decoded as a known RevertError type.
28 * @param error Any thrown error.
29 * @param coerce Coerce unknown selectors into a `RawRevertError` type.
30 * @return A RevertError object.
31 */
32export declare function decodeThrownErrorAsRevertError(error: Error, coerce?: boolean): RevertError;
33/**
34 * Coerce a thrown error into a `RevertError`. Always succeeds.
35 * @param error Any thrown error.
36 * @return A RevertError object.
37 */
38export declare function coerceThrownErrorAsRevertError(error: Error): RevertError;
39/**
40 * Base type for revert errors.
41 */
42export declare abstract class RevertError extends Error {
43 private static readonly _typeRegistry;
44 readonly abi?: RevertErrorAbi;
45 readonly values: ValueMap;
46 protected readonly _raw?: string;
47 /**
48 * Decode an ABI encoded revert error.
49 * Throws if the data cannot be decoded as a known RevertError type.
50 * @param bytes The ABI encoded revert error. Either a hex string or a Buffer.
51 * @param coerce Whether to coerce unknown selectors into a `RawRevertError` type.
52 * @return A RevertError object.
53 */
54 static decode(bytes: string | Buffer | RevertError, coerce?: boolean): RevertError;
55 /**
56 * Register a RevertError type so that it can be decoded by
57 * `RevertError.decode`.
58 * @param revertClass A class that inherits from RevertError.
59 * @param force Allow overwriting existing registrations.
60 */
61 static registerType(revertClass: RevertErrorType, force?: boolean): void;
62 /**
63 * Create a RevertError instance with optional parameter values.
64 * Parameters that are left undefined will not be tested in equality checks.
65 * @param declaration Function-style declaration of the revert (e.g., Error(string message))
66 * @param values Optional mapping of parameters to values.
67 * @param raw Optional encoded form of the revert error. If supplied, this
68 * instance will be treated as a `RawRevertError`, meaning it can only
69 * match other `RawRevertError` types with the same encoded payload.
70 */
71 protected constructor(name: string, declaration?: string, values?: ValueMap, raw?: string);
72 /**
73 * Get the ABI name for this revert.
74 */
75 get name(): string;
76 /**
77 * Get the class name of this type.
78 */
79 get typeName(): string;
80 /**
81 * Get the hex selector for this revert (without leading '0x').
82 */
83 get selector(): string;
84 /**
85 * Get the signature for this revert: e.g., 'Error(string)'.
86 */
87 get signature(): string;
88 /**
89 * Get the ABI arguments for this revert.
90 */
91 get arguments(): DataItem[];
92 get [Symbol.toStringTag](): string;
93 /**
94 * Compares this instance with another.
95 * Fails if instances are not of the same type.
96 * Only fields/values defined in both instances are compared.
97 * @param other Either another RevertError instance, hex-encoded bytes, or a Buffer of the ABI encoded revert.
98 * @return True if both instances match.
99 */
100 equals(other: RevertError | Buffer | string): boolean;
101 encode(): string;
102 toString(): string;
103 private _getArgumentByName;
104 private get _isAnyType();
105 private get _isRawType();
106 private get _hasAllArgumentValues();
107}
108interface GanacheTransactionRevertResult {
109 error: 'revert';
110 program_counter: number;
111 return?: string;
112 reason?: string;
113}
114interface GanacheTransactionRevertError extends Error {
115 results: {
116 [hash: string]: GanacheTransactionRevertResult;
117 };
118 hashes: string[];
119}
120interface ParityTransactionRevertError extends Error {
121 code: number;
122 data: string;
123 message: string;
124}
125/**
126 * Try to extract the ecnoded revert error bytes from a thrown `Error`.
127 */
128export declare function getThrownErrorRevertErrorBytes(error: Error | GanacheTransactionRevertError | ParityTransactionRevertError): string;
129/**
130 * RevertError type for standard string reverts.
131 */
132export declare class StringRevertError extends RevertError {
133 constructor(message?: string);
134}
135/**
136 * Special RevertError type that matches with any other RevertError instance.
137 */
138export declare class AnyRevertError extends RevertError {
139 constructor();
140}
141/**
142 * Special RevertError type that is not decoded.
143 */
144export declare class RawRevertError extends RevertError {
145 constructor(encoded: string | Buffer);
146}
147export {};
148//# sourceMappingURL=revert_error.d.ts.map
\No newline at end of file