drop script.fromSymbolic.

This commit is contained in:
Christopher Jeffrey 2016-05-18 02:06:03 -07:00
parent f798c6f38e
commit a2ddb960f5
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -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