UNPKG

hardhat-scilla-plugin

Version:
73 lines 2.69 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createTemporaryFile = createTemporaryFile; exports.deleteTemporaryFile = deleteTemporaryFile; exports.useNativeScilla = useNativeScilla; exports.decodeTransactionErrors = decodeTransactionErrors; exports.stringifyTransactionErrors = stringifyTransactionErrors; exports.getEventLog = getEventLog; const core_1 = require("@zilliqa-js/core"); const fs_1 = __importDefault(require("fs")); const os_1 = __importDefault(require("os")); const path_1 = __importDefault(require("path")); /** Create a temporary file and return its name */ function createTemporaryFile(prefix, extension) { const tempDir = os_1.default.tmpdir(); const dirName = fs_1.default.mkdtempSync(`${tempDir}/${prefix}`); return `${dirName}/temp${prefix}.${extension}`; } /** Delete the temporary file and its directory */ function deleteTemporaryFile(fileName) { // Find the parent directory const parent = path_1.default.dirname(fileName); // console.log(`Would delete ${parent}`); fs_1.default.rmSync(parent, { recursive: true, force: true }); } /** Should we use native scilla binaries? */ function useNativeScilla() { return process.env.USE_NATIVE_SCILLA !== undefined; } /** Given a transaction, return a string[][] array containing a list of errors, decoded into their * symbolic values, for each level of the transaction. */ function decodeTransactionErrors(txn) { const receipt = txn.getReceipt(); if (receipt === undefined) { return []; } if (receipt.errors === undefined) { return []; } const rv = []; const errors = receipt.errors; for (const key in errors) { const our_errors = []; for (const err in errors[key]) { our_errors.push(`${err} (${core_1.TransactionError[err]})`); } rv.push(our_errors); } return rv; } /** Given a transaction, get the errors from the receipt and return a human-readable string that * can be used to display them. */ function stringifyTransactionErrors(txn) { const errors = decodeTransactionErrors(txn); let result = ""; for (const level in errors) { result = result + "[" + errors[level].join(",") + "] "; } return result; } /** Given a transaction, extract the event log in case you want to read parameters of it */ async function getEventLog(tx) { const receipt = tx.getReceipt(); const event_logs = receipt.event_logs; return event_logs; } //# sourceMappingURL=ZilliqaUtils.js.map