UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

100 lines (98 loc) 5.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeployHelper = void 0; const tslib_1 = require("tslib"); const ts_utils_1 = require("@neo-one/ts-utils"); const typescript_1 = tslib_1.__importDefault(require("typescript")); const Helper_1 = require("../Helper"); const utils_1 = require("./utils"); class DeployHelper extends Helper_1.Helper { constructor({ contractInfo, propInfo }) { super(); this.contractInfo = contractInfo; this.propInfo = propInfo; } emit(sb, node, optionsIn) { const options = sb.pushValueOptions(optionsIn); const handleDeployProperties = (contractInfo, innerOptions) => { contractInfo.propInfos .filter((prop) => prop.classDecl === contractInfo.smartContract) .forEach((propertyPropInfo) => { if (propertyPropInfo.type === 'property' && propertyPropInfo.structuredStorageType === undefined) { const property = propertyPropInfo.decl; if (typescript_1.default.isPropertyDeclaration(property)) { const initializer = ts_utils_1.tsUtils.initializer.getInitializer(property); const propNode = initializer === undefined ? property : initializer; if (initializer === undefined) { sb.emitHelper(propNode, sb.pushValueOptions(innerOptions), sb.helpers.wrapUndefined); } else { sb.visit(initializer, sb.pushValueOptions(innerOptions)); } sb.emitPushString(property, ts_utils_1.tsUtils.node.getName(property)); sb.emitHelper(property, innerOptions, sb.helpers.putCommonStorage); } else if (typescript_1.default.isParameterPropertyDeclaration(property, property.parent)) { const name = ts_utils_1.tsUtils.node.getName(property); sb.scope.get(sb, property, sb.pushValueOptions(innerOptions), name); sb.emitPushString(property, name); sb.emitHelper(property, innerOptions, sb.helpers.putCommonStorage); } } }); }; const handleDeploy = (currentContractInfo, propInfo, innerOptions, entry = true) => { const decl = propInfo.decl; const superDeploy = utils_1.findSuperDeployPropInfo(currentContractInfo); if (decl === undefined) { if (superDeploy === undefined) { handleDeployProperties(currentContractInfo, innerOptions); } else { handleDeploy(superDeploy[0], superDeploy[1], innerOptions, entry); handleDeployProperties(currentContractInfo, innerOptions); } } else { if (entry) { sb.emitPushInt(decl, 1); sb.emitHelper(decl, innerOptions, sb.helpers.getArgument); } sb.withScope(decl, innerOptions, (innerInnerOptions) => { sb.emitHelper(decl, innerInnerOptions, sb.helpers.parameters({ params: ts_utils_1.tsUtils.parametered.getParameters(decl), mapParam: entry ? utils_1.createWrapParam(sb) : undefined, })); const invokeOptions = sb.handleSuperConstructOptions(sb.noPushValueOptions(innerInnerOptions), (expr, _superExpr, innerInnerInnerOptionsIn) => { if (superDeploy === undefined) { return; } const innerInnerInnerOptions = sb.pushValueOptions(innerInnerInnerOptionsIn); sb.emitHelper(expr, innerInnerInnerOptions, sb.helpers.args); handleDeploy(superDeploy[0], superDeploy[1], innerInnerInnerOptions, false); handleDeployProperties(currentContractInfo, innerInnerInnerOptions); }); if (superDeploy === undefined) { handleDeployProperties(currentContractInfo, innerInnerOptions); } sb.emitHelper(decl, invokeOptions, sb.helpers.invokeSmartContractMethod({ method: decl })); }); } }; sb.emitHelper(node, options, sb.helpers.if({ condition: () => { sb.emitHelper(this.propInfo.decl === undefined ? node : this.propInfo.decl, options, sb.helpers.isDeployed); }, whenTrue: () => { sb.emitPushBoolean(this.propInfo.decl === undefined ? this.propInfo.classDecl : this.propInfo.decl, false); }, whenFalse: () => { handleDeploy(this.contractInfo, this.propInfo, options); sb.emitHelper(this.propInfo.decl === undefined ? node : this.propInfo.decl, options, sb.helpers.setDeployed); sb.emitPushBoolean(this.propInfo.decl === undefined ? this.propInfo.classDecl : this.propInfo.decl, true); }, })); } } exports.DeployHelper = DeployHelper; //# sourceMappingURL=DeployHelper.js.map