1234567891011121314151617181920212223242526272829303132333435363738 |
- // From https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6
- function transactionMined (txnHash, interval) {
- var transactionReceiptAsync;
- interval = interval || 500;
- transactionReceiptAsync = function (txnHash, resolve, reject) {
- try {
- var receipt = web3.eth.getTransactionReceipt(txnHash);
- if (receipt === null) {
- setTimeout(function () {
- transactionReceiptAsync(txnHash, resolve, reject);
- }, interval);
- } else {
- resolve(receipt);
- }
- } catch (e) {
- reject(e);
- }
- };
- if (Array.isArray(txnHash)) {
- var promises = [];
- txnHash.forEach(function (oneTxHash) {
- promises.push(
- web3.eth.getTransactionReceiptMined(oneTxHash, interval));
- });
- return Promise.all(promises);
- } else {
- return new Promise(function (resolve, reject) {
- transactionReceiptAsync(txnHash, resolve, reject);
- });
- }
- }
- web3.eth.transactionMined = transactionMined;
- module.exports = {
- transactionMined,
- };
|