aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Autry <lukeautry@gmail.com>2017-11-10 23:43:52 +0800
committerLuke Autry <lukeautry@gmail.com>2017-11-10 23:43:52 +0800
commit583b92e672d5ff644d79e3a75dd8c9b6cc85932a (patch)
tree9a43bb2c0ecedd37a78867fd6d79ed1ced91e94a
parenta7bedad9f020cf0bbd91d3823a14a0711ea78e0b (diff)
downloaddexon-sol-tools-583b92e672d5ff644d79e3a75dd8c9b6cc85932a.tar
dexon-sol-tools-583b92e672d5ff644d79e3a75dd8c9b6cc85932a.tar.gz
dexon-sol-tools-583b92e672d5ff644d79e3a75dd8c9b6cc85932a.tar.bz2
dexon-sol-tools-583b92e672d5ff644d79e3a75dd8c9b6cc85932a.tar.lz
dexon-sol-tools-583b92e672d5ff644d79e3a75dd8c9b6cc85932a.tar.xz
dexon-sol-tools-583b92e672d5ff644d79e3a75dd8c9b6cc85932a.tar.zst
dexon-sol-tools-583b92e672d5ff644d79e3a75dd8c9b6cc85932a.zip
allow timeout for await transaction mined
-rw-r--r--src/0x.ts13
-rw-r--r--src/types.ts1
2 files changed, 13 insertions, 1 deletions
diff --git a/src/0x.ts b/src/0x.ts
index bc753434c..2208e5ec8 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -289,10 +289,11 @@ export class ZeroEx {
* Waits for a transaction to be mined and returns the transaction receipt.
* @param txHash Transaction hash
* @param pollingIntervalMs How often (in ms) should we check if the transaction is mined.
+ * @param timeoutMs How long (in ms) to poll for transaction mined until aborting.
* @return Transaction receipt with decoded log args.
*/
public async awaitTransactionMinedAsync(
- txHash: string, pollingIntervalMs: number = 1000): Promise<TransactionReceiptWithDecodedLogs> {
+ txHash: string, pollingIntervalMs = 1000, timeoutMs?: number): Promise<TransactionReceiptWithDecodedLogs> {
const txReceiptPromise = new Promise(
(resolve: (receipt: TransactionReceiptWithDecodedLogs) => void, reject) => {
const intervalId = intervalUtils.setAsyncExcludingInterval(async () => {
@@ -311,6 +312,16 @@ export class ZeroEx {
}
}, pollingIntervalMs);
});
+
+ if (timeoutMs) {
+ return Promise.race([
+ txReceiptPromise,
+ new Promise<TransactionReceiptWithDecodedLogs>((resolve, reject) => {
+ setTimeout(() => reject(ZeroExError.TransactionMiningTimeout), timeoutMs);
+ })
+ ]);
+ }
+
return txReceiptPromise;
}
/*
diff --git a/src/types.ts b/src/types.ts
index 9ac726ef8..a9eac56d8 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -16,6 +16,7 @@ export enum ZeroExError {
OutOfGas = 'OUT_OF_GAS',
NoNetworkId = 'NO_NETWORK_ID',
SubscriptionNotFound = 'SUBSCRIPTION_NOT_FOUND',
+ TransactionMiningTimeout = 'TRANSACTION_MINING_TIMEOUT',
}
export enum InternalZeroExError {