@neo-one/smart-contract-compiler
Version:
NEO•ONE TypeScript smart contract compiler.
47 lines (45 loc) • 2.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LinkedSmartContractFor = void 0;
const ts_utils_1 = require("@neo-one/ts-utils");
const DiagnosticCode_1 = require("../../../../DiagnosticCode");
const DiagnosticMessage_1 = require("../../../../DiagnosticMessage");
const SmartContractForBase_1 = require("../SmartContractForBase");
class LinkedSmartContractFor extends SmartContractForBase_1.SmartContractForBase {
emitAdditionalProperties(sb, _func, node, options) {
const scriptHash = this.getScriptHash(sb, node);
if (scriptHash !== undefined) {
sb.emitOp(node, 'DUP');
sb.emitPushString(node, 'address');
sb.emitPushBuffer(node, scriptHash);
sb.emitHelper(node, options, sb.helpers.wrapBuffer);
sb.emitHelper(node, options, sb.helpers.setDataPropertyObjectProperty);
}
}
emitInvoke(sb, _func, node, prop, _addressName, callBuffer, _options) {
const scriptHash = this.getScriptHash(sb, node);
if (scriptHash !== undefined) {
sb.emitOp(prop, 'CALL_E', Buffer.concat([callBuffer, scriptHash]));
}
}
getScriptHash(sb, node) {
const type = sb.context.analysis.getType(node);
if (type === undefined) {
return undefined;
}
const symbol = sb.context.analysis.getSymbolForType(node, type);
if (symbol === undefined) {
return undefined;
}
const decl = ts_utils_1.tsUtils.symbol.getValueDeclaration(symbol);
if (decl === undefined) {
sb.context.reportError(node, DiagnosticCode_1.DiagnosticCode.InvalidLinkedSmartContract, DiagnosticMessage_1.DiagnosticMessage.InvalidLinkedSmartContractDeclaration);
return undefined;
}
const filePath = ts_utils_1.tsUtils.file.getFilePath(ts_utils_1.tsUtils.node.getSourceFile(decl));
const name = ts_utils_1.tsUtils.symbol.getName(symbol);
return sb.getLinkedScriptHash(node, filePath, name);
}
}
exports.LinkedSmartContractFor = LinkedSmartContractFor;
//# sourceMappingURL=for.js.map