UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

82 lines (80 loc) 3.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.add = void 0; const ts_utils_1 = require("@neo-one/ts-utils"); const constants_1 = require("../../constants"); const BuiltinInterface_1 = require("../BuiltinInterface"); const BuiltinMemberCall_1 = require("../BuiltinMemberCall"); const BuiltinValueObject_1 = require("../BuiltinValueObject"); class CryptoInterface extends BuiltinInterface_1.BuiltinInterface { } class CryptoValue extends BuiltinValueObject_1.BuiltinValueObject { constructor() { super(...arguments); this.type = 'CryptoConstructor'; } } class HashOp extends BuiltinMemberCall_1.BuiltinMemberCall { constructor(op) { super(); this.op = op; } emitCall(sb, _func, node, optionsIn) { const options = sb.pushValueOptions(optionsIn); const args = ts_utils_1.tsUtils.argumented.getArguments(node); if (args.length === 0) { return; } const arg = args[0]; const throwTypeError = (innerOptions) => { sb.emitOp(arg, 'DROP'); sb.emitHelper(arg, innerOptions, sb.helpers.throwTypeError); }; const unwrap = (type) => (innerOptions) => { sb.emitHelper(arg, innerOptions, sb.helpers.unwrapVal({ type })); }; sb.visit(arg, options); sb.emitHelper(node, options, sb.helpers.forBuiltinType({ type: sb.context.analysis.getType(arg), array: throwTypeError, map: throwTypeError, set: throwTypeError, boolean: unwrap(constants_1.Types.Boolean), buffer: unwrap(constants_1.Types.Buffer), null: throwTypeError, number: unwrap(constants_1.Types.Number), object: throwTypeError, string: unwrap(constants_1.Types.String), symbol: throwTypeError, undefined: throwTypeError, arrayStorage: throwTypeError, mapStorage: throwTypeError, setStorage: throwTypeError, error: throwTypeError, forwardValue: throwTypeError, iteratorResult: throwTypeError, iterable: throwTypeError, iterableIterator: throwTypeError, transaction: throwTypeError, output: throwTypeError, attribute: throwTypeError, input: throwTypeError, account: throwTypeError, asset: throwTypeError, contract: throwTypeError, header: throwTypeError, block: throwTypeError, })); sb.emitOp(node, this.op); sb.emitHelper(node, optionsIn, sb.helpers.wrapBuffer); } } exports.add = (builtins) => { builtins.addContractInterface('CryptoConstructor', new CryptoInterface()); builtins.addContractMember('CryptoConstructor', 'sha1', new HashOp('SHA1')); builtins.addContractMember('CryptoConstructor', 'sha256', new HashOp('SHA256')); builtins.addContractMember('CryptoConstructor', 'hash160', new HashOp('HASH160')); builtins.addContractMember('CryptoConstructor', 'hash256', new HashOp('HASH256')); builtins.addContractValue('crypto', new CryptoValue()); }; //# sourceMappingURL=crypto.js.map