@neo-one/smart-contract-compiler
Version:
NEO•ONE TypeScript smart contract compiler.
57 lines (55 loc) • 2.4 kB
JavaScript
import { tsUtils } from '@neo-one/ts-utils';
import ts from 'typescript';
import { InternalObjectProperty } from '../../constants';
import { BuiltinCall } from '../BuiltinCall';
class CreateEventNotifier extends BuiltinCall {
emitCall(sb, node, options) {
if (!options.pushValue) {
return;
}
const args = tsUtils.argumented.getArguments(node);
if (args.length < 1) {
return;
}
const arg = args[0];
if (!ts.isStringLiteral(arg)) {
return;
}
const eventName = tsUtils.literal.getLiteralValue(arg);
const type = sb.context.analysis.getType(node);
const result = sb.context.analysis.extractSignatureForType(node, type, { error: true });
if (result === undefined) {
return;
}
const { paramDecls, paramTypes } = result;
sb.emitHelper(node, options, sb.helpers.createFunctionArray({
body: (innerOptionsIn) => {
const innerOptions = sb.pushValueOptions(innerOptionsIn);
sb.emitHelper(node, innerOptions, sb.helpers.parameters({
params: paramDecls,
asArgsArr: true,
map: (param, innerInnerOptions, isRestElement) => {
let tpe = paramTypes.get(param);
if (type !== undefined && isRestElement) {
tpe = tsUtils.type_.getArrayType(type);
}
sb.emitHelper(node, innerInnerOptions, sb.helpers.unwrapValRecursive({ type: tpe }));
},
}));
sb.emitOp(node, 'UNPACK');
sb.emitPushString(node, eventName);
sb.emitOp(node, 'SWAP');
sb.emitOp(node, 'INC');
sb.emitOp(node, 'PACK');
sb.emitSysCall(node, 'Neo.Runtime.Notify');
sb.emitHelper(node, innerOptions, sb.helpers.wrapUndefined);
sb.emitHelper(node, innerOptions, sb.helpers.return);
},
}));
sb.emitHelper(node, options, sb.helpers.createFunctionObject({ property: InternalObjectProperty.Call }));
}
}
export const add = (builtins) => {
builtins.addContractValue('createEventNotifier', new CreateEventNotifier());
};
//# sourceMappingURL=createEventNotifier.js.map