UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

46 lines (44 loc) 2.23 kB
import { GlobalProperty, Types } from '../../constants'; import { BuiltinInterface } from '../BuiltinInterface'; import { BuiltinMemberValue } from '../BuiltinMemberValue'; import { BuiltinValueObject } from '../BuiltinValueObject'; import { SysCallMemberValue } from './SysCallMemberValue'; class BlockchainValue extends BuiltinValueObject { constructor() { super(...arguments); this.type = 'BlockchainConstructor'; } } class BlockchainConstructorInterface extends BuiltinInterface { } class BlockchainCurrentCallerContract extends BuiltinMemberValue { emit(sb, node, options) { if (options.pushValue) { sb.emitHelper(node, options, sb.helpers.getGlobalProperty({ property: GlobalProperty.CallingScriptHash })); sb.emitOp(node, 'DUP'); sb.emitSysCall(node, 'Neo.Blockchain.GetContract'); sb.emitHelper(node, options, sb.helpers.if({ condition: () => { sb.emitPushBuffer(node, Buffer.from([])); sb.emitOp(node, 'EQUAL'); }, whenTrue: () => { sb.emitOp(node, 'DROP'); sb.emitHelper(node, options, sb.helpers.wrapUndefined); }, whenFalse: () => { sb.emitHelper(node, options, sb.helpers.wrapBuffer); }, })); } } } export const add = (builtins) => { builtins.addContractValue('Blockchain', new BlockchainValue()); builtins.addContractInterface('BlockchainConstructor', new BlockchainConstructorInterface()); builtins.addContractMember('BlockchainConstructor', 'currentBlockTime', new SysCallMemberValue('Neo.Runtime.GetTime', Types.Number)); builtins.addContractMember('BlockchainConstructor', 'currentHeight', new SysCallMemberValue('Neo.Blockchain.GetHeight', Types.Number)); builtins.addContractMember('BlockchainConstructor', 'currentTransaction', new SysCallMemberValue('System.ExecutionEngine.GetScriptContainer', Types.Transaction)); builtins.addContractMember('BlockchainConstructor', 'currentCallerContract', new BlockchainCurrentCallerContract()); }; //# sourceMappingURL=blockchain.js.map