aboutsummaryrefslogtreecommitdiffstats
path: root/src/web3_wrapper.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-11-13 10:12:37 +0800
committerFabio Berger <me@fabioberger.com>2017-11-13 10:12:37 +0800
commite33027c6244b99a1fb181404668bd2a259d923e2 (patch)
tree24438eda01318a80b5cbc7f1939d1640764a9859 /src/web3_wrapper.ts
parent5d2b6585c66fc17a36bb9841a3b3fb009e23024c (diff)
parentb0be323e899ea7be42b6c695b4fd6d526070b213 (diff)
downloaddexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar
dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar.gz
dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar.bz2
dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar.lz
dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar.xz
dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar.zst
dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.zip
Merge branch 'development' into feature/receipt-status
* development: (164 commits) Remove old tests Remove unused code Fix tests Remove redundant spaces Don't store empty objects Fix a typo Remove duplicate operations Remove redundant instance variables Fix tests Remove blockStore and default to numConfirmations === 0 Add a comment Store number of confirmations in a blockStore Remove tautology check Pass blockStore to eventWatcher Fix last merge conflicts Clear cache on unsubscribe Clear store cache on events Add more configs for order watcher Make subscribe function async and make blockStore operational Adjust tests to new interface ... # Conflicts: # package.json # src/types.ts # yarn.lock
Diffstat (limited to 'src/web3_wrapper.ts')
-rw-r--r--src/web3_wrapper.ts14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts
index be81fe78c..c937f9288 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) {
@@ -95,6 +101,10 @@ export class Web3Wrapper {
const signData = await promisify(this.web3.eth.sign)(address, message);
return signData;
}
+ public async getBlockNumberAsync(): Promise<number> {
+ const blockNumber = await promisify(this.web3.eth.getBlockNumber)();
+ return blockNumber;
+ }
public async getBlockAsync(blockParam: string|Web3.BlockParam): Promise<Web3.BlockWithoutTransactionData> {
const block = await promisify(this.web3.eth.getBlock)(blockParam);
return block;