script.fromString.
This commit is contained in:
parent
9965f258e8
commit
fca282acdb
@ -2216,8 +2216,8 @@ Script.prototype.indexOf = function indexOf(data) {
|
||||
|
||||
/**
|
||||
* Check to see if a pushdata Buffer abides by minimaldata.
|
||||
* @param {Buffer} value - Pushdata op from script code
|
||||
* (must be from a deserialized script).
|
||||
* @param {Buffer} data
|
||||
* @param {Number} opcode
|
||||
* @param {Number?} flags
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
@ -3820,14 +3820,14 @@ Script.fromString = function fromString(code) {
|
||||
if (op[0] === '\'') {
|
||||
assert(op[op.length - 1] === '\'', 'Unknown opcode.');
|
||||
op = op.slice(1, -1);
|
||||
op = new Buffer(op, 'ascii');
|
||||
p.writeBytes(Script.encodePush(op));
|
||||
op = Opcode.fromString(op);
|
||||
p.writeBytes(op.toRaw());
|
||||
continue;
|
||||
}
|
||||
if (/^-?\d+$/.test(op)) {
|
||||
op = new bn(op, 10);
|
||||
op = Script.array(op);
|
||||
p.writeBytes(Script.fromArray([op]).raw);
|
||||
op = Opcode.fromNumber(op);
|
||||
p.writeBytes(op.toRaw());
|
||||
continue;
|
||||
}
|
||||
assert(op.indexOf('0x') === 0, 'Unknown opcode.');
|
||||
@ -3958,7 +3958,7 @@ Script.verify = function verify(input, witness, output, tx, i, flags) {
|
||||
hadWitness = true;
|
||||
|
||||
// Input script must be exactly one push of the redeem script.
|
||||
if (!utils.equal(input.raw, Script.encodePush(raw)))
|
||||
if (!utils.equal(input.raw, Opcode.fromPush(raw).toRaw()))
|
||||
throw new ScriptError('WITNESS_MALLEATED_P2SH');
|
||||
|
||||
// Verify the program in the redeem script
|
||||
@ -4289,37 +4289,6 @@ Script.parseArray = function parseArray(code) {
|
||||
return out;
|
||||
};
|
||||
|
||||
/**
|
||||
* Encode a single push op. Note that this
|
||||
* will _always_ be a PUSHDATA. Analagous to
|
||||
* bitcoind's `CScript() << vector`.
|
||||
* @param {Buffer} data
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
Script.encodePush = function encodePush(data) {
|
||||
var p = new BufferWriter();
|
||||
if (data.length <= 0x4b) {
|
||||
p.writeU8(data.length);
|
||||
p.writeBytes(data);
|
||||
} else if (data.length <= 0xff) {
|
||||
p.writeU8(opcodes.OP_PUSHDATA1);
|
||||
p.writeU8(data.length);
|
||||
p.writeBytes(data);
|
||||
} else if (data.length <= 0xffff) {
|
||||
p.writeU8(opcodes.OP_PUSHDATA2);
|
||||
p.writeU16(data.length);
|
||||
p.writeBytes(data);
|
||||
} else if (data.length <= 0xffffffff) {
|
||||
p.writeU8(opcodes.OP_PUSHDATA4);
|
||||
p.writeU32(data.length);
|
||||
p.writeBytes(data);
|
||||
} else {
|
||||
throw new Error('Pushdata size too large.');
|
||||
}
|
||||
return p.render();
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate the size (including
|
||||
* the opcode) of a pushdata.
|
||||
@ -4456,7 +4425,7 @@ Opcode.fromString = function fromString(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
|
||||
return Opcode.fromPush(data);
|
||||
return Opcode.fromData(data);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -4478,7 +4447,7 @@ Opcode.from = function from(data) {
|
||||
if (typeof data === 'string')
|
||||
return Opcode.fromString(data, 'utf8');
|
||||
|
||||
return Opcode.fromPush(data);
|
||||
return Opcode.fromData(data);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user