aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-03-28 17:05:36 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-04-02 17:34:29 +0800
commit4d9029bb0e3b215efdf165704c80d3bacef0e85a (patch)
tree8f699dcd0a7b5fba3c31c065a62d640407bba8c3 /packages/0x.js/src
parentbc49dde4d5d24b9a8b01459bde061f9b23fb5898 (diff)
downloaddexon-sol-tools-4d9029bb0e3b215efdf165704c80d3bacef0e85a.tar
dexon-sol-tools-4d9029bb0e3b215efdf165704c80d3bacef0e85a.tar.gz
dexon-sol-tools-4d9029bb0e3b215efdf165704c80d3bacef0e85a.tar.bz2
dexon-sol-tools-4d9029bb0e3b215efdf165704c80d3bacef0e85a.tar.lz
dexon-sol-tools-4d9029bb0e3b215efdf165704c80d3bacef0e85a.tar.xz
dexon-sol-tools-4d9029bb0e3b215efdf165704c80d3bacef0e85a.tar.zst
dexon-sol-tools-4d9029bb0e3b215efdf165704c80d3bacef0e85a.zip
Add metacoin example project
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r--packages/0x.js/src/0x.ts52
-rw-r--r--packages/0x.js/src/contract_wrappers/contract_wrapper.ts8
-rw-r--r--packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts4
-rw-r--r--packages/0x.js/src/contract_wrappers/exchange_wrapper.ts3
-rw-r--r--packages/0x.js/src/contract_wrappers/token_wrapper.ts9
-rw-r--r--packages/0x.js/src/globals.d.ts36
-rw-r--r--packages/0x.js/src/globalsAugment.d.ts23
-rw-r--r--packages/0x.js/src/order_watcher/order_state_watcher.ts5
-rw-r--r--packages/0x.js/src/types.ts1
9 files changed, 19 insertions, 122 deletions
diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts
index b82cc820f..87d8ffd39 100644
--- a/packages/0x.js/src/0x.ts
+++ b/packages/0x.js/src/0x.ts
@@ -58,7 +58,6 @@ export class ZeroEx {
*/
public proxy: TokenTransferProxyWrapper;
private _web3Wrapper: Web3Wrapper;
- private _abiDecoder: AbiDecoder;
/**
* Verifies that the elliptic curve signature `signature` was generated
* by signing `data` with the private key corresponding to the `signerAddress` address.
@@ -167,21 +166,22 @@ export class ZeroEx {
]);
const artifactJSONs = _.values(artifacts);
const abiArrays = _.map(artifactJSONs, artifact => artifact.abi);
- this._abiDecoder = new AbiDecoder(abiArrays);
const defaults = {
gasPrice: config.gasPrice,
};
this._web3Wrapper = new Web3Wrapper(provider, defaults);
+ _.forEach(abiArrays, abi => {
+ this._web3Wrapper.abiDecoder.addABI(abi);
+ });
this.proxy = new TokenTransferProxyWrapper(
this._web3Wrapper,
config.networkId,
config.tokenTransferProxyContractAddress,
);
- this.token = new TokenWrapper(this._web3Wrapper, config.networkId, this._abiDecoder, this.proxy);
+ this.token = new TokenWrapper(this._web3Wrapper, config.networkId, this.proxy);
this.exchange = new ExchangeWrapper(
this._web3Wrapper,
config.networkId,
- this._abiDecoder,
this.token,
config.exchangeContractAddress,
config.zrxContractAddress,
@@ -191,7 +191,7 @@ export class ZeroEx {
config.networkId,
config.tokenRegistryContractAddress,
);
- this.etherToken = new EtherTokenWrapper(this._web3Wrapper, config.networkId, this._abiDecoder, this.token);
+ this.etherToken = new EtherTokenWrapper(this._web3Wrapper, config.networkId, this.token);
}
/**
* Sets a new web3 provider for 0x.js. Updating the provider will stop all
@@ -285,44 +285,12 @@ export class ZeroEx {
pollingIntervalMs = 1000,
timeoutMs?: number,
): Promise<TransactionReceiptWithDecodedLogs> {
- let timeoutExceeded = false;
- if (timeoutMs) {
- setTimeout(() => (timeoutExceeded = true), timeoutMs);
- }
-
- const txReceiptPromise = new Promise(
- (resolve: (receipt: TransactionReceiptWithDecodedLogs) => void, reject) => {
- const intervalId = intervalUtils.setAsyncExcludingInterval(
- async () => {
- if (timeoutExceeded) {
- intervalUtils.clearAsyncExcludingInterval(intervalId);
- return reject(ZeroExError.TransactionMiningTimeout);
- }
-
- const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash);
- if (!_.isNull(transactionReceipt)) {
- intervalUtils.clearAsyncExcludingInterval(intervalId);
- const logsWithDecodedArgs = _.map(
- transactionReceipt.logs,
- this._abiDecoder.tryToDecodeLogOrNoop.bind(this._abiDecoder),
- );
- const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs = {
- ...transactionReceipt,
- logs: logsWithDecodedArgs,
- };
- resolve(transactionReceiptWithDecodedLogArgs);
- }
- },
- pollingIntervalMs,
- (err: Error) => {
- intervalUtils.clearAsyncExcludingInterval(intervalId);
- reject(err);
- },
- );
- },
+ const transactionReceiptWithDecodedLogs = await this._web3Wrapper.awaitTransactionMinedAsync(
+ txHash,
+ pollingIntervalMs,
+ timeoutMs,
);
- const txReceipt = await txReceiptPromise;
- return txReceipt;
+ return transactionReceiptWithDecodedLogs;
}
/**
* Instantiates and returns a new OrderStateWatcher instance.
diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
index 6c96428ed..02be2dab3 100644
--- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
@@ -32,7 +32,6 @@ const CONTRACT_NAME_TO_NOT_FOUND_ERROR: {
export class ContractWrapper {
protected _web3Wrapper: Web3Wrapper;
protected _networkId: number;
- private _abiDecoder?: AbiDecoder;
private _blockAndLogStreamerIfExists?: BlockAndLogStreamer;
private _blockAndLogStreamIntervalIfExists?: NodeJS.Timer;
private _filters: { [filterToken: string]: FilterObject };
@@ -41,10 +40,9 @@ export class ContractWrapper {
};
private _onLogAddedSubscriptionToken: string | undefined;
private _onLogRemovedSubscriptionToken: string | undefined;
- constructor(web3Wrapper: Web3Wrapper, networkId: number, abiDecoder?: AbiDecoder) {
+ constructor(web3Wrapper: Web3Wrapper, networkId: number) {
this._web3Wrapper = web3Wrapper;
this._networkId = networkId;
- this._abiDecoder = abiDecoder;
this._filters = {};
this._filterCallbacks = {};
this._blockAndLogStreamerIfExists = undefined;
@@ -102,10 +100,10 @@ export class ContractWrapper {
protected _tryToDecodeLogOrNoop<ArgsType extends ContractEventArgs>(
log: LogEntry,
): LogWithDecodedArgs<ArgsType> | RawLog {
- if (_.isUndefined(this._abiDecoder)) {
+ if (_.isUndefined(this._web3Wrapper.abiDecoder)) {
throw new Error(InternalZeroExError.NoAbiDecoder);
}
- const logWithDecodedArgs = this._abiDecoder.tryToDecodeLogOrNoop(log);
+ const logWithDecodedArgs = this._web3Wrapper.abiDecoder.tryToDecodeLogOrNoop(log);
return logWithDecodedArgs;
}
protected async _getContractAbiAndAddressFromArtifactsAsync(
diff --git a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
index 4a4da116b..f52dba2f1 100644
--- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
@@ -21,8 +21,8 @@ export class EtherTokenWrapper extends ContractWrapper {
[address: string]: EtherTokenContract;
} = {};
private _tokenWrapper: TokenWrapper;
- constructor(web3Wrapper: Web3Wrapper, networkId: number, abiDecoder: AbiDecoder, tokenWrapper: TokenWrapper) {
- super(web3Wrapper, networkId, abiDecoder);
+ constructor(web3Wrapper: Web3Wrapper, networkId: number, tokenWrapper: TokenWrapper) {
+ super(web3Wrapper, networkId);
this._tokenWrapper = tokenWrapper;
}
/**
diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
index 6b5a75a9a..53f32f111 100644
--- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
@@ -87,12 +87,11 @@ export class ExchangeWrapper extends ContractWrapper {
constructor(
web3Wrapper: Web3Wrapper,
networkId: number,
- abiDecoder: AbiDecoder,
tokenWrapper: TokenWrapper,
contractAddressIfExists?: string,
zrxContractAddressIfExists?: string,
) {
- super(web3Wrapper, networkId, abiDecoder);
+ super(web3Wrapper, networkId);
this._tokenWrapper = tokenWrapper;
this._orderValidationUtils = new OrderValidationUtils(this);
this._contractAddressIfExists = contractAddressIfExists;
diff --git a/packages/0x.js/src/contract_wrappers/token_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_wrapper.ts
index e350dfb92..5224d451c 100644
--- a/packages/0x.js/src/contract_wrappers/token_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/token_wrapper.ts
@@ -22,13 +22,8 @@ export class TokenWrapper extends ContractWrapper {
public UNLIMITED_ALLOWANCE_IN_BASE_UNITS = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
private _tokenContractsByAddress: { [address: string]: TokenContract };
private _tokenTransferProxyWrapper: TokenTransferProxyWrapper;
- constructor(
- web3Wrapper: Web3Wrapper,
- networkId: number,
- abiDecoder: AbiDecoder,
- tokenTransferProxyWrapper: TokenTransferProxyWrapper,
- ) {
- super(web3Wrapper, networkId, abiDecoder);
+ constructor(web3Wrapper: Web3Wrapper, networkId: number, tokenTransferProxyWrapper: TokenTransferProxyWrapper) {
+ super(web3Wrapper, networkId);
this._tokenContractsByAddress = {};
this._tokenTransferProxyWrapper = tokenTransferProxyWrapper;
}
diff --git a/packages/0x.js/src/globals.d.ts b/packages/0x.js/src/globals.d.ts
index 3e8ea21bc..3cd6d91b1 100644
--- a/packages/0x.js/src/globals.d.ts
+++ b/packages/0x.js/src/globals.d.ts
@@ -1,50 +1,14 @@
declare module 'web3_beta';
-declare module 'chai-bignumber';
-declare module 'dirty-chai';
declare module 'request-promise-native';
-declare module 'web3-provider-engine';
-declare module 'web3-provider-engine/subproviders/rpc';
-declare module 'publish-release';
// semver-sort declarations
declare module 'semver-sort' {
const desc: (versions: string[]) => string[];
}
-// HACK: In order to merge the bignumber declaration added by chai-bignumber to the chai Assertion
-// interface we must use `namespace` as the Chai definitelyTyped definition does. Since we otherwise
-// disallow `namespace`, we disable tslint for the following.
-/* tslint:disable */
-declare namespace Chai {
- interface Assertion {
- bignumber: Assertion;
- // HACK: In order to comply with chai-as-promised we make eventually a `PromisedAssertion` not an `Assertion`
- eventually: PromisedAssertion;
- }
-}
-/* tslint:enable */
-
declare module '*.json' {
const json: any;
/* tslint:disable */
export default json;
/* tslint:enable */
}
-
-declare module 'ethereumjs-abi' {
- const soliditySHA3: (argTypes: string[], args: any[]) => Buffer;
-}
-
-// truffle-hdwallet-provider declarations
-declare module 'truffle-hdwallet-provider' {
- import { JSONRPCRequestPayload, JSONRPCResponsePayload } from '@0xproject/types';
- import * as Web3 from 'web3';
- class HDWalletProvider implements Web3.Provider {
- constructor(mnemonic: string, rpcUrl: string);
- public sendAsync(
- payload: JSONRPCRequestPayload,
- callback: (err: Error, result: JSONRPCResponsePayload) => void,
- ): void;
- }
- export = HDWalletProvider;
-}
diff --git a/packages/0x.js/src/globalsAugment.d.ts b/packages/0x.js/src/globalsAugment.d.ts
deleted file mode 100644
index 3e2f2216b..000000000
--- a/packages/0x.js/src/globalsAugment.d.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { BigNumber } from '@0xproject/utils';
-
-// HACK: This module overrides the Chai namespace so that we can use BigNumber types inside.
-// Source: https://github.com/Microsoft/TypeScript/issues/7352#issuecomment-191547232
-declare global {
- // HACK: In order to merge the bignumber declaration added by chai-bignumber to the chai Assertion
- // interface we must use `namespace` as the Chai definitelyTyped definition does. Since we otherwise
- // disallow `namespace`, we disable tslint for the following.
- /* tslint:disable */
- namespace Chai {
- interface NumberComparer {
- (value: number | BigNumber, message?: string): Assertion;
- }
- interface NumericComparison {
- greaterThan: NumberComparer;
- }
- }
- /* tslint:enable */
- interface DecodedLogArg {
- name: string;
- value: string | BigNumber;
- }
-}
diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts
index cd6016c5a..0aa0c33bd 100644
--- a/packages/0x.js/src/order_watcher/order_state_watcher.ts
+++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts
@@ -69,7 +69,6 @@ export class OrderStateWatcher {
private _callbackIfExists?: OnOrderStateChangeCallback;
private _eventWatcher: EventWatcher;
private _web3Wrapper: Web3Wrapper;
- private _abiDecoder: AbiDecoder;
private _expirationWatcher: ExpirationWatcher;
private _orderStateUtils: OrderStateUtils;
private _orderFilledCancelledLazyStore: OrderFilledCancelledLazyStore;
@@ -78,12 +77,10 @@ export class OrderStateWatcher {
private _cleanupJobIntervalIdIfExists?: NodeJS.Timer;
constructor(
web3Wrapper: Web3Wrapper,
- abiDecoder: AbiDecoder,
token: TokenWrapper,
exchange: ExchangeWrapper,
config?: OrderStateWatcherConfig,
) {
- this._abiDecoder = abiDecoder;
this._web3Wrapper = web3Wrapper;
const pollingIntervalIfExistsMs = _.isUndefined(config) ? undefined : config.eventPollingIntervalMs;
const stateLayer =
@@ -230,7 +227,7 @@ export class OrderStateWatcher {
return;
}
const log = logIfExists as LogEvent; // At this moment we are sure that no error occured and log is defined.
- const maybeDecodedLog = this._abiDecoder.tryToDecodeLogOrNoop<ContractEventArgs>(log);
+ const maybeDecodedLog = this._web3Wrapper.abiDecoder.tryToDecodeLogOrNoop<ContractEventArgs>(log);
const isLogDecoded = !_.isUndefined(((maybeDecodedLog as any) as LogWithDecodedArgs<ContractEventArgs>).event);
if (!isLogDecoded) {
return; // noop
diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts
index 7f1f140ca..1f128d656 100644
--- a/packages/0x.js/src/types.ts
+++ b/packages/0x.js/src/types.ts
@@ -38,7 +38,6 @@ export enum ZeroExError {
NoNetworkId = 'NO_NETWORK_ID',
SubscriptionNotFound = 'SUBSCRIPTION_NOT_FOUND',
SubscriptionAlreadyPresent = 'SUBSCRIPTION_ALREADY_PRESENT',
- TransactionMiningTimeout = 'TRANSACTION_MINING_TIMEOUT',
}
export enum InternalZeroExError {