transactionMined.js 980 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. //from https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6
  3. module.export = web3.eth.transactionMined = function (txnHash, interval) {
  4. var transactionReceiptAsync;
  5. interval = interval ? interval : 500;
  6. transactionReceiptAsync = function(txnHash, resolve, reject) {
  7. try {
  8. var receipt = web3.eth.getTransactionReceipt(txnHash);
  9. if (receipt === null) {
  10. setTimeout(function () {
  11. transactionReceiptAsync(txnHash, resolve, reject);
  12. }, interval);
  13. } else {
  14. resolve(receipt);
  15. }
  16. } catch(e) {
  17. reject(e);
  18. }
  19. };
  20. if (Array.isArray(txnHash)) {
  21. var promises = [];
  22. txnHash.forEach(function (oneTxHash) {
  23. promises.push(
  24. web3.eth.getTransactionReceiptMined(oneTxHash, interval));
  25. });
  26. return Promise.all(promises);
  27. } else {
  28. return new Promise(function (resolve, reject) {
  29. transactionReceiptAsync(txnHash, resolve, reject);
  30. });
  31. }
  32. };