From c9e490bdaec53e3a93b5da8daaaf0b1d87d9de76 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 4 Sep 2017 19:08:14 +0200 Subject: Implement zeroEx.awaitTransactionMined --- src/0x.ts | 14 ++++++++++++++ src/web3_wrapper.ts | 4 ++++ 2 files changed, 18 insertions(+) (limited to 'src') diff --git a/src/0x.ts b/src/0x.ts index 3cf672a1b..e92c92e1f 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -1,5 +1,6 @@ import * as _ from 'lodash'; import * as BigNumber from 'bignumber.js'; +import * as Web3 from 'web3'; import {SchemaValidator, schemas} from '0x-json-schemas'; import {bigNumberConfigs} from './bignumber_config'; import * as ethUtil from 'ethereumjs-util'; @@ -248,4 +249,17 @@ export class ZeroEx { throw new Error(ZeroExError.InvalidSignature); } + public async awaitTransactionMined(txHash: string, + pollingIntervalMs: number = 500): Promise { + const txReceiptPromise = new Promise((resolve: (receipt: Web3.TransactionReceipt) => void, reject) => { + const intervalId = setInterval(async () => { + const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); + if (!_.isNull(transactionReceipt)) { + clearInterval(intervalId); + resolve(transactionReceipt); + } + }, pollingIntervalMs); + }); + return txReceiptPromise; + } } diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index 129017e7c..f3fe8a00b 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -27,6 +27,10 @@ export class Web3Wrapper { const nodeVersion = await promisify(this.web3.version.getNode)(); return nodeVersion; } + public async getTransactionReceiptAsync(txHash: string): Promise { + const transactionReceipt = await promisify(this.web3.eth.getTransactionReceipt)(txHash); + return transactionReceipt; + } public getCurrentProvider(): Web3.Provider { return this.web3.currentProvider; } -- cgit v1.2.3