diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-06-12 12:56:56 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-12 12:56:56 +0800 |
commit | 746b1d0c4d0c5a6442373655877b268d365f9a0a (patch) | |
tree | db0b26808f00347fb4774b52b5539402dbf0335b /packages/web3-wrapper | |
parent | 387c80e00af6db337f23ad9a762fcb5ca0cd7d09 (diff) | |
parent | b916e7f7ef020c6208febe3ba69f4177346daab2 (diff) | |
download | dexon-sol-tools-746b1d0c4d0c5a6442373655877b268d365f9a0a.tar dexon-sol-tools-746b1d0c4d0c5a6442373655877b268d365f9a0a.tar.gz dexon-sol-tools-746b1d0c4d0c5a6442373655877b268d365f9a0a.tar.bz2 dexon-sol-tools-746b1d0c4d0c5a6442373655877b268d365f9a0a.tar.lz dexon-sol-tools-746b1d0c4d0c5a6442373655877b268d365f9a0a.tar.xz dexon-sol-tools-746b1d0c4d0c5a6442373655877b268d365f9a0a.tar.zst dexon-sol-tools-746b1d0c4d0c5a6442373655877b268d365f9a0a.zip |
Merge pull request #688 from 0xProject/feature/await-transaction-speedup
Speedup awaitTransactionMinedAsync and reduce polling interval in contracts tests
Diffstat (limited to 'packages/web3-wrapper')
-rw-r--r-- | packages/web3-wrapper/CHANGELOG.json | 5 | ||||
-rw-r--r-- | packages/web3-wrapper/src/web3_wrapper.ts | 17 |
2 files changed, 21 insertions, 1 deletions
diff --git a/packages/web3-wrapper/CHANGELOG.json b/packages/web3-wrapper/CHANGELOG.json index 35a8e2c05..bd4bf06dd 100644 --- a/packages/web3-wrapper/CHANGELOG.json +++ b/packages/web3-wrapper/CHANGELOG.json @@ -29,6 +29,11 @@ { "note": "Add new setHeadAsync method", "pr": 622 + }, + { + "note": + "Improve performance of awaitTransactionMinedAsync by immediately checking if the transaction was already mined instead of waiting for the first interval.", + "pr": 688 } ] }, diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts index 780695091..5d2eedcb3 100644 --- a/packages/web3-wrapper/src/web3_wrapper.ts +++ b/packages/web3-wrapper/src/web3_wrapper.ts @@ -402,6 +402,21 @@ export class Web3Wrapper { pollingIntervalMs: number = 1000, timeoutMs?: number, ): Promise<TransactionReceiptWithDecodedLogs> { + // Immediately check if the transaction has already been mined. + let transactionReceipt = await this.getTransactionReceiptAsync(txHash); + if (!_.isNull(transactionReceipt)) { + const logsWithDecodedArgs = _.map( + transactionReceipt.logs, + this.abiDecoder.tryToDecodeLogOrNoop.bind(this.abiDecoder), + ); + const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs = { + ...transactionReceipt, + logs: logsWithDecodedArgs, + }; + return transactionReceiptWithDecodedLogArgs; + } + + // Otherwise, check again every pollingIntervalMs. let wasTimeoutExceeded = false; if (timeoutMs) { setTimeout(() => (wasTimeoutExceeded = true), timeoutMs); @@ -416,7 +431,7 @@ export class Web3Wrapper { return reject(Web3WrapperErrors.TransactionMiningTimeout); } - const transactionReceipt = await this.getTransactionReceiptAsync(txHash); + transactionReceipt = await this.getTransactionReceiptAsync(txHash); if (!_.isNull(transactionReceipt)) { intervalUtils.clearAsyncExcludingInterval(intervalId); const logsWithDecodedArgs = _.map( |