UNPKG

@kiroboio/fct-core

Version:

Kirobo.io FCT Core library

85 lines 3.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isExternalVariable = isExternalVariable; exports.isComputedVariable = isComputedVariable; exports.isOutputVariable = isOutputVariable; exports.isGlobalVariable = isGlobalVariable; exports.isConstantVariable = isConstantVariable; const constants_1 = require("../constants"); const helpers_1 = require("../helpers"); const globalVariables_1 = require("./globalVariables"); function isExternalVariable(value) { if (helpers_1.InstanceOf.Variable(value)) { return value.type === "external"; } if (typeof value === "string" && (value.length === 42 || value.length === 66)) { const hexString = value.toLowerCase(); const base = value.length === 42 ? constants_1.ExternalVariableBaseAddress.toLowerCase() : constants_1.ExternalVariableBaseBytes32.toLowerCase(); return hexString.slice(0, -4) === base.slice(0, -4); } return false; } function isComputedVariable({ value, id, index, strict = false }) { if (helpers_1.InstanceOf.CoreVariable(value)) { const idCheck = id ? value.id === id : true; return value.type === "computed" && idCheck; } if (typeof value === "string" && (value.length === 42 || value.length === 66)) { const hexString = value.toLowerCase(); const base = value.length === 42 ? constants_1.ComputedBaseAddress.toLowerCase() : constants_1.ComputedBaseBytes32.toLowerCase(); if (hexString.slice(0, -4) === base.slice(0, -4)) { if (!strict) return true; const parsedIndex = parseInt(hexString.slice(-4), 16).toString(); return parsedIndex === (index + 1).toString(); } } return false; } function isOutputVariable({ value, index, strict = false, }) { if (helpers_1.InstanceOf.Variable(value)) { return value.type === "output"; } if (typeof value === "string" && (value.length === 42 || value.length === 66)) { const hexString = value.toLowerCase(); const base = value.length === 42 ? constants_1.OutputVariableBaseAddress.toLowerCase() : constants_1.OutputVariableBaseBytes32.toLowerCase(); const backBase = value.length === 42 ? constants_1.BackOutputVariableBaseAddress.toLowerCase() : constants_1.BackOutputVariableBaseBytes32.toLowerCase(); if (hexString.slice(0, -8) === base.slice(0, -8)) { if (!strict) return true; const parsedIndex = parseInt(hexString.slice(-4), 16).toString(); return parsedIndex === (index + 1).toString(); } if (hexString.slice(0, -8) === backBase.slice(0, -8)) { if (!strict) return true; const parsedIndex = parseInt(hexString.slice(-4), 16).toString(); return parsedIndex === (index + 1).toString(); } } return false; } function isGlobalVariable(value) { if (helpers_1.InstanceOf.Variable(value)) { return value.type === "global"; } if (typeof value === "string" && (value.length === 42 || value.length === 66)) { if (value.length === 42) { const setOfGlobalVars = Object.values(globalVariables_1.globalVariables); const valHexString = value.toLowerCase(); return setOfGlobalVars.some((variable) => variable.toLowerCase().slice(0, -4) === valHexString.slice(0, -4)); } else { const setOfGlobalVars = Object.values(globalVariables_1.globalVariablesBytes); const valHexString = value.toLowerCase(); return setOfGlobalVars.some((variable) => variable.toLowerCase().slice(0, -4) === valHexString.slice(0, -4)); } } return false; } function isConstantVariable(value) { if (helpers_1.InstanceOf.Variable(value)) { return value.type === "constants"; } } //# sourceMappingURL=isVariable.js.map