aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-10-30 17:34:26 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-11-10 03:11:45 +0800
commit3ddb203317065a85531a31daa1ae2d73232ca6df (patch)
tree259e473b1e648d3c7dac712ce4363a40964abff9 /src
parent84b8e77aaae3a2c6848bcd1ffab78a2de81e6138 (diff)
downloaddexon-sol-tools-3ddb203317065a85531a31daa1ae2d73232ca6df.tar.gz
dexon-sol-tools-3ddb203317065a85531a31daa1ae2d73232ca6df.tar.zst
dexon-sol-tools-3ddb203317065a85531a31daa1ae2d73232ca6df.zip
Move provider altering logic to Web3Wrapper
Diffstat (limited to 'src')
-rw-r--r--src/0x.ts6
-rw-r--r--src/mempool/order_watcher.ts21
-rw-r--r--src/web3_wrapper.ts10
3 files changed, 19 insertions, 18 deletions
diff --git a/src/0x.ts b/src/0x.ts
index 4bd37c260..0fb968ef3 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -177,12 +177,6 @@ export class ZeroEx {
if (!_.isUndefined(config)) {
assert.doesConformToSchema('config', config, zeroExConfigSchema);
}
- if (_.isUndefined((provider as any).sendAsync)) {
- // Web3@1.0 provider doesn't support synchronous http requests,
- // so it only has an async `send` method, instead of a `send` and `sendAsync` in web3@0.x.x`
- // We re-assign the send method so that Web3@1.0 providers work with 0x.js
- (provider as any).sendAsync = (provider as any).send;
- }
const artifactJSONs = _.values(artifacts);
const abiArrays = _.map(artifactJSONs, artifact => artifact.abi);
this._abiDecoder = new AbiDecoder(abiArrays);
diff --git a/src/mempool/order_watcher.ts b/src/mempool/order_watcher.ts
index 90c15cd34..b2c8598e7 100644
--- a/src/mempool/order_watcher.ts
+++ b/src/mempool/order_watcher.ts
@@ -1,22 +1,23 @@
-import * as Web3 from 'web3';
import * as _ from 'lodash';
-import {Web3Provider, SignedOrder} from '../types';
+import {ZeroEx} from '../';
+import {assert} from '../utils/assert';
+import {Web3Provider, SignedOrder, OnOrderFillabilityStateChangeCallback} from '../types';
import {Web3Wrapper} from '../web3_wrapper';
export class OrderWatcher {
+ private _orders = new Map<string, SignedOrder>();
+ private _web3Wrapper: Web3Wrapper;
constructor(provider: Web3Provider) {
- if (_.isUndefined((provider as any).sendAsync)) {
- // Web3@1.0 provider doesn't support synchronous http requests,
- // so it only has an async `send` method, instead of a `send` and `sendAsync` in web3@0.x.x`
- // We re-assign the send method so that Web3@1.0 providers work with 0x.js
- (provider as any).sendAsync = (provider as any).send;
- }
+ assert.isWeb3Provider('provider', provider);
+ this._web3Wrapper = new Web3Wrapper(provider);
}
public addOrder(signedOrder: SignedOrder): void {
- //
+ const orderHash = ZeroEx.getOrderHashHex(signedOrder);
+ this._orders.set(orderHash, signedOrder);
}
public removeOrder(signedOrder: SignedOrder): void {
- //
+ const orderHash = ZeroEx.getOrderHashHex(signedOrder);
+ this._orders.delete(orderHash);
}
public subscribe(callback: OnOrderFillabilityStateChangeCallback): void {
//
diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts
index 3b1e4477b..01d572654 100644
--- a/src/web3_wrapper.ts
+++ b/src/web3_wrapper.ts
@@ -10,10 +10,16 @@ export class Web3Wrapper {
private defaults: Partial<Web3.TxData>;
private networkIdIfExists?: number;
private jsonRpcRequestId: number;
- constructor(provider: Web3.Provider, defaults: Partial<Web3.TxData>) {
+ constructor(provider: Web3.Provider, defaults?: Partial<Web3.TxData>) {
+ if (_.isUndefined((provider as any).sendAsync)) {
+ // Web3@1.0 provider doesn't support synchronous http requests,
+ // so it only has an async `send` method, instead of a `send` and `sendAsync` in web3@0.x.x`
+ // We re-assign the send method so that Web3@1.0 providers work with 0x.js
+ (provider as any).sendAsync = (provider as any).send;
+ }
this.web3 = new Web3();
this.web3.setProvider(provider);
- this.defaults = defaults;
+ this.defaults = defaults || {};
this.jsonRpcRequestId = 0;
}
public setProvider(provider: Web3.Provider) {