UNPKG

hardhat-scilla-plugin

Version:
58 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.simplifyLogs = void 0; const bignumber_1 = require("@ethersproject/bignumber"); const ScillaParser_1 = require("../parser/ScillaParser"); const simplifyLogs = function (logs) { for (const log of logs) { log.params.forEach((param) => { if ((0, ScillaParser_1.isNumeric)(param.type)) { param.value = simplifyNumber(param.type, param.value); } else if (param.type.startsWith("Option")) { param = simplifyOption(param); } else if (param.type === "Bool") { param = simplifyBool(param); } }); } return logs; }; exports.simplifyLogs = simplifyLogs; const simplifyNumber = function (type, n) { switch (type) { case "Uint32": case "Int64": case "Uint64": return Number(n); case "Uint128": case "Int128": case "Uint256": case "Int256": return bignumber_1.BigNumber.from(n); default: break; } return n; }; const simplifyOption = function (param) { const constr = param.value.constructor; if (constr === "None") { param.value = null; } else { const innerType = param.value.argtypes[0]; const innerValue = param.value.arguments[0]; if ((0, ScillaParser_1.isNumeric)(innerType)) { param.value = simplifyNumber(innerType, innerValue); } } return param; }; const simplifyBool = function (param) { const constr = param.value.constructor; param.value = constr === "True" ? true : false; return param; }; //# sourceMappingURL=LogsSimplifier.js.map