UNPKG

@kaiachain/web3js-ext

Version:
51 lines (47 loc) 2.63 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/get_transaction_error.ts Object.defineProperty(exports, "__esModule", { value: true }); exports.getTransactionError = getTransactionError; const web3_errors_1 = require("web3-errors"); const get_revert_reason_js_1 = require("./get_revert_reason.js"); async function getTransactionError(web3Context, transactionFormatted, transactionReceiptFormatted, receivedError, contractAbi, knownReason) { let _reason = knownReason; if (_reason === undefined) { if (receivedError !== undefined) { _reason = (0, get_revert_reason_js_1.parseTransactionError)(receivedError); } else if (web3Context.handleRevert && transactionFormatted !== undefined) { _reason = await (0, get_revert_reason_js_1.getRevertReason)(web3Context, transactionFormatted, contractAbi); } } let error; if (_reason === undefined) { error = new web3_errors_1.TransactionRevertedWithoutReasonError(transactionReceiptFormatted); } else if (typeof _reason === "string") { error = new web3_errors_1.TransactionRevertInstructionError(_reason, undefined, transactionReceiptFormatted); } else if (_reason.customErrorName !== undefined && _reason.customErrorDecodedSignature !== undefined && _reason.customErrorArguments !== undefined) { const reasonWithCustomError = _reason; error = new web3_errors_1.TransactionRevertWithCustomError(reasonWithCustomError.reason, reasonWithCustomError.customErrorName, reasonWithCustomError.customErrorDecodedSignature, reasonWithCustomError.customErrorArguments, reasonWithCustomError.signature, transactionReceiptFormatted, reasonWithCustomError.data); } else { error = new web3_errors_1.TransactionRevertInstructionError(_reason.reason, _reason.signature, transactionReceiptFormatted, _reason.data); } return error; }