UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

35 lines (33 loc) 1.71 kB
import { Types } from '../../constants'; import { BuiltinInterface } from '../BuiltinInterface'; import { SysCallInstanceMemberPrimitive } from './SysCallInstanceMemberPrimitive'; import { ValueFor } from './ValueFor'; import { ValueInstanceOf } from './ValueInstanceOf'; class ContractInterface extends BuiltinInterface { } class ContractConstructorInterface extends BuiltinInterface { } export const add = (builtins) => { builtins.addContractInterface('Contract', new ContractInterface()); builtins.addContractValue('Contract', new ValueInstanceOf('ContractConstructor', (sb) => sb.helpers.isContract)); builtins.addContractMember('Contract', 'script', new SysCallInstanceMemberPrimitive('Neo.Contract.GetScript', Types.Contract, Types.Buffer)); builtins.addContractMember('Contract', 'payable', new SysCallInstanceMemberPrimitive('Neo.Contract.IsPayable', Types.Contract, Types.Boolean)); builtins.addContractInterface('ContractConstructor', new ContractConstructorInterface()); builtins.addContractMember('ContractConstructor', 'for', new ValueFor('Neo.Blockchain.GetContract', (sb, node, options) => { sb.emitHelper(node, options, sb.helpers.if({ condition: () => { sb.emitOp(node, 'DUP'); 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.wrapContract); }, })); })); }; //# sourceMappingURL=contract.js.map