From a2ddb960f522713c0faa48e726a010a7a10a6927 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 18 May 2016 02:06:03 -0700 Subject: [PATCH] drop script.fromSymbolic. --- lib/bcoin/script.js | 88 +++------------------------------------------ 1 file changed, 4 insertions(+), 84 deletions(-) diff --git a/lib/bcoin/script.js b/lib/bcoin/script.js index 17624719..7d3858fc 100644 --- a/lib/bcoin/script.js +++ b/lib/bcoin/script.js @@ -271,50 +271,6 @@ Witness.fromString = function fromString(items) { return new Witness(result); }; -/** - * Parse an array of opcodes and pushdatas (Buffers) with the - * opcodes as strings representing their symbolic name. - * _Must_ contain only stack items (no non-push opcodes). - * @example - * Witness.fromSymbolic(['OP_1', new Buffer([2]), 'OP_3']); - * @param {Array} items - Array of strings and Buffers. - * @returns {Witness} - * @throws Parse error. - */ - -Witness.fromSymbolic = function fromSymbolic(items) { - var code = new Array(items.length); - var i, op, symbol; - - for (i = 0; i < items.length; i++) { - op = items[i]; - - if (Buffer.isBuffer(op)) { - code[i] = op; - continue; - } - - op = (op + '').toLowerCase(); - if (op.indexOf('op_') === 0) - op = op.slice(3); - - if (+op === -1) - op = STACK_NEGATE; - else if (+op === 0 || op === 'false') - op = STACK_FALSE; - else if (+op === 1 || op === 'true') - op = STACK_TRUE; - else if (+op >= 1 && +op <= 16) - op = new Buffer([+op]); - else - assert(false, 'Non-stack item in witness string.'); - - code[i] = op; - } - - return new Witness(code); -}; - /** * Format script code into a human readable-string. * @param {Array} code @@ -3629,8 +3585,10 @@ Script.fromString = function fromString(code) { if (opcodes[symbol] == null) { if (op[0] === '\'') { + assert(op[op.length - 1] === '\'', 'Unknown opcode.'); op = op.slice(1, -1); - p.writeBytes(Script.encode([new Buffer(op, 'ascii')])); + op = new Buffer(op, 'ascii') + p.writeBytes(Script.encode([op])); continue; } if (/^-?\d+$/.test(op)) { @@ -3639,11 +3597,9 @@ Script.fromString = function fromString(code) { p.writeBytes(Script.encode([op])); continue; } - assert(op.indexOf('0x') === 0); + assert(op.indexOf('0x') === 0, 'Unknown opcode.'); op = op.substring(2); assert(utils.isHex(op), 'Unknown opcode.'); - if (op.length % 2 !== 0) - op = op + '0'; op = new Buffer(op, 'hex'); p.writeBytes(op); continue; @@ -3702,42 +3658,6 @@ Script.toSmall = function toSmall(op) { return op + 0x50; }; -/** - * Parse an array of opcodes and pushdatas (Buffers) with the - * opcodes as strings representing their symbolic name. - * Script.fromSymbolic(['OP_1', new Buffer([2]), 'OP_ADD']); - * @param {Array} items - Array of strings and Buffers. - * @returns {Script} - * @throws Parse error on unknown opcode. - */ - -Script.fromSymbolic = function fromSymbolic(items) { - var code = new Array(items.length); - var i, op; - - for (i = 0; i < items.length; i++) { - op = items[i]; - - if (Buffer.isBuffer(op)) { - code[i] = op; - continue; - } - - if (+op === -1) - op = '1negate'; - - op = (op + '').toUpperCase(); - if (op.indexOf('OP_') !== 0) - op = 'OP_' + op; - - assert(opcodes[op] != null, 'Unknown opcode.'); - - code[i] = opcodes[op]; - } - - return new Script(code); -}; - /** * Verify an input and output script, and a witness if present. * @param {Script} input