aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-06-19 23:42:25 +0800
committerFabio Berger <me@fabioberger.com>2017-06-19 23:42:25 +0800
commita8f706c79fb4244119a6d4ad03ea666689cc63fc (patch)
treef370ede530e5ae6f9b3530f7983c3e71e164156c /src
parentfe63a81f6a15a521c643b74f4442cdbf037202cf (diff)
parent36fe4c01aa5a86ef820c11bb0b2e4724c68e40b5 (diff)
downloaddexon-0x-contracts-a8f706c79fb4244119a6d4ad03ea666689cc63fc.tar.gz
dexon-0x-contracts-a8f706c79fb4244119a6d4ad03ea666689cc63fc.tar.zst
dexon-0x-contracts-a8f706c79fb4244119a6d4ad03ea666689cc63fc.zip
Merge branch 'master' of github.com:0xProject/0x.js
Diffstat (limited to 'src')
-rw-r--r--src/0x.ts15
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts3
-rw-r--r--src/index.ts5
-rw-r--r--src/types.ts38
-rw-r--r--src/web3_wrapper.ts6
5 files changed, 53 insertions, 14 deletions
diff --git a/src/0x.ts b/src/0x.ts
index d9e7b1b82..b75486902 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -14,9 +14,8 @@ import {ExchangeWrapper} from './contract_wrappers/exchange_wrapper';
import {TokenRegistryWrapper} from './contract_wrappers/token_registry_wrapper';
import {ecSignatureSchema} from './schemas/ec_signature_schema';
import {TokenWrapper} from './contract_wrappers/token_wrapper';
-import {ECSignature, ZeroExError, Order, SignedOrder} from './types';
+import {ECSignature, ZeroExError, Order, SignedOrder, Web3Provider} from './types';
import * as ExchangeArtifacts from './artifacts/Exchange.json';
-import {SchemaValidator} from './utils/schema_validator';
import {orderSchema} from './schemas/order_schemas';
// Customize our BigNumber instances
@@ -136,12 +135,12 @@ export class ZeroEx {
}
/**
* Instantiates a new ZeroEx instance that provides the public interface to the 0x.js library.
- * @param web3 The Web3.js instance you would like the 0x.js library to use for interacting with
- * the Ethereum network.
+ * @param provider The Web3.js Provider instance you would like the 0x.js library to use for interacting with
+ * the Ethereum network.
* @return An instance of the 0x.js ZeroEx class.
*/
- constructor(web3: Web3) {
- this._web3Wrapper = new Web3Wrapper(web3);
+ constructor(provider: Web3Provider) {
+ this._web3Wrapper = new Web3Wrapper(provider);
this.token = new TokenWrapper(this._web3Wrapper);
this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token);
this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper);
@@ -149,9 +148,9 @@ export class ZeroEx {
/**
* Sets a new provider for the web3 instance used by 0x.js. Updating the provider will stop all
* subscriptions so you will need to re-subscribe to all events relevant to your app after this call.
- * @param provider The Web3.Provider you would like the 0x.js library to use from now on.
+ * @param provider The Web3Provider you would like the 0x.js library to use from now on.
*/
- public async setProviderAsync(provider: Web3.Provider) {
+ public async setProviderAsync(provider: Web3Provider) {
this._web3Wrapper.setProvider(provider);
await this.exchange.invalidateContractInstanceAsync();
this.tokenRegistry.invalidateContractInstance();
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index 92eaa0f45..6b8ffd014 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -22,6 +22,7 @@ import {
ContractResponse,
OrderCancellationRequest,
OrderFillRequest,
+ LogErrorContractEventArgs,
} from '../types';
import {assert} from '../utils/assert';
import {utils} from '../utils/utils';
@@ -716,7 +717,7 @@ export class ExchangeWrapper extends ContractWrapper {
private _throwErrorLogsAsErrors(logs: ContractEvent[]): void {
const errEvent = _.find(logs, {event: 'LogError'});
if (!_.isUndefined(errEvent)) {
- const errCode = errEvent.args.errorId.toNumber();
+ const errCode = (errEvent.args as LogErrorContractEventArgs).errorId.toNumber()
const errMessage = this._exchangeContractErrCodesToMsg[errCode];
throw new Error(errMessage);
}
diff --git a/src/index.ts b/src/index.ts
index 48e83fc19..109718462 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -19,4 +19,9 @@ export {
OrderCancellationRequest,
OrderFillRequest,
ContractEventEmitter,
+ LogErrorContractEventArgs,
+ LogCancelArgs,
+ LogFillArgs,
+ ContractEventArgs,
+ Web3Provider,
} from './types';
diff --git a/src/types.ts b/src/types.ts
index 11d3182d8..c4191ebd8 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -1,4 +1,5 @@
import * as _ from 'lodash';
+import * as Web3 from 'web3';
// Utility function to create a K:V from a list of strings
// Adapted from: https://basarat.gitbooks.io/typescript/content/docs/types/literal-types.html
@@ -190,9 +191,38 @@ export interface ContractEvent {
address: string;
type: string;
event: string;
- args: any;
+ args: ContractEventArgs;
}
+export interface LogFillArgs {
+ maker: string;
+ taker: string;
+ feeRecipient: string;
+ tokenM: string;
+ tokenT: string;
+ filledValueM: BigNumber.BigNumber;
+ filledValueT: BigNumber.BigNumber;
+ feeMPaid: BigNumber.BigNumber;
+ feeTPaid: BigNumber.BigNumber;
+ tokens: string;
+ orderHash: string;
+}
+export interface LogCancelArgs {
+ maker: string;
+ feeRecipient: string;
+ tokenM: string;
+ tokenT: string;
+ cancelledValueM: BigNumber.BigNumber;
+ cancelledValueT: BigNumber.BigNumber;
+ tokens: string;
+ orderHash: string;
+}
+export interface LogErrorContractEventArgs {
+ errorId: BigNumber.BigNumber;
+ orderHash: string;
+}
+export type ContractEventArgs = LogFillArgs|LogCancelArgs|LogErrorContractEventArgs;
+
export interface Order {
maker: string;
taker: string;
@@ -280,3 +310,9 @@ export interface ContractEventEmitter {
watch: (eventCallback: EventCallback) => void;
stopWatchingAsync: () => Promise<void>;
}
+/**
+ * We re-export the `Web3.Provider` type specified in the Web3 Typescript typings
+ * since it is the type of the `provider` argument to the `ZeroEx` constructor.
+ * It is however a `Web3` library type, not a native `0x.js` type.
+ */
+export type Web3Provider = Web3.Provider;
diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts
index 05a8dc063..6bdca499f 100644
--- a/src/web3_wrapper.ts
+++ b/src/web3_wrapper.ts
@@ -2,14 +2,12 @@ import * as _ from 'lodash';
import * as Web3 from 'web3';
import * as BigNumber from 'bignumber.js';
import promisify = require('es6-promisify');
-import {ZeroExError} from './types';
-import {assert} from './utils/assert';
export class Web3Wrapper {
private web3: Web3;
- constructor(web3: Web3) {
+ constructor(provider: Web3.Provider) {
this.web3 = new Web3();
- this.web3.setProvider(web3.currentProvider);
+ this.web3.setProvider(provider);
}
public setProvider(provider: Web3.Provider) {
this.web3.setProvider(provider);