UNPKG

@kaiachain/web3js-ext

Version:
60 lines (56 loc) 2.79 kB
"use strict"; /* This file is part of web3.js. web3.js is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. web3.js is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see <http://www.gnu.org/licenses/>. */ // Taken from https://github.com/web3/web3.js/blob/v4.3.0/packages/web3-eth/src/utils/wait_for_transaction_receipt.ts Object.defineProperty(exports, "__esModule", { value: true }); exports.waitForTransactionReceipt = void 0; const web3_errors_1 = require("web3-errors"); const web3_eth_1 = require("web3-eth"); const web3_utils_1 = require("web3-utils"); const reject_if_block_timeout_js_1 = require("./reject_if_block_timeout.js"); async function waitForTransactionReceipt(web3Context, transactionHash, returnFormat) { const pollingInterval = web3Context.transactionReceiptPollingInterval ?? web3Context.transactionPollingInterval; const [awaitableTransactionReceipt, IntervalId] = (0, web3_utils_1.pollTillDefinedAndReturnIntervalId)(async () => { try { return (0, web3_eth_1.getTransactionReceipt)(web3Context, transactionHash, returnFormat); } catch (error) { console.warn("An error happen while trying to get the transaction receipt", error); return undefined; } }, pollingInterval); const [timeoutId, rejectOnTimeout] = (0, web3_utils_1.rejectIfTimeout)(web3Context.transactionPollingTimeout, new web3_errors_1.TransactionPollingTimeoutError({ numberOfSeconds: web3Context.transactionPollingTimeout / 1000, transactionHash, })); const [rejectOnBlockTimeout, blockTimeoutResourceCleaner] = await (0, reject_if_block_timeout_js_1.rejectIfBlockTimeout)(web3Context, transactionHash); try { // If an error happened here, do not catch it, just clear the resources before raising it to the caller function. return await Promise.race([ awaitableTransactionReceipt, rejectOnTimeout, rejectOnBlockTimeout, // this will throw an error on Transaction Block Timeout ]); } finally { if (timeoutId) { clearTimeout(timeoutId); } if (IntervalId) { clearInterval(IntervalId); } blockTimeoutResourceCleaner.clean(); } } exports.waitForTransactionReceipt = waitForTransactionReceipt;