aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-06-15 23:05:03 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-06-15 23:05:03 +0800
commitd789aa24aa2c9f4e0d17a382fe9cb8d56ab27957 (patch)
treed93f79ec7909c1808ddfe7a145df41d2c104a553
parent424912040a7e68b6d07cd4ae40763d9bcd98de28 (diff)
downloaddexon-sol-tools-d789aa24aa2c9f4e0d17a382fe9cb8d56ab27957.tar
dexon-sol-tools-d789aa24aa2c9f4e0d17a382fe9cb8d56ab27957.tar.gz
dexon-sol-tools-d789aa24aa2c9f4e0d17a382fe9cb8d56ab27957.tar.bz2
dexon-sol-tools-d789aa24aa2c9f4e0d17a382fe9cb8d56ab27957.tar.lz
dexon-sol-tools-d789aa24aa2c9f4e0d17a382fe9cb8d56ab27957.tar.xz
dexon-sol-tools-d789aa24aa2c9f4e0d17a382fe9cb8d56ab27957.tar.zst
dexon-sol-tools-d789aa24aa2c9f4e0d17a382fe9cb8d56ab27957.zip
Make ZeroEx constructor accept Web3Provider instead of Web3 instance
-rw-r--r--package.json2
-rw-r--r--src/0x.ts14
-rw-r--r--src/index.ts1
-rw-r--r--src/types.ts3
-rw-r--r--src/web3_wrapper.ts11
-rw-r--r--test/0x.js_test.ts6
-rw-r--r--test/assert_test.ts2
-rw-r--r--test/exchange_wrapper_test.ts2
-rw-r--r--test/token_registry_wrapper_test.ts2
-rw-r--r--test/token_wrapper_test.ts2
-rw-r--r--yarn.lock6
11 files changed, 27 insertions, 24 deletions
diff --git a/package.json b/package.json
index 386a2e232..bd077ad30 100644
--- a/package.json
+++ b/package.json
@@ -82,7 +82,7 @@
"typedoc": "^0.7.1",
"typescript": "^2.3.3",
"web3-provider-engine": "^13.0.1",
- "web3-typescript-typings": "0.0.8",
+ "web3-typescript-typings": "^0.0.9",
"webpack": "^2.6.0"
},
"dependencies": {
diff --git a/src/0x.ts b/src/0x.ts
index 74e4ef7e6..a9b2c41af 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -14,7 +14,7 @@ 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 {orderSchema} from './schemas/order_schemas';
@@ -122,12 +122,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);
@@ -135,9 +135,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/index.ts b/src/index.ts
index 48e83fc19..7b1a16125 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -19,4 +19,5 @@ export {
OrderCancellationRequest,
OrderFillRequest,
ContractEventEmitter,
+ Web3Provider,
} from './types';
diff --git a/src/types.ts b/src/types.ts
index 11d3182d8..8c9e9ad5d 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
@@ -280,3 +281,5 @@ export interface ContractEventEmitter {
watch: (eventCallback: EventCallback) => void;
stopWatchingAsync: () => Promise<void>;
}
+
+export type Web3Provider = Web3.Provider;
diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts
index 05a8dc063..5bff25233 100644
--- a/src/web3_wrapper.ts
+++ b/src/web3_wrapper.ts
@@ -2,16 +2,15 @@ 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';
+import {Web3Provider} from './types';
export class Web3Wrapper {
private web3: Web3;
- constructor(web3: Web3) {
+ constructor(provider: Web3Provider) {
this.web3 = new Web3();
- this.web3.setProvider(web3.currentProvider);
+ this.web3.setProvider(provider);
}
- public setProvider(provider: Web3.Provider) {
+ public setProvider(provider: Web3Provider) {
this.web3.setProvider(provider);
}
public isAddress(address: string): boolean {
@@ -25,7 +24,7 @@ export class Web3Wrapper {
const nodeVersion = await promisify(this.web3.version.getNode)();
return nodeVersion;
}
- public getCurrentProvider(): Web3.Provider {
+ public getCurrentProvider(): Web3Provider {
return this.web3.currentProvider;
}
public async getNetworkIdIfExistsAsync(): Promise<number|undefined> {
diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts
index 58f5c8533..005b9fa0c 100644
--- a/test/0x.js_test.ts
+++ b/test/0x.js_test.ts
@@ -15,7 +15,7 @@ describe('ZeroEx library', () => {
describe('#setProvider', () => {
it('overrides provider in nested web3s and invalidates contractInstances', async () => {
const web3 = web3Factory.create();
- const zeroEx = new ZeroEx(web3);
+ const zeroEx = new ZeroEx(web3.currentProvider);
// Instantiate the contract instances with the current provider
await (zeroEx.exchange as any)._getExchangeContractAsync();
await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync();
@@ -51,7 +51,7 @@ describe('ZeroEx library', () => {
};
const address = '0x5409ed021d9299bf6814279a6a1411a7e866a631';
const web3 = web3Factory.create();
- const zeroEx = new ZeroEx(web3);
+ const zeroEx = new ZeroEx(web3.currentProvider);
it('should return false if the data doesn\'t pertain to the signature & address', async () => {
expect(ZeroEx.isValidSignature('0x0', signature, address)).to.be.false();
return expect(
@@ -149,7 +149,7 @@ describe('ZeroEx library', () => {
});
it('calculates the order hash', async () => {
const web3 = web3Factory.create();
- const zeroEx = new ZeroEx(web3);
+ const zeroEx = new ZeroEx(web3.currentProvider);
stubs = [
Sinon.stub((zeroEx as any), '_getExchangeAddressAsync')
diff --git a/test/assert_test.ts b/test/assert_test.ts
index 25d9a8d16..6a8d30716 100644
--- a/test/assert_test.ts
+++ b/test/assert_test.ts
@@ -8,7 +8,7 @@ const expect = chai.expect;
describe('Assertion library', () => {
const web3 = web3Factory.create();
- const zeroEx = new ZeroEx(web3);
+ const zeroEx = new ZeroEx(web3.currentProvider);
describe('#isSenderAddressHexAsync', () => {
it('throws when address is invalid', async () => {
const address = '0xdeadbeef';
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index 28a5c719e..e4b2e3f86 100644
--- a/test/exchange_wrapper_test.ts
+++ b/test/exchange_wrapper_test.ts
@@ -39,7 +39,7 @@ describe('ExchangeWrapper', () => {
let fillScenarios: FillScenarios;
before(async () => {
web3 = web3Factory.create();
- zeroEx = new ZeroEx(web3);
+ zeroEx = new ZeroEx(web3.currentProvider);
userAddresses = await promisify(web3.eth.getAccounts)();
tokens = await zeroEx.tokenRegistry.getTokensAsync();
tokenUtils = new TokenUtils(tokens);
diff --git a/test/token_registry_wrapper_test.ts b/test/token_registry_wrapper_test.ts
index 158a02596..da436161c 100644
--- a/test/token_registry_wrapper_test.ts
+++ b/test/token_registry_wrapper_test.ts
@@ -18,7 +18,7 @@ describe('TokenRegistryWrapper', () => {
let zeroEx: ZeroEx;
before(async () => {
const web3 = web3Factory.create();
- zeroEx = new ZeroEx(web3);
+ zeroEx = new ZeroEx(web3.currentProvider);
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
diff --git a/test/token_wrapper_test.ts b/test/token_wrapper_test.ts
index 308d3b634..a1c035672 100644
--- a/test/token_wrapper_test.ts
+++ b/test/token_wrapper_test.ts
@@ -21,7 +21,7 @@ describe('TokenWrapper', () => {
let addressWithoutFunds: string;
before(async () => {
web3 = web3Factory.create();
- zeroEx = new ZeroEx(web3);
+ zeroEx = new ZeroEx(web3.currentProvider);
userAddresses = await promisify(web3.eth.getAccounts)();
tokens = await zeroEx.tokenRegistry.getTokensAsync();
coinbase = userAddresses[0];
diff --git a/yarn.lock b/yarn.lock
index 595f9a817..48cce8d89 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4467,9 +4467,9 @@ web3-provider-engine@~8.1.0:
xhr "^2.2.0"
xtend "^4.0.1"
-web3-typescript-typings@0.0.8:
- version "0.0.8"
- resolved "https://registry.yarnpkg.com/web3-typescript-typings/-/web3-typescript-typings-0.0.8.tgz#96997eeaf670fbaaf28d8814a1c27dce1a07df66"
+web3-typescript-typings@^0.0.9:
+ version "0.0.9"
+ resolved "https://registry.yarnpkg.com/web3-typescript-typings/-/web3-typescript-typings-0.0.9.tgz#f0c9e9bfcf0effaf16f3498b3d3883686451428b"
dependencies:
bignumber.js "^4.0.2"