@neo-one/smart-contract-compiler
Version:
NEO•ONE TypeScript smart contract compiler.
43 lines (41 loc) • 1.85 kB
JavaScript
import { tsUtils } from '@neo-one/ts-utils';
import { DiagnosticCode } from '../../../../DiagnosticCode';
import { DiagnosticMessage } from '../../../../DiagnosticMessage';
import { SmartContractForBase } from '../SmartContractForBase';
export class LinkedSmartContractFor extends 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 = tsUtils.symbol.getValueDeclaration(symbol);
if (decl === undefined) {
sb.context.reportError(node, DiagnosticCode.InvalidLinkedSmartContract, DiagnosticMessage.InvalidLinkedSmartContractDeclaration);
return undefined;
}
const filePath = tsUtils.file.getFilePath(tsUtils.node.getSourceFile(decl));
const name = tsUtils.symbol.getName(symbol);
return sb.getLinkedScriptHash(node, filePath, name);
}
}
//# sourceMappingURL=for.js.map