Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 105e814

Browse files
committed
decoupled pub/sub and polling paradigms in contract deployment timeout
1 parent c9ca65d commit 105e814

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

packages/web3-core-method/src/index.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var promiEvent = require('web3-core-promievent');
3131
var Subscriptions = require('web3-core-subscriptions').subscriptions;
3232

3333
var TIMEOUTBLOCK = 50;
34+
var POLLINGTIMEOUT = 15 * TIMEOUTBLOCK; // ~average block time (seconds) * TIMEOUTBLOCK
3435
var CONFIRMATIONBLOCKS = 24;
3536

3637
var Method = function Method(options) {
@@ -240,7 +241,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
240241

241242

242243
// fire "receipt" and confirmation events and resolve after
243-
var checkConfirmation = function (err, blockHeader, sub, existingReceipt) {
244+
var checkConfirmation = function (err, blockHeader, sub, existingReceipt, isPolling) {
244245
if (!err) {
245246
// create fake unsubscribe
246247
if (!sub) {
@@ -369,10 +370,20 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
369370
.catch(function () {
370371
timeoutCount++;
371372

372-
if (timeoutCount - 1 >= TIMEOUTBLOCK) {
373-
sub.unsubscribe();
374-
promiseResolved = true;
375-
return utils._fireError(new Error('Transaction was not mined within 50 blocks, please make sure your transaction was properly sent. Be aware that it might still be mined!'), defer.eventEmitter, defer.reject);
373+
// check to see if we are http polling
374+
if(!!isPolling) {
375+
// polling timeout is different than TIMEOUTBLOCK blocks since we are triggering every second
376+
if (timeoutCount - 1 >= POLLINGTIMEOUT) {
377+
sub.unsubscribe();
378+
promiseResolved = true;
379+
return utils._fireError(new Error('Transaction was not mined within' + POLLINGTIMEOUT + ' seconds, please make sure your transaction was properly sent. Be aware that it might still be mined!'), defer.eventEmitter, defer.reject);
380+
}
381+
} else {
382+
if (timeoutCount - 1 >= TIMEOUTBLOCK) {
383+
sub.unsubscribe();
384+
promiseResolved = true;
385+
return utils._fireError(new Error('Transaction was not mined within 50 blocks, please make sure your transaction was properly sent. Be aware that it might still be mined!'), defer.eventEmitter, defer.reject);
386+
}
376387
}
377388
});
378389

@@ -390,7 +401,10 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
390401
if (_.isFunction(this.requestManager.provider.on)) {
391402
_ethereumCall.subscribe('newBlockHeaders', checkConfirmation);
392403
} else {
393-
intervalId = setInterval(checkConfirmation, 1000);
404+
// if provider is http and polling
405+
intervalId = setInterval(function() {
406+
checkConfirmation(null, null, null, null, true);
407+
}, 1000);
394408
}
395409
}.bind(this);
396410

0 commit comments

Comments
 (0)