aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r--packages/0x.js/src/types.ts8
-rw-r--r--packages/0x.js/src/web3_wrapper.ts13
2 files changed, 18 insertions, 3 deletions
diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts
index 69fd3ba03..a8da05205 100644
--- a/packages/0x.js/src/types.ts
+++ b/packages/0x.js/src/types.ts
@@ -2,9 +2,12 @@ import BigNumber from 'bignumber.js';
import * as Web3 from 'web3';
export enum ZeroExError {
- ContractDoesNotExist = 'CONTRACT_DOES_NOT_EXIST',
ExchangeContractDoesNotExist = 'EXCHANGE_CONTRACT_DOES_NOT_EXIST',
ZRXContractDoesNotExist = 'ZRX_CONTRACT_DOES_NOT_EXIST',
+ EtherTokenContractDoesNotExist = 'ETHER_TOKEN_CONTRACT_DOES_NOT_EXIST',
+ TokenTransferProxyContractDoesNotExist = 'TOKEN_TRANSFER_PROXY_CONTRACT_DOES_NOT_EXIST',
+ TokenRegistryContractDoesNotExist = 'TOKEN_REGISTRY_CONTRACT_DOES_NOT_EXIST',
+ TokenContractDoesNotExist = 'TOKEN_CONTRACT_DOES_NOT_EXIST',
UnhandledError = 'UNHANDLED_ERROR',
UserHasNoAssociatedAddress = 'USER_HAS_NO_ASSOCIATED_ADDRESSES',
InvalidSignature = 'INVALID_SIGNATURE',
@@ -443,7 +446,10 @@ export interface TransactionReceiptWithDecodedLogs extends TransactionReceipt {
logs: Array<LogWithDecodedArgs<DecodedLogArgs>|Web3.LogEntry>;
}
+export type ArtifactContractName = 'ZRX'|'TokenTransferProxy'|'TokenRegistry'|'Token'|'Exchange'|'EtherToken';
+
export interface Artifact {
+ contract_name: ArtifactContractName;
abi: Web3.ContractAbi;
networks: {
[networkId: number]: {
diff --git a/packages/0x.js/src/web3_wrapper.ts b/packages/0x.js/src/web3_wrapper.ts
index 557cd28e5..a031de486 100644
--- a/packages/0x.js/src/web3_wrapper.ts
+++ b/packages/0x.js/src/web3_wrapper.ts
@@ -4,7 +4,7 @@ import * as _ from 'lodash';
import * as Web3 from 'web3';
import {Contract} from './contract';
-import {Artifact, TransactionReceipt, ZeroExError} from './types';
+import {Artifact, ArtifactContractName, TransactionReceipt, ZeroExError} from './types';
interface RawLogEntry {
logIndex: string|null;
@@ -17,6 +17,15 @@ interface RawLogEntry {
topics: string[];
}
+const CONTRACT_NAME_TO_NOT_FOUND_ERROR: {[contractName: string]: ZeroExError} = {
+ ZRX: ZeroExError.ZRXContractDoesNotExist,
+ EtherToken: ZeroExError.EtherTokenContractDoesNotExist,
+ Token: ZeroExError.TokenContractDoesNotExist,
+ TokenRegistry: ZeroExError.TokenRegistryContractDoesNotExist,
+ TokenTransferProxy: ZeroExError.TokenTransferProxyContractDoesNotExist,
+ Exchange: ZeroExError.ExchangeContractDoesNotExist,
+};
+
export class Web3Wrapper {
private web3: Web3;
private networkId: number;
@@ -77,7 +86,7 @@ export class Web3Wrapper {
}
const doesContractExist = await this.doesContractExistAtAddressAsync(contractAddress);
if (!doesContractExist) {
- throw new Error(ZeroExError.ContractDoesNotExist);
+ throw new Error(CONTRACT_NAME_TO_NOT_FOUND_ERROR[artifact.contract_name]);
}
const contractInstance = this.getContractInstance<A>(
artifact.abi, contractAddress,