@neo-one/smart-contract-compiler
Version:
NEO•ONE TypeScript smart contract compiler.
46 lines (44 loc) • 1.56 kB
JavaScript
import { GlobalProperty } from '../../constants';
import { Helper } from '../Helper';
export class CacheStorageHelper extends Helper {
constructor() {
super(...arguments);
this.needsGlobal = true;
this.needsGlobalOut = true;
}
emitGlobal(sb, node, _options) {
sb.emitPushInt(node, GlobalProperty.CacheStorage);
sb.emitOp(node, 'NEWMAP');
sb.emitOp(node, 'SETITEM');
}
emitGlobalOut(sb, node, optionsIn) {
const options = sb.pushValueOptions(optionsIn);
sb.emitPushInt(node, GlobalProperty.CacheStorage);
sb.emitOp(node, 'PICKITEM');
sb.emitSysCall(node, 'Neo.Runtime.GetTrigger');
sb.emitPushInt(node, 0x10);
sb.emitHelper(node, options, sb.helpers.if({
condition: () => {
sb.emitOp(node, 'NUMEQUAL');
},
whenTrue: () => {
sb.emitHelper(node, options, sb.helpers.mapForEach({
each: () => {
sb.emitSysCall(node, 'Neo.Storage.GetContext');
sb.emitSysCall(node, 'Neo.Storage.Put');
},
}));
},
whenFalse: () => {
sb.emitOp(node, 'DROP');
},
}));
}
emit(sb, node, options) {
if (!options.pushValue) {
return;
}
sb.emitHelper(node, options, sb.helpers.getGlobalProperty({ property: GlobalProperty.CacheStorage }));
}
}
//# sourceMappingURL=CacheStorageHelper.js.map